Skip to content

Commit

Permalink
Update model.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lm-cyber authored Apr 17, 2024
1 parent 485e948 commit 2d30845
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions app/model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
from schema import ModelDayInput
import joblib
from collections import defaultdict
import random


class Model:
"""заплатка что с моделью"""

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

def forward(self, data: ModelDayInput):
return self.model(data)
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)

0 comments on commit 2d30845

Please sign in to comment.