This commit is contained in:
Anton Romanov 2023-04-28 11:53:13 +04:00
parent f168f0747c
commit 8de4e80a99

116
main.py
View File

@ -1,4 +1,112 @@
i = 0
if i == 0:
i = i + 1
print("This line will be printed. " + str(i))
import matplotlib.pyplot as plt
import pandas as pd
from statsmodels.tsa.holtwinters import ExponentialSmoothing
import requests
import json
# ts = pd.read_csv("d:\\files\\Features count.csv")
# ts.plot()
# plt.grid()
# plt.show()
# moving_avg = ts.rolling(4).mean()
# ts.plot()
# plt.plot(moving_avg, color='green', label='Moving average')
# plt.legend()
# plt.grid()
# model = ExponentialSmoothing(ts, trend="additive", seasonal="additive", seasonal_periods=5)
# fit1 = model.fit()
# pred1 = fit1.forecast(5)
# plt.plot(ts, label='Features count')
# plt.plot(pred1, color='red', label='Holt-Winters forecast')
# plt.legend()
# plt.grid()
ts = pd.read_csv("d:\\files\\Testing time.csv")
model = ExponentialSmoothing(ts, trend="additive", seasonal="additive", seasonal_periods=7)
fit1 = model.fit()
pred1 = fit1.forecast(10)
plt.plot(ts, label='Testing time')
plt.plot(pred1, color='red', label='Holt-Winters forecast')
plt.legend()
plt.grid()
plt.show()
# Èñïîëüçîâàòü âíåøíèé ñåðâèñ ïðîãíîçèðîâàíèÿ
time_series = {
"originalTimeSeries": {
"values": [
{
"date": "2023-04-16T06:29:50.668476",
"value": 1
},
{
"date": "2023-04-17T06:29:50.668476",
"value": 2
},
{
"date": "2023-04-18T06:29:50.668476",
"value": 3
},
{
"date": "2023-04-19T06:29:50.668476",
"value": 4
},
{
"date": "2023-04-20T06:29:50.668476",
"value": 5
},
{
"date": "2023-04-21T06:29:50.668476",
"value": 6
},
{
"date": "2023-04-22T06:29:50.668476",
"value": 5
},
{
"date": "2023-04-23T06:29:50.668476",
"value": 4
},
{
"date": "2023-04-24T06:29:50.668476",
"value": 3
},
{
"date": "2023-04-25T06:29:50.668476",
"value": 2
},
{
"date": "2023-04-26T06:29:50.668476",
"value": 1
},
{
"date": "2023-04-27T06:29:50.668476",
"value": 2
}
],
"name": 'test'
},
"countForecast": 5
}
source = []
for v in time_series['originalTimeSeries']['values']:
source.append(v['value'])
url = "http://time-series.athene.tech/api/1.0/getForecast"
headers = {'Content-type': 'application/json'}
r = requests.post(url, data=json.dumps(time_series), headers=headers)
forecast = []
for v in r.json()['timeSeries']['values']:
forecast.append(v['value'])
forecast = list(filter(lambda a: a !=0, forecast))
plt.plot(range(1, 1+len(source)), source)
plt.plot(range(len(source), len(source)+len(forecast)), forecast)
plt.grid()
plt.show()