开发者

Copy values to an array based on half hourly time

开发者 https://www.devze.com 2023-01-22 13:50 出处:网络
I\'m receiving a bunch of values from my server for various dates with each value corresponding to half hour of a day,i.e for today there will be 50 values...it\'ll be a basic keyvalue pair like the o

I'm receiving a bunch of values from my server for various dates with each value corresponding to half hour of a day,i.e for today there will be 50 values...it'll be a basic keyvalue pair like the one below

    valsFromServer[28/10/2010 00:00:00] = 23;
    valsFromServer[开发者_JAVA技巧28/10/2010 00:30:00] = 100;
    valsFromServer[28/10/2010 01:00:00] = 200;
.
.
.
    valsFromServer[30/10/2010 23:30:00] = 100;
    valsFromServer[30/10/2010 23:30:00] = 200;

I need to convert this into a matrix format..like

28/10/2010 23 100 200....till the 50th value
.
.
30/10/2010 34 45 65...till the 50th value

Also the datetime could start at any arbitary time, it need not necessarily start at 00:00:00, it could even start at 23:00:00 as well, however this value should be placed at the appropriate index and in this case that would be at 48th position in the output matrix.

What would be the best way to do this?

I have written a linq query which parses the incoming datatble(which holds all values)

 date = row => row.Field<DateTime>("DateColumn").Date;
 priceSelector = column => column.Field<double>("PriceColumn");
 matrixRows = cells => MatrixRow.Create(cells.Key, cells.Select(priceSelector));

  return table.AsEnumerable()
                            .GroupBy(date)
                                .Select(matrixRows);

This actually gives me the matrix output format grouped by date, however currently stuck with how to create the output which is associated with time.Please could you help?


I think it would be best if you were to create a type that takes the key value pairs that are your input and stores them locally.

then have a method to parse all the values into the required output.

it can create a multidimensional array, and add the vaules to the array as required

0

精彩评论

暂无评论...
验证码 换一张
取 消