-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
176 lines (130 loc) · 4.74 KB
/
main.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
from flask import Flask, request
from app.domain.chart_machine import ChartMachine
import app.domain.cron_ai as soda
# import py_eureka_client.eureka_client as eureka_client
from apscheduler.schedulers.background import BackgroundScheduler
from app.infra.db.mongodb.mongodb_handler import MongoDBHandler
from app.infra.machine.groq_machine import GroqMachine
import os
# from app.infra.machine.chatGPT_machine import ChatMachine
import json
from app.domain.init_coin_data import init_code
rest_port= port = int(os.getenv("PORT", 5000))
# eureka_client.init(eureka_server="http://flowbit-discovery:8761/eureka/",
# app_name="bitcoin-service",
# instance_port=rest_port)
app = Flask(__name__)
chart_machine = ChartMachine()
mongodbMachine = MongoDBHandler(db_name="BTC", collection_name="analysis_data")
@app.route("/")
def home():
html = """
<html>
<head><meta charset="utf-8"></head>
<body>
<h1>MAIN PAGE</h1>
</body>
</html>
"""
return html
@app.route("/get_predict_value")
def get_predict_value_old():
ret = {}
# mongodbMachine = MongoDBHandler(db_name="AI", collection_name="actual_data")
data = mongodbMachine.find_last_item(db_name="AI", collection_name="predicted_data")
del data["_id"]
data["predicted_krw"] = data["predicted_price"]
del data["predicted_price"]
ret["predicted_data"] = data
data = mongodbMachine.find_last_item(db_name="AI", collection_name="actual_data")
del data["_id"]
ret["actual_data"] = data
return ret
@app.route("/get_basic_chart")
def get_basic_chart():
# chart_machine = ChartMachine()
return chart_machine.get_basic_chart()
@app.route("/get_all_chart")
def get_all_chart():
# chart_machine = ChartMachine()
return chart_machine.get_all_chart()
@app.route("/get_chart_analysis")
def get_chart_analysis():
arg = request.args.get('currency')
data = mongodbMachine.find_last_item(db_name=arg, collection_name="analysis_data")
del data["_id"]
return data
@app.route("/chart")
def get_chart():
arg = request.args.get('currency')
print(arg)
# chart_machine = ChartMachine()
result = {}
if arg == "BTC":
result = chart_machine.get_all_multiple_chart(db_name=arg)
else:
result = chart_machine.get_all_single_chart(db_name=arg)
return result
@app.route("/predicted-value")
def get_predict_value():
arg = request.args.get('currency')
# mongodbMachine = MongoDBHandler(db_name="BTC", collection_name="analysis_data")
ret = {}
data = mongodbMachine.find_last_item(db_name=arg, collection_name="predicted_data")
print(data)
if "_id" in data:
del data["_id"]
data["predicted_krw"] = data["predicted_price"]
del data["predicted_price"]
ret["predicted_data"] = data
data = mongodbMachine.find_last_item(db_name=arg, collection_name="actual_data")
if "_id" in data:
del data["_id"]
ret["actual_data"] = data
return ret
@app.route("/predicted-value-list")
def get_all_predict_value():
with open('app/conf/config.json') as f:
config = json.load(f)
currency_list = config["currencyList"]
predicted_value_list = {}
for currency in currency_list:
arg = currency
# mongodbMachine = MongoDBHandler(db_name="BTC", collection_name="analysis_data")
ret = {}
data = mongodbMachine.find_last_item(db_name=arg, collection_name="predicted_data")
print(data)
if "_id" in data:
del data["_id"]
data["predicted_krw"] = data["predicted_price"]
del data["predicted_price"]
ret["predicted_data"] = data
data = mongodbMachine.find_last_item(db_name=arg, collection_name="actual_data")
if "_id" in data:
del data["_id"]
ret["actual_data"] = data
predicted_value_list[arg] = ret
return predicted_value_list
@app.route("/test_cron")
def test_cron():
soda.save_one_day_data()
return "this is my name"
@app.route("/test_groq")
def test_groq():
groq = GroqMachine()
actual_data_str, predicted_data_str = chart_machine.get_analysis_chart(database_name="BTC")
res = groq.get_analysis_result(actual_data_str, predicted_data_str)
return res
if __name__ == "__main__":
init_code()
# chat_machine = ChatMachine()
port = int(os.getenv("PORT", 5000))
sched = BackgroundScheduler(daemon=True)
sched.remove_all_jobs()
sched.add_job(soda.save_one_day_data, 'cron', hour=0, minute=2)
sched.start()
# jobs = sched.get_jobs()
# print("start print job")
# for job in jobs:
# print(f"Job ID: {job.id}, Next Run Time: {job.next_run_time}")
app.run(host='0.0.0.0', port=port, debug=False, use_reloader=False)