This commit is contained in:
wuaho 2021-08-27 11:57:11 +08:00
parent e34d712705
commit a6655befdc
2 changed files with 5 additions and 2 deletions

View File

@ -168,9 +168,9 @@ async def event_model(
df = pd.concat([df, pd.DataFrame(concat_data, columns=df.columns)])
df.sort_values('date', inplace=True)
if len(df) >= 2:
q['chain_ratio'] = round((df.iloc[-1, 1] - df.iloc[-2, 1]) * 100 / df.iloc[-2, 1], 2)
q['chain_ratio'] = division((df.iloc[-1, 1] - df.iloc[-2, 1]) * 100 , df.iloc[-2, 1], 2)
if len(df) >= 8:
q['wow'] = round((df.iloc[-1, 1] - df.iloc[-8, 1]) * 100 / df.iloc[-8, 1], 2)
q['wow'] = division((df.iloc[-1, 1] - df.iloc[-8, 1]) * 100 / df.iloc[-8, 1], 2) or 0
q['values'].append(df['values'].to_list())
q['sum'].append(int(df['values'].sum()))
if item['time_particle'] in ('P1D', 'P1W'):

View File

@ -1,7 +1,10 @@
import numpy as np
def division(a, b, n=2):
res = 0
try:
res = round(a / b, n)
if np.isnan(res):
res = 0
except ZeroDivisionError:
pass
return res