Spaces:
Running
Running
Update restful/onnx_utilities.py
Browse files- restful/onnx_utilities.py +10 -2
restful/onnx_utilities.py
CHANGED
@@ -13,8 +13,15 @@ class Utilities:
|
|
13 |
self.posttrained_path = './indonesia_stocks/modeling_datas'
|
14 |
self.scaler_path = './indonesia_stocks/min_max'
|
15 |
|
|
|
|
|
16 |
def truncate_2_decimal(self, val: float):
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def denormalization(self, data, min_value, max_value):
|
20 |
return (data * (max_value - min_value)) + min_value
|
@@ -58,7 +65,8 @@ class Utilities:
|
|
58 |
value = np.array(predicted).flatten()[0]
|
59 |
denorm_price = (value * (max_close - min_close)) + min_close
|
60 |
|
61 |
-
last_date += pd.Timedelta(days=1)
|
|
|
62 |
# predicted_prices[last_date.strftime('%Y-%m-%d')] = float(denorm_price)
|
63 |
predicted_prices[last_date] = self.truncate_2_decimal(denorm_price)
|
64 |
|
|
|
13 |
self.posttrained_path = './indonesia_stocks/modeling_datas'
|
14 |
self.scaler_path = './indonesia_stocks/min_max'
|
15 |
|
16 |
+
# def truncate_2_decimal(self, val: float):
|
17 |
+
# return float(Decimal(str(val)).quantize(Decimal('0.01'), rounding=ROUND_DOWN))
|
18 |
def truncate_2_decimal(self, val: float):
|
19 |
+
try:
|
20 |
+
return float(Decimal(str(float(val))).quantize(Decimal('0.01'), rounding=ROUND_DOWN))
|
21 |
+
except Exception as e:
|
22 |
+
print("Decimal error:", e)
|
23 |
+
return float(val)
|
24 |
+
|
25 |
|
26 |
def denormalization(self, data, min_value, max_value):
|
27 |
return (data * (max_value - min_value)) + min_value
|
|
|
65 |
value = np.array(predicted).flatten()[0]
|
66 |
denorm_price = (value * (max_close - min_close)) + min_close
|
67 |
|
68 |
+
# last_date += pd.Timedelta(days=1)
|
69 |
+
last_date = pd.to_datetime(last_date) + pd.Timedelta(days=1)
|
70 |
# predicted_prices[last_date.strftime('%Y-%m-%d')] = float(denorm_price)
|
71 |
predicted_prices[last_date] = self.truncate_2_decimal(denorm_price)
|
72 |
|