/// <summary> /// Creates a new table from a time aligned source table /// Due to the dynamic implementation and with big data performance hits are possible /// </summary> /// <typeparam name="T"></typeparam> /// <param name="newSerieKeyOrName">Name of zipped serie in the new table</param> /// <param name="zipFunc"> /// Given is a dynamic source table where you can get the current iteration value /// e.g. you have to series with the key "A" and "B" in the source table. /// In this case a lambda expression like 't => t.A + t.B' would add them /// serie A has {1,2,3,4} /// serie B has {2,2,2,4} /// zipped serie has {3,4,5,8} /// </param> /// <returns>New table with the zipped result</returns> public INullableQueryTable <T> ZipToNew(string newSerieKeyOrName, Func <dynamic, T?> zipFunc) { var table = new NullableQueryTable <T>(); var sourceTables = GroupSeries(); var resultTables = new List <INullableQueryTable <T> >(); foreach (var sourceTable in sourceTables) { var dynamicTable = new DynamicTableValues(sourceTable); var firstSerie = sourceTable.Series.First(); var count = firstSerie.Rows.Count; var newRows = new List <ISingleDataRow <T?> >(count); var newSerie = new NullableQuerySerie <T>(newRows, firstSerie).Alias(newSerieKeyOrName); table.AddSerie(newSerie); for (var i = 0; i < count; i++) { dynamicTable.Index = i; var newValue = zipFunc(dynamicTable); newRows.Add(new SingleDataRow <T?>(firstSerie.Rows[i].TimeUtc, newValue)); } resultTables.Add(table); } return(resultTables.MergeTables()); }
public INullableQueryTable <T> Calc(Action <dynamic> zipFunc) { var dynamicTable = new DynamicTableValues(this); var firstSerie = Series.Values.First(); var count = firstSerie.Rows.Count; //TODO: why are series not the same length? bug has to be fixed for (var i = 0; i < count; i++) // - 1/*TODO: remove*/ { try { dynamicTable.Index = i; zipFunc(dynamicTable); } catch (Exception ex) { //Logger.Warn($"Exception in index {i}: {ex.Message}"); } } return(this); }