예제 #1
0
        public IReadOnlyList <INullableQueryTable <T> > GroupSeries()
        {
            var newTables     = new List <INullableQueryTable <T> >();
            var groupedTables = Series.Values.Where(i => i.GroupName != null).ToLookup(i => i.GroupName);

            foreach (var groupedTable in groupedTables)
            {
                var table = new NullableQueryTable <T>();
                newTables.Add(table);
                foreach (var serie in groupedTable)
                {
                    table.AddSerie(serie);
                }
            }

            //Non grouped series to own table
            var nonGroupedSeries = Series.Values.Where(i => i.GroupName == null).ToList();

            if (nonGroupedSeries.Any())
            {
                var tableNonGrouped = new NullableQueryTable <T>();
                foreach (var serie in nonGroupedSeries)
                {
                    tableNonGrouped.AddSerie(serie);
                }

                newTables.Add(tableNonGrouped);
            }

            return(newTables);
        }
예제 #2
0
        public INullableQueryTable <T> ToNewTable(Action <INullableQueryTable <T>, INullableQueryTable <T> > transformAction)
        {
            var table = new NullableQueryTable <T>();

            transformAction(this, table);
            return(table);
        }
예제 #3
0
        /// <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());
        }
예제 #4
0
        public INullableQueryTable <T> Transform(Func <IQuerySerie <T>, INullableQuerySerie <T> > doFunc)
        {
            var table = new NullableQueryTable <T>();

            foreach (var serie in Series.Values)
            {
                table.AddSerie(doFunc(serie));
            }

            return(table);
        }
예제 #5
0
        public INullableQueryTable <T> Group(Func <IGroupSelector <T>, IExecutableGroup <T> > groupConfigurator)
        {
            var table = new NullableQueryTable <T>();

            //groups must be completely aligned, so all the Start and Endtime
            var minStartTime = Series.Min(i => i.Value.StartTime);
            var maxEndTime   = Series.Max(i => i.Value.EndTime);

            foreach (var serie in Series.Values.OfType <ITimeWriteableQuerySerie>())
            {
                serie.StartTime = minStartTime;
                serie.EndTime   = maxEndTime;
            }

            foreach (var serie in Series.Values)
            {
                table.AddSerie(serie.Group(groupConfigurator));
            }

            return(table);
        }