def __call__(self): bucket = PeriodCollate( self._period_start.date, self._period_end.date, debit_credit_generator, store_credit_debit, frequency=self._period_size.frequency, interval=self._period_size.interval, ) for account in account_walker(self._income + self._expenses, ignore_list=self._ignore_accounts): for split in get_splits(account, self._period_start.date, self._period_end.date): bucket.store_value(split) return_value = self._generate_result() credit_values = [] debit_values = [] difference_value = [] for key, value in bucket.container.iteritems(): time_value = time.mktime(key.timetuple()) # Have to switch the signs so that the graph will make sense. In GNUCash the income accounts are debited # when paid, and the expense accounts are 'credited' when purchased. credit_values.append(dict(date=time_value, value=-value["credit"])) debit_values.append(dict(date=time_value, value=-value["debit"])) difference_value.append(dict(date=time_value, value=-(value["debit"] + value["credit"]))) # Income accounts are the debits, and Expense accounts are the credits. return_value["data"]["expenses"] = sorted(credit_values, key=lambda s: s["date"]) return_value["data"]["income"] = sorted(debit_values, key=lambda s: s["date"]) return_value["data"]["net"] = sorted(difference_value, key=lambda s: s["date"]) return return_value
def __call__(self): start_of_trend = self._period_start.date end_of_trend = self._period_end.date asset_bucket = PeriodCollate(start_of_trend, end_of_trend, decimal_generator, split_summation, frequency=self._period_size.frequency, interval=self._period_size.interval) liability_bucket = PeriodCollate(start_of_trend, end_of_trend, decimal_generator, split_summation, frequency=self._period_size.frequency, interval=self._period_size.interval) net_bucket = PeriodCollate(start_of_trend, end_of_trend, decimal_generator, split_summation, frequency=self._period_size.frequency, interval=self._period_size.interval) currency = get_currency() # Calculate the asset balances for account in account_walker(self._asset_accounts): for key, value in asset_bucket.container.iteritems(): balance = get_balance_on_date(account, key, currency) asset_bucket.container[key] += balance # Calculate the liability balances for account in account_walker(self._liability_accounts): for key, value in liability_bucket.container.iteritems(): balance = get_balance_on_date(account, key, currency) liability_bucket.container[key] += balance # Now calculate the net values from the difference. for key, value in liability_bucket.container.iteritems(): net_bucket.container[key] = asset_bucket.container[key] + liability_bucket.container[key] result = self._generate_result() result['data']['assets'] = sorted([dict(date=time.mktime(key.timetuple()), value=value) for key, value in asset_bucket.container.iteritems()], key=lambda s: s['date']) result['data']['liabilities'] = sorted([dict(date=time.mktime(key.timetuple()), value=-value) for key, value in liability_bucket.container.iteritems()], key=lambda s: s['date']) result['data']['net'] = sorted([dict(date=time.mktime(key.timetuple()), value=value) for key, value in net_bucket.container.iteritems()], key=lambda s: s['date']) inflation = get_monthly_inflation() starting_point = None inflation_data = [] for record in result['data']['net']: if starting_point: starting_point += (starting_point * inflation) else: starting_point = record['value'] inflation_data.append(dict(date=record['date'], value=starting_point)) result['data']['inflation'] = inflation_data return result
def __call__(self): investment_value = dict() buckets = PeriodCollate(self._period_start.date, self._period_end.date, investment_bucket_generator, store_investment, frequency=self._period_size.frequency, interval=self._period_size.interval) start_value = Decimal('0.0') start_value_date = self._period_start.date - relativedelta(days=1) currency = get_currency() for account in account_walker(self._investment_accounts, ignore_list=self._ignore_accounts): for split in get_splits(account, self._period_start.date, self._period_end.date): buckets.store_value(split) start_value += get_balance_on_date(account, start_value_date, currency) for key in buckets.container.keys(): date_value = key + relativedelta(months=1) - relativedelta(days=1) investment_value[key] = investment_value.get(key, Decimal('0.0')) + get_balance_on_date(account, date_value, currency) results = self._generate_result() results['data']['start_value'] = start_value results['data']['income'] = sorted( [(time.mktime(key.timetuple()), value['income']) for key, value in buckets.container.iteritems()], key=itemgetter(0)) results['data']['money_in'] = sorted( [(time.mktime(key.timetuple()), value['money_in']) for key, value in buckets.container.iteritems()], key=itemgetter(0)) results['data']['expense'] = sorted( [(time.mktime(key.timetuple()), value['expense']) for key, value in buckets.container.iteritems()], key=itemgetter(0)) results['data']['value'] = sorted( [[time.mktime(key.timetuple()), value] for key, value in investment_value.iteritems()], ) results['data']['basis'] = sorted( [[time.mktime(key.timetuple()), Decimal('0.0')] for key in buckets.container.keys()], key=itemgetter(0) ) monthly_start = start_value for index, record in enumerate(results['data']['basis']): record[1] += (monthly_start + results['data']['income'][index][1] + results['data']['money_in'][index][1] + results['data']['expense'][index][1]) monthly_start = record[1] return results
def __call__(self): bucket = PeriodCollate(self._start.date, self._end.date, decimal_generator, split_summation, frequency=self._size.frequency, interval=self._size.interval) record_count = PeriodCollate(self._start.date, self._end.date, integer_generator, count, frequency=self._size.frequency, interval=self._size.interval) for account in account_walker(self.expenses_base, self.ignore_list): for split in get_splits(account, self._start.date, self._end.date): bucket.store_value(split) record_count.store_value(split) return_value = self._generate_result() sorted_results = [] sorted_count_results = [] for key, value in bucket.container.iteritems(): sorted_results.append(dict(date=time.mktime(key.timetuple()), value=value)) for key, value in record_count.container.iteritems(): sorted_count_results.append(dict(date=time.mktime(key.timetuple()), value=value)) return_value['data']['expenses'] = sorted(sorted_results, key=lambda s: s['date']) if self._show_record_count: return_value['data']['count'] = sorted(sorted_count_results, key=lambda s: s['date']) return return_value
def __call__(self): bucket = PeriodCollate(self._start.date, self._end.date, decimal_generator, split_summation, frequency=self._size.frequency, interval=self._size.interval) for account in account_walker(self.expenses_base, self.ignore_list): for split in get_splits(account, self._start.date, self._end.date): bucket.store_value(split) return_value = self._generate_result() results = [] for key, value in bucket.container.iteritems(): results.append(float(value)) return_value['data']['low'] = np.percentile(results, 0) return_value['data']['high'] = np.percentile(results, 100) return_value['data']['q1'] = np.percentile(results, 25) return_value['data']['q2'] = np.percentile(results, 50) return_value['data']['q3'] = np.percentile(results, 75) return return_value
def __call__(self): bucket = PeriodCollate(self._start.date, self._end.date, debit_credit_generator, store_credit_debit, frequency=self._size.frequency, interval=self._size.interval) for account in account_walker(self._account_names): for split in get_splits(account, self._start.date, self._end.date): bucket.store_value(split) return_value = self._generate_result() credit_values = [] debit_values = [] difference_value = [] for key, value in bucket.container.iteritems(): credit_values.append(dict(date=time.mktime(key.timetuple()), value=value['credit'])) debit_values.append(dict(date=time.mktime(key.timetuple()), value=value['debit'])) difference_value.append(dict(date=time.mktime(key.timetuple()), value=value['credit'] + value['debit'])) return_value['data']['credits'] = sorted(credit_values, key=lambda s: s['date']) return_value['data']['debits'] = sorted(debit_values, key=lambda s: s['date']) return_value['data']['gross'] = sorted(debit_values, key=lambda s: ['date']) return return_value