private SeriesDateBasedElement GetChartElement(IGrouping<DateTime, Purchase> g)
 {
     var seriesElement = new SeriesDateBasedElement{ Argument = g.Key };
     switch (chartValueType)
     {
         case ChartValueType.TotalCost:
             var list = g.ToList();
             seriesElement.Value = g.Sum(purchase => purchase.TotalCost);
             break;
         case ChartValueType.ItemCost:
             list = g.ToList();
             seriesElement.Value = g.Average(purchase => purchase.ItemCost);
             break;
         case ChartValueType.Number:
             list = g.ToList();
             seriesElement.Value = g.Sum(purchase => purchase.ItemsNumber);
             break;
     }
     return seriesElement;
 }
示例#2
0
 public static WeatherResultByDayForecast Create(IGrouping <DateTime, WeatherResultList> group) => new WeatherResultByDayForecast
 {
     Date     = group.Key,
     Humidity = group.Average(a => a.Main.Humidity),
     Icon     = group.FirstOrDefault()?.Weather.FirstOrDefault()?.Icon,
     Speed    = group.Average(a => a.Wind.Speed),
     Temp     = group.Average(a => a.Main.Temp)
 };
        private SeriesDateBasedElement GetChartElement(IGrouping <DateTime, Purchase> g)
        {
            var seriesElement = new SeriesDateBasedElement {
                Argument = g.Key
            };

            switch (chartValueType)
            {
            case ChartValueType.TotalCost:
                var list = g.ToList();
                seriesElement.Value = g.Sum(purchase => purchase.TotalCost);
                break;

            case ChartValueType.ItemCost:
                list = g.ToList();
                seriesElement.Value = g.Average(purchase => purchase.ItemCost);
                break;

            case ChartValueType.Number:
                list = g.ToList();
                seriesElement.Value = g.Sum(purchase => purchase.ItemsNumber);
                break;
            }
            return(seriesElement);
        }
        private string CalculateAveragesForGroup(IGrouping <string, CompleteWorkItem> group)
        {
            _log.Enter(this, args: group.Key);

            var averageTime = group.Average(workItem => (workItem.Fields.MicrosoftVSTSCommonClosedDate - workItem.Fields.SystemCreatedDate).TotalMilliseconds);

            return($"{TimeSpan.FromMilliseconds(averageTime).Days} days and {TimeSpan.FromMilliseconds(averageTime).Minutes} minutes");
        }
示例#5
0
 public static VehicleStatsViewModel ConvertToVehicleStatsViewModel(this IGrouping <string, Vehicle> vehiclesPerManufacturer)
 {
     return(new VehicleStatsViewModel
     {
         AverageCost = vehiclesPerManufacturer.Average(x => double.Parse(x.CostInCredits)),
         ManufacturerName = vehiclesPerManufacturer.Key,
         VehicleCount = vehiclesPerManufacturer.ToList().Count
     });
 }
 public static TransactionCategorySummary CreateCategorySummary(this IGrouping <string, Transaction> group)
 {
     return(new TransactionCategorySummary
     {
         CategoryTitle = group.Key ?? "Uncategorised",
         TotalAmount = Math.Round(group.Sum(y => y.Amount), 2),
         AverageAmount = Math.Round(group.Average(y => y.Amount), 2),
         LargestPurchase = group.OrderByDescending(transaction => Math.Abs(transaction.Amount)).First()
     });
 }
示例#7
0
        private static ElementInfo AggregateToElementInfo(IGrouping <SimHashes, ElementInfo> g)
        {
            var first = g.First();

            return(new ElementInfo
            {
                Id = g.Key,
                Name = first.Name,
                SubstanceName = first.SubstanceName,
                State = first.State,
                HeatCapacity = first.HeatCapacity,

                Mass = g.Sum(e => e.Mass),
                Temperature = g.Average(e => e.Temperature),
            });
        }
        public void Average(IEnumerable <string> fieldNameList)
        {
            if (fieldNameList == null)
            {
                return;
            }

            foreach (var item in fieldNameList)
            {
                PropertyInfo property = this.GetType().GetProperty(item);

                if (property != null)
                {
                    property.SetValue(this, _previouslyGroupedList.Average(avr => (double)GetPropertyValue(avr, item)));
                }
            }
        }
示例#9
0
        private LeadMusicLog ConvertPurchaseGroupToLeadMusicLog(IGrouping <int, Purchase> group)
        {
            var log      = new LeadMusicLog();
            var purchase = group.First();
            var music    = purchase?.Music;

            log.ArtistEarn  = group.Sum(p => p.ArtistEarn ?? 0);
            log.ArtistName  = music?.Artist?.User?.UserName;
            log.AvgCost     = group.Average(p => p.PurchaseCost ?? 0);
            log.Count       = group.Count();
            log.HebrewName  = music?.HebrewName;
            log.MusicID     = purchase != null ? purchase.MusicID : 0;
            log.PasskolEarn = group.Sum(p => p.PasskolEarn ?? 0);
            log.SumCosts    = group.Sum(p => p.PurchaseCost ?? 0);

            return(log);
        }
        private Forecast CalculateDailyForecast(IGrouping <DateTime, Forecast> grp)
        {
            double       temperature  = 0;
            string       description  = null;
            string       icon         = null;
            WeatherCodes code         = default(WeatherCodes);
            DateTime     forecastDate = default(DateTime);

            temperature  = grp.Average(g => g.Temperature);
            description  = grp.First().WeatherDescription;
            icon         = grp.First().WeatherIconUrl;
            code         = grp.First().WeatherCode;
            forecastDate = grp.Key.Date;

            var forecast = new Forecast(grp.First().Location, temperature, description, icon, code, forecastDate);

            return(forecast);
        }
        double Aggregator(IGrouping <string, OrderModel> group)
        {
            var total = 0.0;

            if (Aggregate == "Sum")
            {
                total = group.Sum(o => o.Amount);
            }
            else if (Aggregate == "Count")
            {
                total = group.Count();
            }
            else if (Aggregate == "Average")
            {
                total = group.Average(o => o.Amount);
            }

            return(total);
        }
示例#12
0
        private double ComputeAggregate(IGrouping <string, SdtmRow> rows, string func, string aggVar)
        {
            double n;

            switch (func)
            {
            case "AVG":
                return(rows.Average(i => double.TryParse(i.Qualifiers[aggVar], out n) ? n : 0));

            case "MAX":
                return(rows.Max(i => double.TryParse(i.Qualifiers[aggVar], out n) ? n : 0));

            case "MIN":
                return(rows.Min(i => double.TryParse(i.Qualifiers[aggVar], out n) ? n : 0));

            case "SUM":
                return(rows.Sum(i => double.TryParse(i.Qualifiers[aggVar], out n)? n : 0));

            default:
                return(0);
            }
        }
        private static float Aggregate(IGrouping <string, TransactionWithTimestamp> period, Aggregation aggregation)
        {
            switch (aggregation)
            {
            case Aggregation.Count:
                return(period.Count());

            case Aggregation.Avg:
                return(period.Average(t => t.Transaction.Amount));

            case Aggregation.Sum:
                return(period.Sum(p => p.Transaction.Amount));

            case Aggregation.Min:
                return(period.Min(t => t.Transaction.Amount));

            case Aggregation.Max:
                return(period.Max(t => t.Transaction.Amount));

            default:
                throw new InvalidOperationException("Unknown aggregation.");
            }
        }
示例#14
0
 private static int calculateAverageDLP(IGrouping<Practice, Practice_Protocol> g)
 {
     return (int)Math.Round(g.Average(p => p.AverageDLP));
 }
示例#15
0
 private static double AverageHumidityIndoor(IGrouping <DateTime, Indoor> grp) => Math.Round(grp.Average(data => data.Humidity), 2);
示例#16
0
 private static double AverageTemperatureIndoor(IGrouping <DateTime, Indoor> grp) => Math.Round(grp.Average(data => data.Temperature), 2);
        // Tuple
        // item1: columnName,
        // item2: columnType,
        // item3: OperatorMode.
        private static Feature CollectNewColumnValues(IGrouping <string, Feature> groupFeature, Dictionary <string, string> newColumnValues, Tuple <string, string, DissolveOperatorMode> operatorPair)
        {
            PairStrategy pairStrategy = new PairStrategy
            {
                ColumnName = operatorPair.Item1,
                ColumnType = operatorPair.Item2,
                Operator   = operatorPair.Item3
            };

            var getIntColumnValueFunc = new Func <Feature, int>(f =>
            {
                int currentValue = 0;
                if (f.ColumnValues.ContainsKey(pairStrategy.ColumnName))
                {
                    Int32.TryParse(f.ColumnValues[pairStrategy.ColumnName], out currentValue);
                }
                return(currentValue);
            });

            var getDoubleColumnValueFunc = new Func <Feature, double>(f =>
            {
                double currentValue = 0;
                if (f.ColumnValues.ContainsKey(pairStrategy.ColumnName))
                {
                    Double.TryParse(f.ColumnValues[pairStrategy.ColumnName], out currentValue);
                }
                return(currentValue);
            });

            Feature feature = new Feature();

            switch (pairStrategy.Operator)
            {
            case DissolveOperatorMode.First:
                feature = groupFeature.FirstOrDefault();
                if (feature.GetShape() != null)
                {
                    newColumnValues.Add(pairStrategy.ColumnName, feature.ColumnValues[pairStrategy.ColumnName]);
                }
                break;

            case DissolveOperatorMode.Last:
                feature = groupFeature.LastOrDefault();
                if (feature.GetShape() != null)
                {
                    newColumnValues.Add(pairStrategy.ColumnName, feature.ColumnValues[pairStrategy.ColumnName]);
                }
                break;

            case DissolveOperatorMode.Count:
                newColumnValues.Add(pairStrategy.ColumnName, groupFeature.Count().ToString());
                break;

            case DissolveOperatorMode.Sum:
                if (pairStrategy.ColumnType.Equals("Integer", StringComparison.OrdinalIgnoreCase))
                {
                    int intSum = groupFeature.Sum(getIntColumnValueFunc);
                    newColumnValues.Add(pairStrategy.ColumnName, intSum.ToString());
                }
                else if (pairStrategy.ColumnType.Equals("Double", StringComparison.OrdinalIgnoreCase))
                {
                    double doubleSum = groupFeature.Sum(getDoubleColumnValueFunc);
                    newColumnValues.Add(pairStrategy.ColumnName, doubleSum.ToString());
                }
                break;

            case DissolveOperatorMode.Average:
                if (pairStrategy.ColumnType.Equals("Integer", StringComparison.OrdinalIgnoreCase) || pairStrategy.ColumnType.Equals("Double", StringComparison.OrdinalIgnoreCase))
                {
                    double averageValue = groupFeature.Average(getDoubleColumnValueFunc);
                    newColumnValues.Add(pairStrategy.ColumnName, averageValue.ToString());
                }
                break;

            case DissolveOperatorMode.Min:
                if (pairStrategy.ColumnType.Equals("Integer", StringComparison.OrdinalIgnoreCase))
                {
                    int intMin = groupFeature.Min(getIntColumnValueFunc);
                    newColumnValues.Add(pairStrategy.ColumnName, intMin.ToString());
                }
                else if (pairStrategy.ColumnType.Equals("Double", StringComparison.OrdinalIgnoreCase))
                {
                    double doubleMin = groupFeature.Sum(getDoubleColumnValueFunc);
                    newColumnValues.Add(pairStrategy.ColumnName, doubleMin.ToString());
                }
                break;
            }
            return(feature);
        }
示例#18
0
 private static float GetAverageTemperature(IGrouping <DateTime, List> forecastDate)
 {
     return(forecastDate.Average(x => x.main.temp));
 }
示例#19
0
 private static bool CheckIfSunny(int sunshineThreshold, IGrouping <DateTime, List> forecastDate)
 {
     return(forecastDate.Average(x => x.clouds.all) < sunshineThreshold);
 }