def histogram_value_grouped(history_len):
    print(pathlib.Path(__file__).parent.absolute())
    print(pathlib.Path().absolute())
    q = f"select date_shamsi,SUM(value) as value  from stock_price group by dtyyyymmdd order by date_shamsi desc limit  {history_len} "
    total = pd.read_sql(q, db.engine)

    codes = db.session.query(db.distinct(Stocks.group_code)).all()

    for i, code in enumerate(codes):
        print(code[0])
        q = f"""select date_shamsi,group_name,SUM(value) as value
                from(select * from stock_price Stock_price , stocks Stock where Stock.code = Stock_price.code) where group_code == {code[0]}
                group by dtyyyymmdd,group_code order by date_shamsi desc limit {history_len}
                """
        data = pd.read_sql(q, db.engine)
        result = pd.merge(total, data, on='date_shamsi')
        if len(result) != 0:
            result['ratio'] = (result.value_y / result.value_x) * 100
            ax = plt.gca()
            result.plot(kind='bar', x='date_shamsi', y='ratio', ax=ax, color='green')

            reshaped_text = \
                arabic_reshaper.reshape(result.group_name.iloc[0])
            text = get_display(reshaped_text)
            ax.set_title(text)

            plt.savefig(f'../../output/reports/{code[0]}.png')
            ax.cla()

    return None
Esempio n. 2
0
def get_all_price():
    codes = db.session.query(db.distinct(Stocks.group_code)).all()
    for i, code in enumerate(codes):
        print("progress {100*int((i+1)/len(codes):.2f)}")
        update_group(code)

    print("Download Finished.")
Esempio n. 3
0
def get_all_price():
    codes = db.session.query(db.distinct(Stocks.group_code)).all()
    for i, code in enumerate(codes):
        print(f"                         total progress: {100*(i+1)/len(codes):.2f}%", end="\r")
        update_group(code[0])

    print("Download Finished.")