Exemplo n.º 1
0
        private TransactionBalance[] GetTransactions(TimeGroupingType grouping, DateTime minDate, DateTime maxDate,
                                                     TransactionTypeSelection selection)
        {
            var groupingSelector = GetGroupingSelector(grouping);

            Func <Transaction, bool> valuesPicker = null;

            switch (selection)
            {
            case TransactionTypeSelection.Income:
                valuesPicker = x => (ShowTransfers ? x.ValueWithSign : x.ValueAsProfit) > 0;
                break;

            case TransactionTypeSelection.Outcome:
                valuesPicker = x => (ShowTransfers ? x.ValueWithSign : x.ValueAsProfit) < 0;
                break;

            case TransactionTypeSelection.Balance:
                valuesPicker = x => true;
                break;
            }

            if (valuesPicker == null)
            {
                return(new TransactionBalance[0]);
            }

            return(FillMissingEntriesWithZeroValue(
                       MatchingTransactions
                       .Where(valuesPicker)
                       .GroupBy(x => groupingSelector(x.BookDate))
                       .Select(x => new TransactionBalance(x.Key, x.Sum(y => (ShowTransfers ? y.ValueWithSign : y.ValueAsProfit))))
                       .OrderBy(x => x.BookDate), minDate, maxDate, grouping));
        }
Exemplo n.º 2
0
        private static Func <DateTime, DateTime> GetGroupingSelector(TimeGroupingType grouping)
        {
            switch (grouping)
            {
            case TimeGroupingType.Month:
                return(x => new DateTime(x.Year, x.Month, 1));

            case TimeGroupingType.Year:
                return(x => new DateTime(x.Year, 1, 1));
            }

            return(null);
        }
Exemplo n.º 3
0
        private void SetTwoColorArea(TransactionBalance[] values, PlotModel model, OxyColor color, TimeGroupingType groupingType)
        {
            //lets make it rectangle area by adding same value and the end of the month
            var rectValues = CreateDuplicateTransactionBalancesAtEndOfGroupingPeriod(values, groupingType);

            model.Series.Add(new TwoColorAreaSeries
            {
                ItemsSource = rectValues,
                Limit       = 0,
                Color       = color,
                Color2      = OxyColors.Red,
                Mapping     = x => new DataPoint(DateTimeAxis.ToDouble(((TransactionBalance)x).BookDate),
                                                 (double)((TransactionBalance)x).Value),
                TrackerFormatString = groupingType == TimeGroupingType.Month
                                          ? _areaTrackerMonthFormatString
                                          : _areaTrackerYearFormatString
            });
        }
Exemplo n.º 4
0
        private static TransactionBalance[] CreateDuplicateTransactionBalancesAtEndOfGroupingPeriod(TransactionBalance[] values,
                                                                                                    TimeGroupingType grouping)
        {
            Func <TransactionBalance, TransactionBalance> selector = null;

            switch (grouping)
            {
            case TimeGroupingType.Month:
                selector = x => new TransactionBalance(x.BookDate.AddMonths(1).AddSeconds(-1), x.Value);
                break;

            case TimeGroupingType.Year:
                selector = x => new TransactionBalance(x.BookDate.AddYears(1).AddSeconds(-1), x.Value);
                break;
            }

            if (selector == null)
            {
                return(values);
            }
            var rectValues = values.Concat(values.Select(selector))
                             .OrderBy(x => x.BookDate)
                             .ToArray();

            return(rectValues);
        }
Exemplo n.º 5
0
        private static TransactionBalance[] FillMissingEntriesWithZeroValue(IEnumerable <TransactionBalance> values, DateTime minDate,
                                                                            DateTime maxDate, TimeGroupingType grouping)
        {
            var selector   = GetGroupingSelector(grouping);
            var dict       = values.ToDictionary(x => selector(x.BookDate), x => x.Value);
            int startMonth = grouping == TimeGroupingType.Month ? minDate.Month : 1;
            var actualDate = new DateTime(minDate.Year, startMonth, 1);

            while (actualDate < maxDate)
            {
                if (!dict.ContainsKey(actualDate))
                {
                    dict[actualDate] = 0;
                }
                switch (grouping)
                {
                case TimeGroupingType.Month:
                    actualDate = actualDate.AddMonths(1);
                    break;

                case TimeGroupingType.Year:
                    actualDate = actualDate.AddYears(1);
                    break;
                }
            }

            values = dict.OrderBy(x => x.Key).Select(x => new TransactionBalance(x.Key, x.Value)).ToArray();
            return(values.ToArray());
        }