示例#1
0
        private StatisticItem CalculateDescendantData(PartnerNode partnerNode)
        {
            var statisticItem = new StatisticItem {
                PartnerName = partnerNode.PartnerName
            };
            var     financialItemsOfPartner = _financialItemsRepository.GetFinancialItems(partnerNode.PartnerID);
            var     partnerPurchase         = financialItemsOfPartner.Sum(x => x.Amount);
            decimal descendantPurchase      = 0;

            foreach (var descendantPartnerNodeID in partnerNode.Descendants)
            {
                var descendantPartnerFeePercent = PartnerNodeList[descendantPartnerNodeID].FeePercent;
                var financialItemsOfDescendant  = _financialItemsRepository.GetFinancialItems(descendantPartnerNodeID);
                descendantPurchase          = financialItemsOfDescendant.Sum(x => x.Amount);
                statisticItem.TeamPurchase += descendantPurchase;
            }

            statisticItem.TotalPurchase  = statisticItem.TeamPurchase + partnerPurchase;
            statisticItem.TotalComission = statisticItem.TotalPurchase * partnerNode.FeePercent / 100;

            return(statisticItem);
        }
示例#2
0
 private async Task PrintStatistic(StatisticItem statisticItem)
 {
     await Task.Run(() =>
     {
         Console.WriteLine("");
         Console.WriteLineFormatted("Sum: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.Sum, 2)));
         Console.WriteLineFormatted("Count: {0}", Color.White, TypeDictionary.FormatInput(statisticItem.Count));
         Console.WriteLineFormatted("ArithmeticMean: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.ArithmeticMean, 2)));
         Console.WriteLineFormatted("Median: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.Median, 2)));
         Console.WriteLineFormatted("Minimum: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.Minimum, 2)));
         Console.WriteLineFormatted("Maxmimum: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.Maxmimum, 2)));
         Console.WriteLineFormatted("Range: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.Range, 2)));
         Console.WriteLineFormatted("Variance: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.Variance, 2)));
         Console.WriteLineFormatted("StandardDeviation: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.StandardDeviation, 2)));
         Console.WriteLineFormatted("SampleVariance: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.SampleVariance, 2)));
         Console.WriteLineFormatted("SampleStandardDeviation: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.SampleStandardDeviation, 2)));
         Console.WriteLineFormatted("LowerQuartile: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.LowerQuartile, 2)));
         Console.WriteLineFormatted("HigherQuartile: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.HigherQuartile, 2)));
         Console.WriteLineFormatted("QuartileDistance: {0}", Color.White, TypeDictionary.FormatInput(Math.Round(statisticItem.QuartileDistance, 2)));
         Console.WriteLine("");
     });
 }
        private static void AddOtherItem(IEnumerable <StatisticItem> tempStatisticList,
                                         ICollection <StatisticItem> statisticList)
        {
            if (statisticList.Count < 6)
            {
                return;
            }

            var othersItem = new StatisticItem {
                Category = "Others",
                Value    = tempStatisticList
                           .Where(x => !statisticList.Contains(x))
                           .Sum(x => x.Value)
            };

            othersItem.Label = othersItem.Category + ": " + othersItem.Value + " " + Settings.DefaultCurrency;

            if (othersItem.Value > 0)
            {
                statisticList.Add(othersItem);
            }
        }
        private CashFlow GetCashFlowStatisticItems(
            Func <List <PaymentViewModel> > getPaymentListFunc)
        {
            var payments = getPaymentListFunc();

            var income = new StatisticItem
            {
                Category = Strings.RevenueLabel,
                Value    = payments.Where(x => x.Type == PaymentType.Income).Sum(x => x.Amount)
            };

            income.Label = income.Category + ": " +
                           Math.Round(income.Value, 2, MidpointRounding.AwayFromZero).ToString("C");

            var spent = new StatisticItem
            {
                Category = Strings.ExpenseLabel,
                Value    = payments.Where(x => x.Type == PaymentType.Expense).Sum(x => x.Amount)
            };

            spent.Label = spent.Category + ": " +
                          Math.Round(spent.Value, 2, MidpointRounding.AwayFromZero).ToString("C");

            var increased = new StatisticItem
            {
                Category = Strings.IncreaseLabel,
                Value    = income.Value - spent.Value
            };

            increased.Label = increased.Category + ": " +
                              Math.Round(increased.Value, 2, MidpointRounding.AwayFromZero).ToString("C");

            return(new CashFlow
            {
                Income = income,
                Spending = spent,
                Revenue = increased
            });
        }
示例#5
0
        private async void OnNextOrEnd()
        {
            _statisticItem = new StatisticItem()
            {
                ActivityId = Activities[Counter].Id,
                Date       = DateTime.Now,
                Time       = new DateTime() + DateTime.Now.Subtract(StartTime),
                Result     = SliderValue
            };
            StatisticItems.Add(_statisticItem);

            if (Counter < Activities.Count - 1)
            {
                ++Counter;
                UpdatePopupPageData();
            }
            else
            {
                await ItemsRepository.AddStatisticItemsAsync(StatisticItems);

                await NavigationService.GoBackAsync();
            }
        }
        private void AddOtherItem(IEnumerable <StatisticItem> tempStatisticList,
                                  ICollection <StatisticItem> statisticList)
        {
            if (statisticList.Count < 6)
            {
                return;
            }

            var othersItem = new StatisticItem
            {
                Label = "Others",
                Value = tempStatisticList
                        .Where(x => !statisticList.Contains(x))
                        .Sum(x => x.Value)
            };

            othersItem.Label = othersItem.Label + ": " + othersItem.Value;

            if (othersItem.Value > 0)
            {
                statisticList.Add(othersItem);
            }
        }
示例#7
0
        /// <summary>
        /// Add new object to items and make it current,
        /// also flush items to make sure new object is saved
        /// </summary>
        /// <param name="Obj"></param>
        /// <returns></returns>
        public static bool StartNewObject(string Obj, ClamWinMainForm.ScanPanelIDs ScanID)
        {
            lock (MainLock)
            {
                if (!Opened)
                {
                    return(false);
                }

                if (Items.Count == 0)
                {
                    // Add Total object
                    StatisticItem total = new StatisticItem(TotalString);
                    Items.Insert(0, total);
                }

                if (Obj == TotalString)
                {
                    // Special handling for total
                    // Total is not for direct selection
                    return(false);
                }

                foreach (StatisticItem item in Items)
                {
                    if (item.Object == Obj)
                    {
                        Current = item;
                        return(true);
                    }
                }
                Items.Add(new StatisticItem(Obj));
                Current = (StatisticItem)Items[Items.Count - 1];
            }
            return(true);
        }
示例#8
0
        public void SampleStandardDeviationTest(IList <double> input, double result)
        {
            var statisticItem = new StatisticItem(input);

            Assert.That(statisticItem.SampleStandardDeviation, Is.EqualTo(result).Within(0.001));
        }
 private static void SetLabel(StatisticItem item)
 {
     item.Label = item.Category + ": " + item.Value + " " + Settings.DefaultCurrency;
 }
示例#10
0
        private StatisticItem GetStatisticItem(DateTime startStroke, DateTime endStroke, MongoCollection<Session> sessions)
        {
            var match = GetMatchOperator(startStroke, endStroke);
            var project = GetProjectOperator(startStroke);
            var project1 = GetProjectOperator1();
            var group = GetGroupOperator();
            var pipeline = new[] { match, project, group, project1 };
            var queryResult = sessions.Aggregate(pipeline);
            var items = queryResult.ResultDocuments.ToList();

            var doc = queryResult.ResultDocuments.Select(BsonSerializer.Deserialize<StatisticItem>).FirstOrDefault();
            var count = doc == null ? 0 : doc.Count;
            var result = new StatisticItem { DateTime = startStroke, Count = count };
            return result;
        }
示例#11
0
        public async Task CreateItemStatistics(string subStorage)
        {
            try
            {
                var files = await _fileService.GetStorage(subStorage);

                using (var uow = _statisticService.StartUnitOfWork())
                {
                    foreach (var file in files)
                    {
                        if (!long.TryParse(file.Name.Split('.')[0], out long epoch))
                        {
                            _logger.LogError("{0} file not properly name as epoch", file.Name);
                            break;
                        }
                        var timeStamp = new DateTime(1970, 1, 1).AddMilliseconds(epoch);

                        var existingData = uow.StatisticsRepository.GetByTimestamp(timeStamp);

                        if (!existingData.Any())
                        {
                            var auctionData = await _fileService.LoadFromStorage <AuctionData>(subStorage, file.Name);

                            if (auctionData != default)
                            {
                                foreach (var item in _observedItems)
                                {
                                    if (auctionData.Auctions.Any(x => x.Item == item.Id))
                                    {
                                        var statisticItem = new StatisticItem(auctionData.Auctions.Where(x => x.Item == item.Id).SelectMany(x => Enumerable.Range(1, x.Quantity).Select(y => x.Buyout / x.Quantity / 10000.0)).ToList());

                                        uow.StatisticsRepository.Add(new ItemStatistic
                                        {
                                            ItemID                  = item.Id,
                                            Name                    = item.Name,
                                            TimeStamp               = timeStamp,
                                            Sum                     = statisticItem.Sum,
                                            Count                   = statisticItem.Count,
                                            ArithmeticMean          = statisticItem.ArithmeticMean,
                                            Median                  = statisticItem.Median,
                                            Minimum                 = statisticItem.Minimum,
                                            Maxmimum                = statisticItem.Maxmimum,
                                            Range                   = statisticItem.Range,
                                            Variance                = statisticItem.Variance,
                                            StandardDeviation       = statisticItem.StandardDeviation,
                                            SampleVariance          = statisticItem.SampleVariance,
                                            SampleStandardDeviation = statisticItem.SampleStandardDeviation,
                                            LowerQuartile           = statisticItem.LowerQuartile,
                                            HigherQuartile          = statisticItem.HigherQuartile,
                                            QuartileDistance        = statisticItem.QuartileDistance
                                        });

                                        _logger.LogInformation("Finished processing {0} for {1}", item.Name, timeStamp);
                                    }
                                }
                            }
                        }
                    }
                    uow.Commit();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Failed to create item statistic for storage {0}", subStorage);
            }
        }
示例#12
0
        public void HigherQuartileTest(IList <double> input, double result)
        {
            var statisticItem = new StatisticItem(input);

            Assert.That(statisticItem.HigherQuartile, Is.EqualTo(result).Within(0.001));
        }
        /// <summary>
        /// 格式化xml配置
        /// </summary>
        /// <param name="persons"></param>
        /// <returns></returns>
        public static List <StatisticItem> GetStatisticItems(List <Person> persons, List <Skill> skills)
        {
            List <StatisticItem>   list      = new List <StatisticItem>();
            IEnumerable <XElement> childList = from el in doc.Elements("Statistic")
                                               select el;
            int i = 0;

            foreach (XElement cl in childList)
            {
                i++;
                var info = new Statistic();
                if (cl.Attribute("CacheKey") != null)
                {
                    info.CacheKey = cl.Attribute("CacheKey").Value;
                }
                if (cl.Attribute("StatisticType") != null)
                {
                    info.StatisticType = cl.Attribute("StatisticType").Value;
                }
                if (cl.Attribute("ObjectType") != null)
                {
                    info.ObjectType = int.Parse(cl.Attribute("ObjectType").Value);
                }
                if (cl.Attribute("Uri") != null)
                {
                    info.Uri = cl.Attribute("Uri").Value;
                }
                if (cl.Attribute("BaseReferenceId") != null)
                {
                    info.BaseReferenceId = int.Parse(cl.Attribute("BaseReferenceId").Value);
                }
                info.Index      = i;
                info.ClientName = "SDI2-" + info.Uri;
                if (info.CacheKey.StartsWith("skill/"))
                {
                    var switchname = info.CacheKey.Substring("skill/".Length);
                    var skillquery = skills.Where(x => x.SwitchName == switchname).ToList();
                    foreach (var skill in skillquery)
                    {
                        var item = new StatisticItem()
                        {
                            ObjectId = skill.Number + "@" + skill.SwitchName,
                            DBID     = skill.DBID,
                            TypeID   = 1
                        };
                        item.ReferenceId = item.DBID + info.BaseReferenceId;
                        item.Statistic   = info;
                        list.Add(item);
                    }
                }
                else if (info.CacheKey.StartsWith("agent/"))
                {
                    if (persons != null)
                    {
                        foreach (var person in persons)
                        {
                            var item = new StatisticItem()
                            {
                                ObjectId = person.EmployeeID,
                                DBID     = person.DBID,
                                TypeID   = 2
                            };
                            item.ReferenceId = item.DBID + info.BaseReferenceId;
                            item.Statistic   = info;
                            list.Add(item);
                        }
                    }
                }
            }
            return(list);
        }
示例#14
0
        public void CountTest(IList <double> input, double result)
        {
            var statisticItem = new StatisticItem(input);

            Assert.AreEqual(statisticItem.Count, result);
        }
示例#15
0
        public void VarianceTest(IList <double> input, double result)
        {
            var statisticItem = new StatisticItem(input);

            Assert.That(statisticItem.Variance, Is.EqualTo(result).Within(0.001));
        }
示例#16
0
        public void RangeTest(IList <double> input, double result)
        {
            var statisticItem = new StatisticItem(input);

            Assert.AreEqual(statisticItem.Range, result);
        }
示例#17
0
        public void MaxmimumTest(IList <double> input, double result)
        {
            var statisticItem = new StatisticItem(input);

            Assert.AreEqual(statisticItem.Maxmimum, result);
        }
示例#18
0
        public void ArithmeticMeanTest(IList <double> input, double result)
        {
            var statisticItem = new StatisticItem(input);

            Assert.That(statisticItem.ArithmeticMean, Is.EqualTo(result).Within(0.001));
        }