File size: 951 Bytes
89eb9ba 0a7b47e d7df8d0 0a7b47e d7df8d0 0a7b47e d7df8d0 89eb9ba 8c63991 d7df8d0 89eb9ba d7df8d0 89eb9ba 0a7b47e 89eb9ba 8c63991 89eb9ba 0a7b47e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import json
from typing import _ProtocolMeta
from restful.cutils.utilities import Utilities
from restful.schemas import ForecastingServiceSchema
""" Forecasting Service """
class ForecastingService:
__FORECAST_UTILS = Utilities()
async def forecasting(self, payload: ForecastingServiceSchema, caching: _ProtocolMeta) -> dict:
caching_data = caching.get(
f'CRYPTO_{payload.algorithm}_{payload.currency}_{payload.days}')
actuals, predictions = await self.__FORECAST_UTILS.forecasting_utils(
days = payload.days,
algorithm = payload.algorithm,
model_name = payload.currency,
with_pred = (caching_data == None),
sequence_length = 60
)
if caching_data != None:
predictions = json.loads(caching_data.decode('utf-8'))
else:
caching.set(
f'CRYPTO_{payload.algorithm}_{payload.currency}_{payload.days}',
json.dumps(predictions)
)
return {'actuals': actuals, 'predictions': predictions}
|