1
This commit is contained in:
parent
e34d712705
commit
a6655befdc
@ -168,9 +168,9 @@ async def event_model(
|
|||||||
df = pd.concat([df, pd.DataFrame(concat_data, columns=df.columns)])
|
df = pd.concat([df, pd.DataFrame(concat_data, columns=df.columns)])
|
||||||
df.sort_values('date', inplace=True)
|
df.sort_values('date', inplace=True)
|
||||||
if len(df) >= 2:
|
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:
|
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['values'].append(df['values'].to_list())
|
||||||
q['sum'].append(int(df['values'].sum()))
|
q['sum'].append(int(df['values'].sum()))
|
||||||
if item['time_particle'] in ('P1D', 'P1W'):
|
if item['time_particle'] in ('P1D', 'P1W'):
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
|
import numpy as np
|
||||||
def division(a, b, n=2):
|
def division(a, b, n=2):
|
||||||
res = 0
|
res = 0
|
||||||
try:
|
try:
|
||||||
res = round(a / b, n)
|
res = round(a / b, n)
|
||||||
|
if np.isnan(res):
|
||||||
|
res = 0
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
pass
|
pass
|
||||||
return res
|
return res
|
||||||
|
Loading…
Reference in New Issue
Block a user