def add_new_data(new_data): if df_is_not_empty(new_data): warn('#add_data ------- Adding : -------') info_df(new_data) info('#add_data -----------------------------\n') data = concat_lines([read_data(), new_data]) save_data(data)
def add_new_deposit(new_dep): if df_is_not_empty(new_dep): warn('#add_deposit ------- Adding DEPOSIT: -------') info_df(new_dep) info('#add_deposit -----------------------------\n') deposit = concat_lines([read_deposit_input(), new_dep]) save_deposit_input(deposit)
def get_deposit_input_and_output(): deposit_input = read_deposit_input() deposit_output = get_deposit_output() all_deposit = concat_lines([deposit_input, deposit_output], join='inner') set_pandas_print_parameters() sort_df_by_descending_date(all_deposit) return all_deposit
def find_matches_gone_newsettled(new, gone, link_name, links_to_add): data = read_data() free_new = new[new['replaces_a_pending'] == False] for index_gone in gone.index.tolist(): link_value = get_loc_df(gone, index_gone, link_name) match = filter_df_one_value(free_new, link_name, link_value) if df_is_not_empty(match): index_new_settled = max(match.index) gone_transaction = gone.loc[index_gone] settled_transaction = new.loc[index_new_settled] warn('\n#merge_data ------- Identified : -------') info_df( concat_lines([ gone_transaction.to_frame().T, settled_transaction.to_frame().T ])) info('merge_data -----------------------------\n') to_relink_after_gone_replaced_with_settled(data, gone_transaction, settled_transaction, links_to_add) data = read_data() id_to_remove = gone.loc[index_gone, 'id'] recover_editable_fields(new, index_new_settled, gone, index_gone) drop_line_with_index(gone, index_gone) remove_data_on_id(id_to_remove) warn('#merge_data removing transaction' + '\n' + str(filter_df_one_value(data, 'id', id_to_remove))) assign_value_to_loc(new, index_new_settled, 'replaces_a_pending', True)
def _split_transaction(the_input, refund_transaction): split = make_split_transactions(refund_transaction, the_input) make_refund_split_transaction(refund_transaction) refund_id = get_first_value_from_series(refund_transaction['id']) all_transactions = concat_lines([split, refund_transaction]) set_value_to_column(all_transactions, 'split_field', refund_id) add_new_data(all_transactions) link_ids_if_possible(refund_id + ',' + the_input['id'])
def recap_by_account(cycle): field_name = account_col selected_columns = [amount_euro_col, field_name, currency_col] cycle = decode_cycle(cycle) data = get_data_from_cycle(cycle) process_currency_data(data) if cycle != 'all': is_deposit = column_is_null(data, deposit_name_col) == False deposit_transactions = filter_df_on_bools(data, is_deposit) add_column_with_value(deposit_transactions, account_col, deposit_account) reverse_amount(deposit_transactions) data = select_columns(concat_lines([data, deposit_transactions]), selected_columns) deposit = get_deposit_debits_from_cycle(cycle) data = concat_lines([deposit, data]) all_outputs = select_columns(data, selected_columns) recap = group_by_field(all_outputs, field_name).round(decimals=2) return recap
def make_split_transactions(transaction, the_input): transaction_split_1 = deepcopy(transaction) set_value_to_column(transaction_split_1, 'timestamp', get_timestamp_now()) transaction_split_2 = deepcopy(transaction) set_value_to_column(transaction_split_2, 'timestamp', get_timestamp_now()) for field in ['amount', 'category', 'cycle', 'name']: set_value_to_column(transaction_split_1, field, the_input[field + '1']) set_value_to_column(transaction_split_2, field, the_input[field + '2']) both = concat_lines([transaction_split_2, transaction_split_1]) set_value_to_column(both, 'type', 'FIC') create_id(both) return both
def recap_by_cat(cycle, round_it=True): output_columns = ['category', 'currency', 'spent', 'remaining', 'spent_from_budget', 'amount', 'budget', 'over'] data = get_data_from_cycle(cycle) deposit = get_deposit_debits_from_cycle(cycle) convert_non_euro_amounts(data) add_column_with_value(deposit, currency_col, default_currency) field_name = category_col selected_columns = [amount_euro_col, field_name, currency_col] data = filter_df_on_bools(data, column_is_null(data, deposit_name_col)) data = select_columns(data, selected_columns) deposit = select_columns(deposit, selected_columns) all_output = concat_lines([data, deposit]) if df_is_empty(all_output): return empty_df(columns=output_columns) spent = group_by_field(all_output, category_col).set_index(currency_col, append=True) if df_is_empty(spent): return empty_df(columns=output_columns) budgets = get_budgets(cycle).set_index(currency_col, append=True) rename_columns(budgets, {amount_euro_col: budgets_col}) recap = concat_columns([spent, budgets], keep_index_name=True).round(2).fillna(0).reset_index() recap = filter_df_not_these_values(recap, category_col, no_recap_categories) over = positive_part(- recap[amount_euro_col] - recap[budgets_col]) remaining = positive_part(recap[budgets_col] + recap[amount_euro_col]) spent = positive_part(- recap[amount_euro_col] - over) assign_new_column(recap, 'over', ceil_series(over) if round_it else over) assign_new_column(recap, 'remaining', floor_series(remaining) if round_it else remaining) assign_new_column(recap, 'spent_from_budget', ceil_series(spent) if round_it else spent) return recap
def layered_dict_to_df(payments): payments = [ dict_to_df(unnest_dictionary_layers(transaction)) for transaction in payments ] return concat_lines(payments)