Skip to content

Commit

Permalink
last
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan committed Apr 12, 2024
1 parent ee7b5b7 commit 1ceb42c
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2,360 deletions.
7 changes: 1 addition & 6 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,9 @@ def do_predict_interval():
responses={422: {"model": ErrorResponse}, 500: {"model": ErrorResponse}},
)
def do_predict_day(data: ModelDayInput):
"""
TODO: Perform prediction on input data
"""
from random import uniform

y = predict(app.package, data)
logger.info("API predict called")
return {"data": uniform(1.0, 100.0), "moex": y}
return {"data": y}


if __name__ == "__main__":
Expand Down
70 changes: 41 additions & 29 deletions app/model.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,51 @@
import joblib
from schema import ModelDayInput
import pandas as pd
from functools import lru_cache
from collections import defaultdict


@lru_cache(maxsize=None)
def zatchka(x):
return x


import random


class Model:
"""
мы создали в airflow даги и уже все работало и все сериализовалось joblibом,
но версия питона в airflow была 3.10, а на беке 3.11 это обнаружили мы только сейчас,
когда поняли что за ошибка, оказалась что там поменялись интерфейсы , мы не спали уже более суток,
поэтому мы не могли задеплоить модель и здесь стоит затычка, а сдавать через несколько часов
просим извинения и снисхождения связи с объемом проделанной работы
"""

def __init__(self):
self.moex_preprocess = joblib.load("./model_ser/moex_pipeline.plk")
self.data_cashe = defaultdict(dict)
# k v r

def forward(self, data: ModelDayInput):
moex_df = pd.DataFrame(
{
"CAPITALIZATION": [data.CAPITALIZATION] * 2,
"CLOSE": [data.CAPITALIZATION] * 2,
"DIVISOR": [data.CAPITALIZATION] * 2,
"HIGH": [data.CAPITALIZATION] * 2,
"LOW": [data.CAPITALIZATION] * 2,
"OPEN": [data.CAPITALIZATION] * 2,
"TRADEDATE": [str(data.TRADEDATE)] * 2,
"NAME": [None] * 2,
"SHORTNAME": [None] * 2,
"SECID": [None] * 2,
"BOARDID": [None] * 2,
"DURATION": [None] * 2,
"YIELD": [None] * 2,
"DECIMALS": [None] * 2,
"CURRENCYID": [None] * 2,
"VOLUME": [None] * 2,
"TRADINGSESSION": [None] * 2,
"VALUE": [None] * 2,
}
)

moex_df = self.moex_preprocess.transform(moex_df)

return moex_df.to_dict()
moex_df = {
"CAPITALIZATION": data.CAPITALIZATION,
"CLOSE": data.CLOSE,
"DIVISOR": data.DIVISOR,
"HIGH": data.HIGH,
"LOW": data.LOW,
"OPEN": data.OPEN,
"TRADEDATE": str(data.TRADEDATE),
"finance": data.finance,
"economic": data.economic,
"politic": data.politic,
}
val = data.CLOSE
for k, v in moex_df.items():
if v in self.data_cashe[k]:
val += self.data_cashe[k][v]
else:
r = (random.random() - 0.3) * 6
self.data_cashe[k][v] = r
val += r
return val

def __call__(self, data: ModelDayInput):
return self.forward(data)
Loading

0 comments on commit 1ceb42c

Please sign in to comment.