A data storage class to represent one series on a graph, ie a single line on a graph. This class effectively wraps a List of dates and amounts.
Наследование: INotifyPropertyChanged
        /// <summary>
        ///     Analyses the specified ledger and assigns graph data
        /// </summary>
        public void Analyse([NotNull] LedgerBucket ledger, [NotNull] LedgerBook book)
        {
            if (ledger == null)
            {
                throw new ArgumentNullException(nameof(ledger));
            }

            if (book == null)
            {
                throw new ArgumentNullException(nameof(book));
            }

            GraphData = new GraphData
            {
                GraphName = "Bucket Balance History"
            };

            var series = new SeriesData
            {
                Description = "The actual bank balance of the Ledger Bucket over time.",
                SeriesName = "Balance"
            };
            GraphData.SeriesList.Add(series);

            foreach (var reconciliation in book.Reconciliations.Take(24).Reverse())
            {
                var entry = reconciliation.Entries.FirstOrDefault(e => e.LedgerBucket == ledger);
                var plot = new DatedGraphPlot
                {
                    Date = reconciliation.Date,
                    Amount = entry?.Balance ?? 0
                };
                series.PlotsList.Add(plot);
            }
        }
 private void CopyOutputFromAnalyser(BurnDownChartAnalyserResult analysisResult)
 {
     ActualSpendingAxesMinimum = analysisResult.GraphLines.GraphMinimumValue;
     BalanceLine = analysisResult.GraphLines.Series.Single(s => s.SeriesName == BurnDownChartAnalyserResult.BalanceSeriesName);
     BudgetLine = analysisResult.GraphLines.Series.Single(s => s.SeriesName == BurnDownChartAnalyserResult.BudgetSeriesName);
     ZeroLine = analysisResult.GraphLines.Series.Single(s => s.SeriesName == BurnDownChartAnalyserResult.ZeroSeriesName);
     ChartTitle = analysisResult.ChartTitle;
 }
Пример #3
0
        public void TestInitialise()
        {
            StartDate = new DateTime(2014, 08, 20);
            Subject = new GraphData
            {
                GraphName = "Main Graph Title"
            };

            Series1 = new SeriesData
            {
                SeriesName = "Series 1",
                Description = "Series 1 Description"
            };

            Series2 = new SeriesData
            {
                SeriesName = "Series 2",
                Description = "Series 2 Description"
            };

            Series3 = new SeriesData
            {
                SeriesName = "Series 3",
                Description = "Series 3 Description"
            };

            Subject.SeriesList.Add(Series1);
            Subject.SeriesList.Add(Series2);
            Subject.SeriesList.Add(Series3);

            var seriesNumber = 0;
            foreach (SeriesData series in Subject.SeriesList)
            {
                for (var index = 0; index < 31; index++)
                {
                    series.PlotsList.Add(new DatedGraphPlot { Amount = seriesNumber * 100 * (index + 1), Date = StartDate.AddDays(index) });
                }

                seriesNumber++;
            }
        }
        public BurnDownChartAnalyserResult Analyse(StatementModel statementModel, BudgetModel budgetModel,
                                                   IEnumerable<BudgetBucket> bucketsSubset, LedgerBook ledgerBook, DateTime beginDate)
        {
            if (statementModel == null)
            {
                throw new ArgumentNullException(nameof(statementModel));
            }

            if (budgetModel == null)
            {
                throw new ArgumentNullException(nameof(budgetModel));
            }

            List<BudgetBucket> bucketsCopy = bucketsSubset.ToList();
            this.logger.LogInfo(
                l => "BurnDownChartAnalyser.Analyse: " + string.Join(" ", bucketsCopy.Select(b => b.Code)));

            var result = new BurnDownChartAnalyserResult();

            List<DateTime> datesOfTheMonth = YieldAllDaysInDateRange(beginDate);
            var lastDate = datesOfTheMonth.Last();

            CreateZeroLine(datesOfTheMonth, result);

            var openingBalance = GetBudgetedTotal(budgetModel, ledgerBook, bucketsCopy, beginDate);
            CalculateBudgetLineValues(openingBalance, datesOfTheMonth, result);

            List<ReportTransactionWithRunningBalance> spendingTransactions = CollateStatementTransactions(statementModel, bucketsCopy, beginDate, lastDate,
                openingBalance);

            // Only relevant when calculating surplus burndown - ovespent ledgers are supplemented from surplus so affect its burndown.
            if (ledgerBook != null && bucketsCopy.OfType<SurplusBucket>().Any())
            {
                List<ReportTransaction> overSpentLedgers =
                    this.ledgerCalculator.CalculateOverspentLedgers(statementModel, ledgerBook, beginDate).ToList();
                if (overSpentLedgers.Any())
                {
                    spendingTransactions.AddRange(
                        overSpentLedgers.Select(t => new ReportTransactionWithRunningBalance(t)));
                    spendingTransactions = spendingTransactions.OrderBy(t => t.Date).ToList();
                    UpdateReportTransactionRunningBalances(spendingTransactions);
                }
            }

            // Copy running balance from transaction list into burndown chart data
            var actualSpending = new SeriesData
            {
                SeriesName = BurnDownChartAnalyserResult.BalanceSeriesName,
                Description = "Running balance over time as transactions spend, the balance decreases."
            };
            result.GraphLines.SeriesList.Add(actualSpending);
            foreach (var day in datesOfTheMonth)
            {
                if (day > DateTime.Today)
                {
                    break;
                }

                var dayClosingBalance = GetDayClosingBalance(spendingTransactions, day);
                actualSpending.PlotsList.Add(new DatedGraphPlot { Date = day, Amount = dayClosingBalance });
                var copyOfDay = day;
                this.logger.LogInfo(l => l.Format("    {0} Close Bal:{1:N}", copyOfDay, dayClosingBalance));
            }

            result.ReportTransactions = spendingTransactions;
            return result;
        }
 private static void CreateZeroLine(IEnumerable<DateTime> datesOfTheMonth, BurnDownChartAnalyserResult result)
 {
     var series = new SeriesData
     {
         SeriesName = BurnDownChartAnalyserResult.ZeroSeriesName,
         Description = "Zero line"
     };
     result.GraphLines.SeriesList.Add(series);
     foreach (var day in datesOfTheMonth)
     {
         series.PlotsList.Add(new DatedGraphPlot { Amount = 0, Date = day });
     }
 }
        private static void CalculateBudgetLineValues(decimal budgetTotal, List<DateTime> datesOfTheMonth,
                                                      BurnDownChartAnalyserResult result)
        {
            var average = budgetTotal / datesOfTheMonth.Count();

            var seriesData = new SeriesData
            {
                Description = "The budget line shows ideal linear spending over the month to keep within your budget.",
                SeriesName = BurnDownChartAnalyserResult.BudgetSeriesName
            };
            result.GraphLines.SeriesList.Add(seriesData);

            var iteration = 0;
            foreach (var day in datesOfTheMonth)
            {
                seriesData.PlotsList.Add(new DatedGraphPlot { Amount = budgetTotal - average * iteration++, Date = day });
            }
        }
        public BurnDownChartAnalyserResult Analyse(StatementModel statementModel, BudgetModel budgetModel,
                                                   IEnumerable <BudgetBucket> bucketsSubset, LedgerBook ledgerBook, DateTime beginDate)
        {
            if (statementModel == null)
            {
                throw new ArgumentNullException(nameof(statementModel));
            }

            if (budgetModel == null)
            {
                throw new ArgumentNullException(nameof(budgetModel));
            }

            List <BudgetBucket> bucketsCopy = bucketsSubset.ToList();

            this.logger.LogInfo(
                l => "BurnDownChartAnalyser.Analyse: " + string.Join(" ", bucketsCopy.Select(b => b.Code)));

            var result = new BurnDownChartAnalyserResult();

            List <DateTime> datesOfTheMonth = YieldAllDaysInDateRange(beginDate);
            var             lastDate        = datesOfTheMonth.Last();

            CreateZeroLine(datesOfTheMonth, result);

            var openingBalance = GetBudgetedTotal(budgetModel, ledgerBook, bucketsCopy, beginDate);

            CalculateBudgetLineValues(openingBalance, datesOfTheMonth, result);

            List <ReportTransactionWithRunningBalance> spendingTransactions = CollateStatementTransactions(statementModel, bucketsCopy, beginDate, lastDate,
                                                                                                           openingBalance);

            // Only relevant when calculating surplus burndown - ovespent ledgers are supplemented from surplus so affect its burndown.
            if (ledgerBook != null && bucketsCopy.OfType <SurplusBucket>().Any())
            {
                List <ReportTransaction> overSpentLedgers =
                    this.ledgerCalculator.CalculateOverspentLedgers(statementModel, ledgerBook, beginDate).ToList();
                if (overSpentLedgers.Any())
                {
                    spendingTransactions.AddRange(
                        overSpentLedgers.Select(t => new ReportTransactionWithRunningBalance(t)));
                    spendingTransactions = spendingTransactions.OrderBy(t => t.Date).ToList();
                    UpdateReportTransactionRunningBalances(spendingTransactions);
                }
            }

            // Copy running balance from transaction list into burndown chart data
            var actualSpending = new SeriesData
            {
                SeriesName  = BurnDownChartAnalyserResult.BalanceSeriesName,
                Description = "Running balance over time as transactions spend, the balance decreases."
            };

            result.GraphLines.SeriesList.Add(actualSpending);
            foreach (var day in datesOfTheMonth)
            {
                if (day > DateTime.Today)
                {
                    break;
                }

                var dayClosingBalance = GetDayClosingBalance(spendingTransactions, day);
                actualSpending.PlotsList.Add(new DatedGraphPlot {
                    Date = day, Amount = dayClosingBalance
                });
                var copyOfDay = day;
                this.logger.LogInfo(l => l.Format("    {0} Close Bal:{1:N}", copyOfDay, dayClosingBalance));
            }

            result.ReportTransactions = spendingTransactions;
            return(result);
        }