예제 #1
0
        public void FindIncomeGrowthTest()
        {
            var compRepo = new MongoDBRepository <Company>(nameof(Company)).DbCollection;
            var histColl = new MongoDBRepository <Financial>(nameof(Financial)).DbCollection;
            var results  = histColl.Aggregate().Group(key => key.companyId,
                                                      value => new {
                CompanyId   = value.Select(x => x.companyId).First(),
                TotalIncome = value.Sum(x => x.netIncome).Value,
                FirstYear   = value.First().netIncome.Value,
                LastYear    = value.Last().netIncome.Value,
                YearCount   = value.Count()
            }).ToList().Distinct();

            foreach (var result in results)
            {
                double growthRate = ((double)(result.FirstYear - result.LastYear) / result.LastYear) * 100 / result.YearCount;
                var    filter     = Builders <Company> .Filter.Eq("_id", result.CompanyId);

                var comp = compRepo.Find(filter).ToListAsync().Result;

                if (growthRate > 10 && comp.Count > 0)
                {
                    Console.WriteLine($"{comp.First().symbol}, {result.TotalIncome}, {result.FirstYear}, {result.LastYear}, {growthRate}");
                }
            }
        }