Beispiel #1
0
        public object RunGetAggregatedDataTest()
        {
            List <DataAggregator <IncidentData> > aggregators = new List <DataAggregator <IncidentData> >();

            MonthAggregator <IncidentData> monthAggregator = new MonthAggregator <IncidentData>();
            PropertyInfo prop = typeof(IncidentData).GetProperty("Time");

            monthAggregator.Member = prop;
            aggregators.Add(monthAggregator);

            DataKeyValueDelegate areaDelegate = new DataKeyValueDelegate("Area");
            ValueDelegateAggregator <IncidentData> areaAggregator = new ValueDelegateAggregator <IncidentData>();

            areaAggregator.Name          = "Area";
            areaAggregator.ValueDelegate = areaDelegate.Delegate;
            aggregators.Add(areaAggregator);

            DataKeyValueDelegate codeDelegate = new DataKeyValueDelegate("Code");
            ValueDelegateAggregator <IncidentData> codeAggregator = new ValueDelegateAggregator <IncidentData>();

            codeAggregator.Name          = "Code";
            codeAggregator.ValueDelegate = codeDelegate.Delegate;
            aggregators.Add(codeAggregator);

            return(DataAggregator <IncidentData> .GetAggregatedData(aggregators, Incidents));
        }
Beispiel #2
0
        public object RunAggregatorTest()
        {
            Dictionary <object, Dictionary <object, Dictionary <object, int> > > output = new Dictionary <object, Dictionary <object, Dictionary <object, int> > >();

            MonthAggregator <IncidentData> monthAggregator = new MonthAggregator <IncidentData>();
            PropertyInfo prop = typeof(IncidentData).GetProperty("Time");

            monthAggregator.Member = prop;
            Dictionary <object, List <IncidentData> > monthAggregate = monthAggregator.GetData(Incidents);


            DataKeyValueDelegate areaDelegate = new DataKeyValueDelegate("Area");
            ValueDelegateAggregator <IncidentData> areaAggregator = new ValueDelegateAggregator <IncidentData>();

            areaAggregator.Name          = "Area";
            areaAggregator.ValueDelegate = areaDelegate.Delegate;

            DataKeyValueDelegate codeDelegate = new DataKeyValueDelegate("Code");
            ValueDelegateAggregator <IncidentData> codeAggregator = new ValueDelegateAggregator <IncidentData>();

            codeAggregator.Name          = "Code";
            codeAggregator.ValueDelegate = codeDelegate.Delegate;

            foreach (KeyValuePair <object, List <IncidentData> > monthEntry in monthAggregate)
            {
                if (!output.ContainsKey(monthEntry.Key))
                {
                    output.Add(monthEntry.Key, new Dictionary <object, Dictionary <object, int> >());
                }

                Dictionary <object, List <IncidentData> > areaAggregate = areaAggregator.GetData(monthEntry.Value);
                foreach (KeyValuePair <object, List <IncidentData> > areaEntry in areaAggregate)
                {
                    if (!output[monthEntry.Key].ContainsKey(areaEntry.Key))
                    {
                        output[monthEntry.Key].Add(areaEntry.Key, new Dictionary <object, int>());
                    }

                    Dictionary <object, List <IncidentData> > codeAggregate = codeAggregator.GetData(areaEntry.Value);
                    foreach (KeyValuePair <object, List <IncidentData> > codeEntry in codeAggregate)
                    {
                        if (!output[monthEntry.Key][areaEntry.Key].ContainsKey(codeEntry.Key))
                        {
                            output[monthEntry.Key][areaEntry.Key][codeEntry.Key] = codeEntry.Value.Count;
                        }
                        else
                        {
                            output[monthEntry.Key][areaEntry.Key][codeEntry.Key] += codeEntry.Value.Count;
                        }
                    }
                }
            }

            return(output);
        }
Beispiel #3
0
        public object RunGroupByTest()
        {
            List <DataAggregator <IncidentData> > aggregators = new List <DataAggregator <IncidentData> >();

            MonthAggregator <IncidentData> monthAggregator = new MonthAggregator <IncidentData>();
            PropertyInfo prop = typeof(IncidentData).GetProperty("Time");

            monthAggregator.Member = prop;
            aggregators.Add(monthAggregator);

            DataKeyValueDelegate areaDelegate = new DataKeyValueDelegate("Area");
            ValueDelegateAggregator <IncidentData> areaAggregator = new ValueDelegateAggregator <IncidentData>();

            areaAggregator.Name          = "Area";
            areaAggregator.ValueDelegate = areaDelegate.Delegate;
            aggregators.Add(areaAggregator);

            DataKeyValueDelegate codeDelegate = new DataKeyValueDelegate("Code");
            ValueDelegateAggregator <IncidentData> codeAggregator = new ValueDelegateAggregator <IncidentData>();

            codeAggregator.Name          = "Code";
            codeAggregator.ValueDelegate = codeDelegate.Delegate;
            aggregators.Add(codeAggregator);
            var data = DataAggregator <IncidentData> .GetAggregatedData(aggregators, Incidents);

            var test = data.GroupBy(
                x => x.AggregatorValues.GetValueOrDefault("Area"),
                x => x.AggregatorValues.GetValueOrDefault("Code"), (area, codes) => new
            {
                Area      = area,
                Count     = codes.Count(),
                CodeCount = getCodeCounts(codes.ToList())
            });;

            return(test);
        }