generated from DataVizU/DataVisTemplateProject
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
184 lines (151 loc) · 3.89 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
177
178
179
180
181
182
183
184
import json
import copy
from typing import List
from fastapi import FastAPI, Body
from fastapi.middleware.cors import CORSMiddleware
from src.data_process.get_data_local import GetData
from src.data_process.dataprocess import (
CommunicationMap,
Overview,
Middlelevel,
NewCommunicationMap,
NewTreeMap,
flow_kew_words,
)
(
ori_data,
time,
influence,
users_info,
forward_info,
forward_users_info,
emotion,
topic,
commentusers,
fc2020,
fcemotion,
) = GetData(
"src/database"
).creat() # 初始化读取数据库信息
(
copy_ori_data,
copy_time,
copy_influence,
copy_users_info,
copy_forward_info,
copy_forward_users_info,
copy_emotion,
copy_topic,
copy_commentusers,
copy_fc2020,
copy_fcemotion,
) = (
copy.deepcopy(ori_data),
copy.deepcopy(time),
copy.deepcopy(influence),
copy.deepcopy(users_info),
copy.deepcopy(forward_info),
copy.deepcopy(forward_users_info),
copy.deepcopy(emotion),
copy.deepcopy(topic),
copy.deepcopy(commentusers),
copy.deepcopy(fc2020),
copy.deepcopy(fcemotion),
)
overview_data = Overview().creat(ori_data, users_info, time, topic)
middle_level_data = Middlelevel().creat(ori_data, time, topic, emotion, influence)
dimension_reduction_data = CommunicationMap().creat(
ori_data,
users_info,
forward_info,
forward_users_info,
emotion,
time,
fc2020,
commentusers,
fcemotion,
topic,
)
tree_map_data = NewTreeMap().creat(
copy_ori_data,
copy_users_info,
copy_forward_info,
copy_forward_users_info,
copy_emotion,
copy_fcemotion,
dimension_reduction_data,
copy_fc2020,
)
ids = []
for i in ori_data:
ids.append(i[0])
ftk = flow_kew_words(ids, ori_data, copy_topic)
new_communication_map_data = NewCommunicationMap().creat(
ori_data,
time,
users_info,
emotion,
fc2020,
commentusers,
forward_users_info,
fcemotion,
)
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/hello/{name}")
async def say_hello(name: str):
return {"message": f"Hello {name}"}
@app.get("/overview/{data_type}")
async def get_overview(data_type: str):
result = {}
if overview_data:
if data_type == "time2topic":
result = json.dumps(overview_data[1], ensure_ascii=False)
elif data_type == "map2time":
result = json.dumps(overview_data[0], ensure_ascii=False)
return result
@app.post("/overview/theme-river")
async def get_river_data(content_id: List[str] = Body(...)):
content_ids = content_id
key_words = {}
if content_ids:
key_words = flow_kew_words(content_ids, ori_data, copy_topic)
return key_words
@app.post("/middle")
async def get_middle_level(content_id: List[str] = Body(...)):
result = []
if dimension_reduction_data:
for data in content_id:
content_id_dict = {'content_id': data}
target_dict = dimension_reduction_data.get(data)
if target_dict:
content_id_dict.update(target_dict)
result.append(content_id_dict)
return result
@app.get("/communication/{content_id}")
async def get_communication_map(content_id: str):
result = {}
if new_communication_map_data:
result = new_communication_map_data.get(content_id)
return result
@app.get("/spiral/{content_id}")
async def get_spiral_map(content_id: str):
result = {}
if new_communication_map_data:
result = new_communication_map_data.get(content_id)
return result
@app.get("/treemap/{content_id}")
async def get_tree_map(content_id: str):
result = []
if tree_map_data:
result = tree_map_data.get(content_id)
return result