-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alan
committed
Apr 12, 2024
1 parent
ee7b5b7
commit 1ceb42c
Showing
6 changed files
with
59 additions
and
2,360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.