c# - Create List of Time Series -


i need create time series 200 observations of 10 measuretypes (1 10) , join in list (using c# 7):

var = enumerable.range(1, 200).select(x => new measure { measuretypeid = 1, created = datetime.now.adddays(x), value = (decimal)(80 * random.nextdouble() + 40) });  var b = enumerable.range(1, 200).select(x => new measure { measuretypeid = 2, created = datetime.now.adddays(x), value = (decimal)(20 * random.nextdouble() + 30) });  // other measures  var result = a.union(b).union(c). ... 

what changes measure measure measureid incremental , parameters (80 , 40) (20 , 30) ...

is there way simplify code?

use for loop array (or list) of tuples or custom type hold parameters, following:

var result = set.empty; // or whatever use  tuple<int, int>[] params = {     new tuple<int, int>(80, 40),     new tuple<int, int>(20, 30),     // , on }  for(int = 0; < n; i++) {     result.union(enumerable.range(1, 200).select(x => new measure { measuretypeid = + 1, created = datetime.now.adddays(x), value = (decimal)(params[i].item1 * random.nextdouble() + params[i].item2) })); }  // linq version var result = enumerable.range(1, n).selectmany(x => enumerable.range(1, 200), (t, n) => new measure {     measuretypeid = t,     created = datetime.now.adddays(n),     value = (decimal)(params[t - 1].item1 * random.nextdouble() + params[t - 1].item2) }); 

you can use c# 7's sugared tuple syntax if want, aren't versed yet.

if parameters part of series, can skip tuples entirely.

linq version borrowed , modified @chrispickford's answer.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -