def classify_db_by_lookup_cli(db_path, label_file, classify_if_not_null): """ Classify transactions in a database given a description->label mapping file as input Args:\n db_path (str): Path to the database to classify data in\n label_file (str): Path to the csv description->label file """ global_init(db_path) classify_db_by_lookup(label_file, classify_if_not_null)
def export_to_csv(db_path, csv_file): """ Exports database to CSV. WARNING: Not tested fully for round-trip Args: db_path (str): Path to source DB csv_file (str): Filename to write db to """ global_init(db_path) to_csv(csv_file)
def classify_by_most_common_cli(db_path, scheme, n_classifications_per_trx, if_scheme_exists): """ Create suggested categories in a db by using the n most common accepted categories for that description Args:\n db_path (str): Path to the database to classify data in\n scheme (str): Scheme name for the created suggested categories """ global_init(db_path) classify_by_most_common(scheme=scheme, if_scheme_exists=if_scheme_exists, n_classifications_per_trx=n_classifications_per_trx )
def classify_by_model_cli(db_path, scheme, model, if_scheme_exists): """ Create suggested categories in a db by using a sklearn model Args:\n db_path (str): Path to the database to classify data in\n scheme (str): Scheme name for the created suggested categories model (str): Path to a model saved using joblib """ global_init(db_path) clf = joblib.load(model) classify_by_model(scheme=scheme, clf=clf, if_scheme_exists=if_scheme_exists, n_classifications_per_trx=1 )
def add(db_path, csv_file, csv_flavor, account_name, accept): """ Add transactions to a database from a csv file, creating the database if required Args: \n db_path (str): Path to the database to add transactions to \n csv_file (str): Path to the csv file to load and extract transactions from\n csv_flavor (str): One of:\n mint: Mint-formatted csv file\n pc_mc: PC Mastercard formatted csv file\n """ # Initialize db connection global_init(db_path, False) df = import_csv_as_df(csv_file, csv_flavor, account_name) print(df) add_transactions_from_dataframe(df, accept_category=accept)
def accept_current(db_path, scheme): """ Moves all categories used by Transaction.category to the "accepted" scheme, removing any stale "accepted" categories Stale "accepted" categories are any categories in the accepted scheme now that are no longer attached to a Transaction.category Args: db_path (str): Path to the DB to be edited scheme (str): Scheme name for the "accepted" scheme Side Effects: Removes all categories in scheme that are no longer accepted Modifies all categories that are accepted to now be in the accepted scheme Returns: None """ # Initialize db connection global_init(db_path, False) accept_current_chosen_categories(scheme)
def from_db(cls, db_file=None, feature_column='description', label_column='category'): """ Returns a classifier fitted to the records in db_file This feels a bit too single-purpose and more like a service, but putting it here makes things easy for now... Args: db_file (str): Path to a database file feature_column (str): Name of the db column to use as a feature label_column (str): Name of the db column to use as a label Returns: Fitted CommonUsageClassifier """ if db_file: global_init(db_file, echo=False) # Else we assume the db is initialized df = get_transactions_with_category(return_type='df') clf = cls() clf.fit(df[feature_column], df[label_column]) return clf
return div_style, fig @app.callback(Output(RAW_DATA_ID, "children"), [Input("reload-button", "n_clicks")]) def reload_data(nclicks): if nclicks == 0: raise dash.exceptions.PreventUpdate() raw_data = get_transactions("df").to_json(orient="table") return raw_data def parse_args(): parser = argparse.ArgumentParser() parser.add_argument( "db", help="Path to transactions database", ) return parser.parse_args() if __name__ == '__main__': args = parse_args() global_init(args.db, echo=False) app.layout = get_app_layout() app.run_server(debug=True, port=8051)
raise ValueError("Cannot find active row") return this_row # CLI def parse_args(): parser = argparse.ArgumentParser() parser.add_argument( "db", help="Path to transactions database", ) return parser.parse_args() if __name__ == '__main__': args = parse_args() global_init(args.db, echo=True) app.layout = get_app_layout(db_file=args.db) ports = range(8850, 8860, 1) for port in ports: try: print(f"TRYING PORT {port}") app.run_server(debug=True, port=port) except OSError: continue break
def db_init(): # global_init builds tables and populates session factory global_init('', echo=True) yield global_forget()