def get_common_row(stock_id, col_name, db_session=db_info, db=Info, p=__proc1): a = FmUtils() trans = a.load_from_json("./json/trans.json") trans = a.swap_dict(trans) name = a.load_from_json("./json/table_trans.json") name = a.swap_dict(name) exclude = ['revenue'] if col_name == "date": decor = [False, "", False] elif col_name in exclude: decor = [False, "Y", False] else: decor = a.load_from_json("./json/decor.json") decor = decor[trans[col_name]] if decor[1] == "%": decor[1] = "\\%" print(col_name) print(decor) res = db_session.query(getattr(db, col_name)).filter( db.stock_id == stock_id).order_by(desc(db.date)).all() if col_name == "date": line = "" elif col_name in exclude: line = name[col_name] res.pop() else: line = trans[col_name] # check if exists for i in res: if col_name == "date": line = line + "& " + str(i[0]) + decor[1] + " " else: line = line + "& " + str(p(i[0])) + decor[1] + " " line += "\\\\" if decor[0]: line = "\\rowcolor[gray]{0.9}" + line if decor[2] == 'dot': line = line + "\\hdashline" if decor[2] == 'solid': line = line + "\midrule" return (line)
from sqlalchemy import exists, and_, or_ a = FmUtils() stock_id = '002372' for ayear in range(2010, 2018): year = [str(ayear), str(ayear - 1)] rec = a.load_from_json("./json/table_trans.json") # load trans rec = dict(rec) tmp = [] for i in rec: if rec[i] == '0': tmp.append(i) for i in tmp: rec.pop(i) rec = a.swap_dict(rec) last = dict() this = dict() for i in rec.keys(): tmp = float(db_info.query(getattr(Concise_Table,i)).filter(and_(Concise_Table.date ==year[0]\ ,Concise_Table.stock_id==stock_id)).all()[0][0]) tmp1 = float(db_info.query(getattr(Concise_Table,i)).filter(and_(Concise_Table.date ==year[1]\ ,Concise_Table.stock_id==stock_id)).all()[0][0]) last[i] = tmp1 this[i] = tmp # TODO check revenue and total revenue