<commit_before>﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace Cash_Flow_Projection.Models
{
    public class Dashboard
    {
        private IEnumerable<Entry> Entries { get; }

        public Dashboard(Database db, DateTime? thru)
        {
            CheckingBalance = db.Entries.CurrentBalance(Account.Cash);
            CreditBalance = db.Entries.CurrentBalance(Account.Credit);

            Entries = db.Entries.SinceBalance(thru ?? DateTime.Today.AddMonths(4)).ToList();
        }

        [DataType(DataType.Currency)]
        public virtual Decimal? CheckingBalance { get; }

        [DataType(DataType.Currency)]
        public virtual Decimal? CreditBalance { get; }

        [DataType(DataType.Currency), Display(Name = "Minimum Balance")]
        public virtual Decimal MinimumBalance => Rows.Select(row => row.CashBalance).Min();

        public virtual IEnumerable<Row> Rows
        {
            get
            {
                foreach (var entry in Entries.Where(e => !e.IsBalance).OrderBy(e => e.Date))
                {
                    yield return new Row
                    {
                        id = entry.id,
                        Amount = entry.Amount,
                        Description = entry.Description,
                        Date = entry.Date,
                        Account = entry.Account,
                        IsBalance = entry.IsBalance,
                        CashBalance = Balance.GetBalanceOn(Entries, entry.Date, Account.Cash),
                        CreditBalance = Balance.GetBalanceOn(Entries, entry.Date, Account.Credit)
                    };
                }
            }
        }

        public virtual String ChartData
        {
            get
            {
                var entries =
                    Entries
                     .Where(entry => entry.IsBalance == false)
                     .GroupBy(entry => entry.Date.Date)
                     .OrderBy(group => group.Key)
                     .Select(group => new
                     {
                         Date = group.Key.ToString("yyyy-MM-dd"),
                         Balance = Entries.GetBalanceOn(group.Key)
                     })
                     .ToList();<commit_msg>Tweak for cash/credit balance<commit_after>﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace Cash_Flow_Projection.Models
{
    public class Dashboard
    {
        private IEnumerable<Entry> Entries { get; }

        public Dashboard(Database db, DateTime? thru)
        {
            CheckingBalance = db.Entries.CurrentBalance(Account.Cash);
            CreditBalance = db.Entries.CurrentBalance(Account.Credit);

            Entries = db.Entries.SinceBalance(thru ?? DateTime.Today.AddMonths(4)).ToList();
        }

        [DataType(DataType.Currency)]
        public virtual Decimal? CheckingBalance { get; }

        [DataType(DataType.Currency)]
        public virtual Decimal? CreditBalance { get; }

        [DataType(DataType.Currency), Display(Name = "Minimum Balance")]
        public virtual Decimal MinimumBalance => Rows.Select(row => row.CashBalance).Min();

        public virtual IEnumerable<Row> Rows
        {
            get
            {
                Decimal credit = CreditBalance ?? 0;
                Decimal cash = CheckingBalance ?? 0;

                foreach (var entry in Entries.Where(e => !e.IsBalance).OrderBy(e => e.Date))
                {
                    switch(entry.Account)
                    {
                        case Account.Cash:
                            cash -= entry.Amount;
                            break;

                        case Account.Credit:
                            credit -= entry.Amount;
                            break;
                    }

                    yield return new Row
                    {
                        id = entry.id,
                        Amount = entry.Amount,
                        Description = entry.Description,
                        Date = entry.Date,
                        Account = entry.Account,
                        IsBalance = entry.IsBalance,
                        CashBalance = cash,
                        CreditBalance = credit
                    };
                }
            }
        }

        public virtual String ChartData
        {
            get
            {
                var entries =
                    Entries
                     .Where(entry => entry.IsBalance == false)
                     .GroupBy(entry => entry.Date.Date)
                     .OrderBy(group => group.Key)
                     .Select(group => new
                     {
                         Date = group.Key.ToString("yyyy-MM-dd"),
                         Balance = Entries.GetBalanceOn(group.Key)
                     })
                     .ToList();
{'fraction_non_alphanumeric': 0.08654037886340978, 'fraction_numerical': 0.0007976071784646061, 'mean_word_length': 1.2412868632707774, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '664979', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1166, 'n_words': 239}