dev
timofejmalinin 3 years ago
parent 8f54c897c1
commit 47740d6600

@ -8,7 +8,7 @@ def raschet_real(df, koefs):
df['rate'] = df['rate'] / koef_summ
return df
def raschet(tables, filters, koefs):
def raschet(tables, filters, koefs, method):
conn = sqlalchemy.create_engine(settings.DB_URL, connect_args={'options': '-csearch_path=public'})
msk_ao = filters.get('msk_ao')
msk_rayon = filters.get('msk_rayon')
@ -27,9 +27,12 @@ def raschet(tables, filters, koefs):
else:
query = f"select * from {table} where category in ({categories});" if len(categories) > 0 else f"select * from {table};"
points = pd.read_sql(query, conn)
points_df = raschet_real(points, koefs)
if rate_from is not None and rate_to is not None:
points_df = points_df[(points_df['rate'] >= rate_from) & (points_df['rate'] <= rate_to)]
if method == 'rate':
points_df = raschet_real(points, koefs)
if rate_from is not None and rate_to is not None:
points_df = points_df[(points_df['rate'] >= rate_from) & (points_df['rate'] <= rate_to)]
else:
points_df = points[(points['model'] >= rate_from) & (points['model'] <= rate_to)]
if 'net' in table:
if msk_ao is not None:
@ -39,8 +42,11 @@ def raschet(tables, filters, koefs):
else:
query = f"select * from {table};"
nets = pd.read_sql(query, conn)
nets_df = raschet_real(nets, koefs)
if rate_from is not None and rate_to is not None:
nets_df = nets_df[(nets_df['rate'] >= rate_from) & (nets_df['rate'] <= rate_to)]
if method == 'rate':
nets_df = raschet_real(nets, koefs)
if rate_from is not None and rate_to is not None:
nets_df = nets_df[(nets_df['rate'] >= rate_from) & (nets_df['rate'] <= rate_to)]
else:
nets_df = nets[(nets['model'] >= rate_from) & (nets['model'] <= rate_to)]
return points_df, nets_df

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save