def __init__(self, acc_user, acc_asset='', db=None, table='transactions', columns=[ 'id', 'acc_user', 'acc_asset', 'nam_asset', 'rmk_asset', 'amt_trans', 'tye_asset', 'ico_asset', 'tye_flow', 'dte_trans', 'tme_trans', 'acc_asset_related', 'nam_asset_related', 'rmk_asset_related', 'ico_asset_related', 'tye_asset_related', 'cod_trans_type', 'txt_trans_type', 'txt_trans_type_sub', 'txt_remark', 'ico_trans' ]): self.db = db self.table = table self.columns = columns self.dtype_columns = {} self.vdefault_columns = {} self.acc_user = acc_user self.acc_asset = acc_asset self.nam_asset = '' self.amt_trans = 0.0 self.tye_flow = '' self.dte_trans = '' self.tme_trans = '' self.acc_asset_related = '' self.nam_asset_related = '' self.cod_trans_type = '' self.txt_trans_type = '' self.txt_trans_type_sub = '' self.txt_remark = '' if not db: self.db = DataBase()
def main(db=None): if not db: db = DataBase() if backup_db(db): if init_db(db): if init_data(db): return True return False
def __init__(self, acc_user, dte_month=None, db=None, table='statistics', columns=['id', 'acc_user', 'dte_month', 'amt_income_month', 'amt_expend_month', 'amt_budget', 'amt_budget_surplus', 'amt_debt_total', 'amt_asset_total', 'amt_asset_net']): self.db = db self.table = table self.columns = columns self.acc_user = acc_user self.dte_month = dte_month if not self.db: self.db = DataBase()
def __init__(self, acc_user, db=None, table='assets', columns=[ 'id', 'acc_user', 'acc_asset', 'nam_asset', 'rmk_asset', 'tye_asset', 'amt_asset', 'ico_asset', 'boo_active' ]): self.db = db self.table = table self.columns = columns self.acc_user = acc_user self.df_asset = pd.DataFrame() if not self.db: self.db = DataBase()
def create_from_transactions(self, df_transactions): next_id = load_next_id() data_asset = [] nam_asset_list = df_transactions['nam_asset'].unique() for i in range(len(nam_asset_list)): id = next_id + i nam_asset = nam_asset_list[i] acc_asset = gen_short_uuid() tye_asset = '' amt_asset = 0.0 data_asset.append([ id, self.acc_user, acc_asset, nam_asset, tye_asset, amt_asset ]) self.df_asset = pd.DataFrame(data=data_asset, columns=self.columns) flag, result = DataBase().write(self.df_asset, self.table) print(flag, result) return self.acc_user
def create_from_default(self): if not self.df_transtype_default: next_id = load_next_id(self.table) df_transtype_default = pd.read_csv( os.path.join(self.base_path, file_default_transtype)) len_transtype_default = len(df_transtype_default) df_transtype_default['txt_trans_type_sub'] = [ '' ] * len_transtype_default df_transtype_default['acc_user'] = [self.acc_user ] * len_transtype_default df_transtype_default['id'] = [ next_id + i for i in range(len_transtype_default) ] flag, result = DataBase().write(df_transtype_default, self.table) if flag: self.df_transtype_default = df_transtype_default self.df_transtype = df_transtype_default return flag
def __init__(self, acc_user, db=None, table='transtypes', columns=[ 'id', 'acc_user', 'cod_trans_type', 'txt_trans_type', 'txt_trans_type_sub', 'tye_flow', 'boo_active', 'ico_trans' ]): self.db = db self.table = table self.columns = columns self.acc_user = acc_user self.cod_trans_type = '' self.txt_trans_type = '' self.txt_trans_type_sub = '' self.tye_flow = '' self.df_transtype = pd.DataFrame() self.df_transtype_default = None self.base_path = os.path.dirname(__file__) if not self.db: self.db = DataBase()
def __init__(self, acc_user=None, pwd_user_md5=None, db=None, table='users', columns=[ 'id', 'acc_user', 'pwd_user_md5', 'nam_user', 'vlu_email', 'vlu_phone', 'vlu_openid', 'nam_nick', 'cod_gender', 'vlu_lang', 'vlu_city', 'vlu_prov', 'vlu_country', 'url_avatar' ]): self.db = db self.table = table self.columns = columns self.acc_user = acc_user self.pwd_user_md5 = pwd_user_md5 self.nam_user = '' self.vlu_email = '' self.vlu_phone = '' self.vlu_openid = '' if not self.db: self.db = DataBase()
def backup_db(db=None, batch=50000): if not db: db = DataBase() path = mkdir() flag, result = db.read('show tables') if flag: df_tables = result for table in df_tables.values[:, 0]: num_line = load_next_id(table, db) - 1 filename = os.path.join(path, '%s.csv' % table) for index in range(1 + int(num_line / batch)): offset = batch * index flag, result = db.read('select * from %s limit %s,%s' % (table, offset, batch)) if flag: result.to_csv(filename, index=False, mode='a', header=True if index == 0 else None) # 追加写入 else: print(result) else: print(result) return flag