예제 #1
0
        internal Album(IGrouping <string, SONG> album)
        {
            Name = album.Key.IsNullorEmpty() ? Consts.UnknownAlbum : album.Key;

            // uint value, use their max value
            DiscCount  = album.Max(x => x.DiscCount);
            TrackCount = album.Max(x => x.TrackCount);
            Year       = album.Max(x => x.Year);

            // TODO: not combine all, just use not-null value
            // string[] value, use their all value (remove duplicated values) combine
            AlbumArtists     = (from aa in album where !aa.AlbumArtists.IsNullorEmpty() select aa.AlbumArtists).FirstOrDefault()?.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);//album.Where(x => !x.AlbumArtists.IsNullorEmpty()).FirstOrDefault().AlbumArtists;
            Genres           = (from aa in album where !aa.Genres.IsNullorEmpty() select aa.Genres).FirstOrDefault()?.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);
            AlbumArtistsSort = (from aa in album where !aa.AlbumArtistsSort.IsNullorEmpty() select aa.AlbumArtistsSort).FirstOrDefault()?.Split(new string[] { Consts.ArraySeparator }, StringSplitOptions.RemoveEmptyEntries);

            // normal value, use their not-null value
            AlbumSort           = (from aa in album where !aa.AlbumSort.IsNullorEmpty() select aa.AlbumSort).FirstOrDefault();
            ReplayGainAlbumGain = (from aa in album where aa.ReplayGainAlbumGain != double.NaN select aa.ReplayGainAlbumGain).FirstOrDefault();
            ReplayGainAlbumPeak = (from aa in album where aa.ReplayGainAlbumPeak != double.NaN select aa.ReplayGainAlbumPeak).FirstOrDefault();
            PicturePath         = (from aa in album where !aa.PicturePath.IsNullorEmpty() select aa.PicturePath).FirstOrDefault();

            // songs, serialized as "ID0|ID1|ID2...|IDn"
            Songs = album.Select(x => x.ID).Distinct().ToArray();

            IsOnedrive = album.Any(a => a.IsOneDrive);
        }
예제 #2
0
        private ElectricityInfoEntity createSummaryElectricityRow(IGrouping <int, ElectricityFileInfo> row)
        {
            var defaultValues  = row.First();
            var maxPaymentDate = row.Max(x => x.PaymentDate);

            return(new ElectricityInfoEntity
            {
                AmountAfterTax = row.Sum(x => x.Amount),
                BankAccount = defaultValues.BankAccount,
                BankAccountType = defaultValues.BankAccountType,
                Branch = defaultValues.BankBranch,
                Bank = defaultValues.BankCode,
                BillCreatingDate = row.Min(x => x.BillCreatingDate),
                ConsumerAddress = defaultValues.ConsumerAddress,
                ConsumerName = defaultValues.ConsumerName,
                ConsumerNumber = defaultValues.ConsumerNumber,
                CustomerId = defaultValues.CustomerId,
                GeneralRowId = defaultValues.GeneralRowId,
                Invoice = 0,
                JournalEntryNumber = 0,
                MonthOfLastInvoice = maxPaymentDate.Month,
                NumberOfCreditDays = defaultValues.NumberOfCreditDays,
                PaymentDate = maxPaymentDate,
                YearOfLastInvoice = maxPaymentDate.Year,
                IsMatched = row.Where(x => !x.IsMatched).Count() == 0,
                Contract = row.Key,
                RowId = 0,
            });
        }
예제 #3
0
 private RecommendedProduct GetProductByLatestOrderDate(IGrouping <Guid?, RecommendedProduct> items)
 {
     return(new RecommendedProduct()
     {
         ProductId = items.Key,
         ProductName = items.FirstOrDefault().ProductName,
         LastOrderDate = items.Max(rp => rp.LastOrderDate),
     });
 }
예제 #4
0
        public ActionResult ChangeReturnPoint(int arg, int group, int?value, int type)
        {
            var list = DB.DeliveryLists.FirstOrDefault(x => x.ID == group);

            if (list != null)
            {
                IGrouping <int?, DeliveryListOrder> gr = null;
                if (type == (int)SectorTypes.CarSector)
                {
                    gr = list.DeliveryListOrders.GroupBy(x => x.CarID).FirstOrDefault(x => x.Key == arg);
                }
                if (type == (int)SectorTypes.CourierSector)
                {
                    gr = list.DeliveryListOrders.GroupBy(x => x.WorkerID).FirstOrDefault(x => x.Key == arg);
                }
                if (value.HasValue)
                {
                    var rp = gr.FirstOrDefault(x => x.ReturnPoint);
                    if (rp != null)
                    {
                        rp.StoreID = value.Value;
                    }
                    else
                    {
                        var max = gr.Max(x => x.OrderNum);
                        rp = new DeliveryListOrder()
                        {
                            StoreID     = value.Value,
                            Type        = type,
                            ReturnPoint = true,
                            OrderNum    = max + 1,
                            ListID      = list.ID
                        };
                        if (type == (int)SectorTypes.CarSector)
                        {
                            rp.CarID = arg;
                        }
                        if (type == (int)SectorTypes.CourierSector)
                        {
                            rp.WorkerID = arg;
                        }
                        DB.DeliveryListOrders.InsertOnSubmit(rp);
                    }
                }
                else
                {
                    var rp = gr.FirstOrDefault(x => x.ReturnPoint);
                    if (rp != null)
                    {
                        DB.DeliveryListOrders.DeleteOnSubmit(rp);
                    }
                }
                DB.SubmitChanges();
            }
            return(new ContentResult());
        }
예제 #5
0
        public ServerMessageInfo(IGrouping <byte, ServerMessageModel> group)
        {
            Index    = group.Key;
            Messages = Enumerable.Repeat("", group.Max(s => s.Language) + 1).ToList();

            foreach (ServerMessageModel message in group)
            {
                Messages[message.Language] = message.Message;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DuringFirst"/> class.
        /// </summary>
        public DuringFirst(IGrouping <string, RescueRoomInfo> group, DateTime time)
        {
            this.DuringMin = group.Min(c => c.DuringHours.Value);
            this.DuringMax = group.Max(c => c.DuringHours.Value);
            this.Time      = time;
            this.Level     = 1;

            this.DuringGroupName = group.Key;
            this.Count           = group.Count();

            this.List = group.OrderBy(c => c.During).GroupBy(c => c.DuringHours.Value).Select(c => new DuringSecond(c, time)).ToList();
        }
예제 #7
0
        private static void CreateHeader(StringBuilder sb, IGrouping <DateTime, RaidModel> raidDate)
        {
            var killed = raidDate.Count(i => i.Killed);
            var failed = raidDate.Count(i => !i.Killed);
            var bosses = raidDate.Select(i => i.EncounterName).Distinct().Count();

            var tryTime = new TimeSpan(raidDate.Select(i => i.OccurenceEnd - i.OccurenceStart)
                                       .Sum(i => i.Ticks));
            var raidTime = raidDate.Max(i => i.OccurenceEnd) - raidDate.Min(i => i.OccurenceStart);

            sb.Append(HtmlCreator.CreateHeaderHtml(raidDate.Key, killed, failed, tryTime, raidTime, bosses));
        }
예제 #8
0
 public AggregatedResult(IGrouping <string, TournamentResult> results)
 {
     Username           = results.First().Username;
     Title              = results.First().Title;
     MaxRating          = results.Max(p => p.Rating);
     Ranks              = results.Select(p => p.Rank);
     Scores             = results.Select(p => p.Score >= p.Points ? p.Score : p.Points); // A TournamentResult should only have either Score (Arena tournaments) or Points (Swiss tournaments)
     TieBreaks          = results.Select(p => p.TieBreak);
     TotalScores        = Scores.Sum();
     TotalTieBreaks     = TieBreaks.Sum();
     AveragePerformance = (double)results.Select(p => p.Performance).Sum() / results.Count();
 }
예제 #9
0
        private static float GetAvgAmount(IGrouping <DateTime, RoomRates> list)
        {
            var highest = list.Max(i => i.AmountTypeInclusive);
            var total   = 0;

            foreach (var item in list)
            {
                total += item.AmountTypeExclusive;
            }
            var average = total / list.Count();

            return(average);
        }
예제 #10
0
 public override void SetValues(IGrouping <Tuple <Order, string>, OrderConfirmation> entity)
 {
     OrderNumber    = entity.Key.Item1.Number;
     OrderType      = entity.Key.Item1.OrderType;
     TotalScrap     = (entity.Key.Item1.OrderData?.FirstOrDefault()?.TotalScrap == null) ? 0 : entity.Key.Item1.OrderData.First().TotalScrap;
     TotalProduced  = TotalScrap + ((entity.Key.Item1.OrderData?.FirstOrDefault()?.TotalYield == null) ? 0 : entity.Key.Item1.OrderData.First().TotalYield);
     Scrap          = entity.Sum(con => con.Scrap);
     MaterialCode   = entity.Key.Item1.OrderData?.FirstOrDefault()?.Material?.Code;
     Color          = entity.Key.Item1.OrderData?.FirstOrDefault()?.Material?.ColorComponent?.Description;
     FamilyCode     = entity.Key.Item1.OrderData?.FirstOrDefault()?.Material?.MaterialFamily?.L1?.Code;
     CauseShortText = entity.Key.Item2;
     EndDate        = entity.Max(con => con.EndTime);
 }
예제 #11
0
        ColumnType _GetColumnType(IGrouping <int, ColumnType> group)
        {
            var ret = (ColumnType)group.Max(v => (int)v);

            if (ret == ColumnType.Date)
            {
                if (group.All(d => d == ColumnType.Date))
                {
                    return(ret);
                }
                return(ColumnType.String);
            }
            return(ret);
        }
        private void GenerateStatistics(IGrouping <uint, ObjectInfo> nsGroup)
        {
            Stats.Add(new Statistic()
            {
                StatName  = "Object count",
                StatValue = nsGroup.Count().ToString("N0")
            });

            Stats.Add(new Statistic()
            {
                StatName  = "Total object data",
                StatValue = nsGroup.Sum(oi => (long)oi.SizeInBytes).ToString("N0") + " bytes"
            });

            Tuple <double, double> meanStdDev = Statistics.MeanStandardDeviation(nsGroup.Select(oi => (double)oi.SizeInBytes));

            Stats.Add(new Statistic()
            {
                StatName  = "Average object size",
                StatValue = meanStdDev.Item1.ToString("N2") + " bytes"
            });

            Stats.Add(new Statistic()
            {
                StatName  = "StdDev",
                StatValue = meanStdDev.Item2.ToString("N2")
            });

            Stats.Add(new Statistic()
            {
                StatName  = "Median",
                StatValue = Statistics.Median(nsGroup.Select(oi => (double)oi.SizeInBytes)).ToString("N0") + " bytes"
            });

            Stats.Add(new Statistic()
            {
                StatName  = "Smallest object",
                StatValue = nsGroup.Min(oi => oi.SizeInBytes).ToString("N0") + " bytes"
            });

            Stats.Add(new Statistic()
            {
                StatName  = "Largest object",
                StatValue = nsGroup.Max(oi => oi.SizeInBytes).ToString("N0") + " bytes"
            });
        }
        private static Car GetFirstCar(Tournament tournament, IGrouping <string, CarResult> classGroup)
        {
            var maxPoints         = classGroup.Max(r => r.Points);
            var carsWithMaxPoints = classGroup.Where(r => r.Points == maxPoints).ToArray();

            if (carsWithMaxPoints.Count() == 1)
            {
                return(carsWithMaxPoints.First().Car);
            }
            var tiebreakWinner = TiebreakWinner(tournament, classGroup);

            if (tiebreakWinner == null)
            {
                return(null);
            }
            return(tiebreakWinner);
        }
        public CohortGroup MapCohortGroup(IGrouping <DateTime, CohortMember> group)
        {
            int totalUniqueCustomersWithinCohort = group
                                                   .Select(o => o.CustomerId)
                                                   .Distinct()
                                                   .Count();

            return(new CohortGroup
            {
                CohortRange = FormatCohortRange(
                    group.Min(g => g.CohortDate),
                    group.Max(g => g.CohortDate)
                    ),
                Customers = totalUniqueCustomersWithinCohort,
                Buckets = group
                          .Where(item => item.CohortPeriod > 0)
                          .OrderBy(item => item.CohortPeriod)
                          .GroupBy(item => item.CohortPeriod)
                          .Select(bucket => this.MapBucket(bucket, totalUniqueCustomersWithinCohort))
                          .ToList(),
            });
        }
예제 #15
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.");
            }
        }
        private static Feature CollectNewColumnValues(IGrouping <string, Feature> groupFeature, Dictionary <string, string> newColumnValues, OperatorPair operatorPair)
        {
            var getIntColumnValueFunc = new Func <Feature, int>(f =>
            {
                int currentValue = 0;
                if (f.ColumnValues.ContainsKey(operatorPair.ColumnName))
                {
                    Int32.TryParse(f.ColumnValues[operatorPair.ColumnName], out currentValue);
                }
                return(currentValue);
            });

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

            Feature feature = new Feature();

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

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

            case OperatorMode.Count:
                newColumnValues.Add(operatorPair.ColumnName, groupFeature.Count().ToString());
                break;

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

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

            case OperatorMode.Min:
                if (operatorPair.ColumnType.Equals("Integer", StringComparison.OrdinalIgnoreCase))
                {
                    int intMin = groupFeature.Min(getIntColumnValueFunc);
                    newColumnValues.Add(operatorPair.ColumnName, intMin.ToString());
                }
                else if (operatorPair.ColumnType.Equals("Double", StringComparison.OrdinalIgnoreCase))
                {
                    double doubleMin = groupFeature.Min(getDoubleColumnValueFunc);
                    newColumnValues.Add(operatorPair.ColumnName, doubleMin.ToString());
                }
                break;

            case OperatorMode.Max:
                if (operatorPair.ColumnType.Equals("Integer", StringComparison.OrdinalIgnoreCase))
                {
                    int intMin = groupFeature.Max(getIntColumnValueFunc);
                    newColumnValues.Add(operatorPair.ColumnName, intMin.ToString());
                }
                else if (operatorPair.ColumnType.Equals("Double", StringComparison.OrdinalIgnoreCase))
                {
                    double doubleMin = groupFeature.Max(getDoubleColumnValueFunc);
                    newColumnValues.Add(operatorPair.ColumnName, doubleMin.ToString());
                }
                break;
            }
            return(feature);
        }
        private static void SaveGroupToFile(IGrouping<decimal, Row> grouping)
        {
            var minRate = grouping.Min(row => row.Rate);
            var maxRate = grouping.Max(row => row.Rate);//or grouping.Key
            var fileName = string.Format("DailyCompounded_PaidWeekly_Principal1-10m_Rate{0}-{1}.csv",
                minRate,
                maxRate);

            var csvLines = from row in grouping
                    orderby row.Rate, row.Principal, row.Term
                    select row.ToCsv();
            var rows = Enumerable.Repeat(Row.CsvHeader, 1)
                                 .Concat(csvLines);

            File.WriteAllLines(fileName, rows);

            //var binaryContents = SevenZipHelper.Decompress(zipConents);
            var bytes = File.ReadAllBytes(fileName);
            var compressed = SevenZipHelper.Compress(bytes);
            File.WriteAllBytes(fileName +".lzma", compressed);
        }
 private static Car GetFirstCar(Tournament tournament, IGrouping<string, CarResult> classGroup)
 {
     var maxPoints = classGroup.Max(r => r.Points);
     var carsWithMaxPoints = classGroup.Where(r => r.Points == maxPoints).ToArray();
     if (carsWithMaxPoints.Count() == 1)
     {
         return carsWithMaxPoints.First().Car;
     }
     var tiebreakWinner = TiebreakWinner(tournament, classGroup);
     if (tiebreakWinner == null)
     {
         return null;
     }
     return tiebreakWinner;
 }