Spaces:
Runtime error
Runtime error
import requests | |
import json | |
import pickle | |
import os | |
class auto_arima(): | |
def __init__(self, apikey) -> None: | |
self.apikey = apikey | |
def parse_res(self, res): | |
if str(res.status_code)[0] != '2': | |
raise ValueError('auto_arima API Call Failed!\n', res.text) | |
else: | |
parsed_res = res.json() | |
return parsed_res | |
def forecast( | |
self, | |
ts_list, | |
n_predict: int, | |
seasonal_cycle=None): | |
endpoint = 'https://idsc.com.sg/foretell/prediction/time-series/continuous/arima' | |
payloads = { | |
'time_series_data': ts_list, | |
'num_predict': n_predict} | |
headers = {'api-key': self.apikey} | |
res = requests.post(endpoint, json=payloads, headers=headers) | |
self.__save_res(res) | |
print('auto_arima_______') | |
print(res) | |
return self.parse_res(res) | |
def __save_res(self, res): | |
# The successful res is based on "data/test.csv" | |
script_dir = os.path.dirname(__file__) | |
rel_path = "./tests/auto_arima_success_res.dict" | |
abs_file_path = os.path.join(script_dir, rel_path) | |
with open(abs_file_path, 'wb') as f: | |
pickle.dump(res, f) | |
def __load_res(self): | |
# The successful res is based on "data/test.csv" | |
script_dir = os.path.dirname(__file__) | |
rel_path = "./tests/auto_arima_success_res.dict" | |
abs_file_path = os.path.join(script_dir, rel_path) | |
with open(abs_file_path, 'rb') as f: | |
res = pickle.load(f) | |
return res | |