Repository navigation
Expand file tree
/
Copy pathtmp.py
More file actions
198 lines (143 loc) · 5.36 KB
/
Copy pathtmp.py
File metadata and controls
198 lines (143 loc) · 5.36 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import pymysql
from datetime import datetime, timedelta, date
creedit = pymysql.connect(host='203.245.30.13', user='ehdgus93', password='', db='db_creedit', charset='utf8')
manager = creedit.cursor()
CATEGORY = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
]
END = 'end'
START = 'start'
manager.execute("truncate table statistics")
creedit.commit()
data = {}
for category in CATEGORY:
data[category] = {}
target = datetime.now()
end = date(target.year, target.month, target.day)
target = datetime.now() - timedelta(days=11)
start = date(target.year, target.month, target.day)
sql = "select categorymap.category_id, stat.cid, stat.time_stamp, stat.viewCount, stat.subscriberCount from categorymap join stat where categorymap.cid = stat.cid and stat.time_stamp between \'{0}\' and \'{1}\' order by stat.time_stamp".format(str(start), str(end))
manager.execute(sql)
rows = manager.fetchall()
for cno, cid, date, views, subs in rows:
data[cno][cid] = {}
data[cno][cid][END] = str(end)
channel_id = ""
category = 0
for cno, cid, date, views, subs in rows:
date = str(date)
if category != cno:
category = cno
data[cno][cid][START] = str(date)
if subs != 0:
data[cno][cid][date] = subs
else:
data[cno][cid][date] = views
delta = end - start
channels = {}
for cno in CATEGORY:
dx = delta.days
target_channel = ""
val = 0
for key in data[cno].keys():
if START not in data[cno][key].keys():
continue
u = data[cno][key][START]
v = data[cno][key][END]
dy = data[cno][key][v] - data[cno][key][u]
if target_channel is "":
target_channel = key
val = dy / dx
continue
if val <= (dy / dx):
if val == (dy / dx):
if data[cno][target_channel][v] < data[cno][key][v]:
target_channel = key
val = dy / dx
else:
target_channel = key
val = dy / dx
channels[cno] = target_channel
for cno in CATEGORY:
if channels[cno] == "":
continue
sql = "select cname from channels where cid = \'{0}\'".format(channels[cno])
manager.execute(sql)
cname = manager.fetchall()[0][0]
print(cno, cname)
for row in data[cno][channels[cno]]:
if row is END:
continue
if row is START:
continue
print(row, data[cno][channels[cno]][row])
sql = "insert into statistics(category, time_stamp, subscriberCount, viewCount) values(%s, %s, %s, %s)"
manager.execute(sql, (cno, row, data[cno][channels[cno]][row], 0))
creedit.commit()
creedit.close()
# import pymysql
# from datetime import datetime, timedelta, date
# creedit = pymysql.connect(host='203.245.30.13', user='ehdgus93', password='ehdgus93!', db='db_creedit', charset='utf8')
# manager = creedit.cursor()
# CATEGORY = [
# 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
# ]
# END = 'end'
# START = 'start'
# manager.execute("truncate table statistics")
# creedit.commit()
# data = {}
# for category in CATEGORY:
# data[category] = {}
# target = datetime.now()
# end = date(target.year, target.month, target.day)
# target = datetime.now() - timedelta(days=11)
# start = date(target.year, target.month, target.day)
# sql = "select categorymap.category_id, stat.cid, stat.time_stamp, stat.viewCount, stat.subscriberCount from categorymap join stat where categorymap.cid = stat.cid and stat.time_stamp between \'{0}\' and \'{1}\' order by stat.time_stamp".format(str(start), str(end))
# manager.execute(sql)
# rows = manager.fetchall()
# for cno, cid, date, views, subs in rows:
# data[cno][cid] = {}
# data[cno][cid][END] = str(end)
# channel_id = ""
# category = 0
# for cno, cid, date, views, subs in rows:
# date = str(date)
# if category != cno:
# category = cno
# data[cno][cid][START] = str(date)
# if subs != 0:
# data[cno][cid][date] = subs
# else:
# data[cno][cid][date] = views
# for cno in CATEGORY:
# if channels[cno] == "":
# continue
# sql = "select cname from channels where cid = \'{0}\'".format(channels[cno])
# manager.execute(sql)
# cname = manager.fetchall()[0][0]
# print(cno, cname)
# for row in data[cno][channels[cno]]:
# if row is END:
# continue
# if row is START:
# continue
# print(row, data[cno][channels[cno]][row])
# sql = "insert into statistics(category, time_stamp, subscriberCount, viewCount) values(%s, %s, %s, %s)"
# manager.execute(sql, (cno, row, data[cno][channels[cno]][row], 0))
# creedit.commit()
# creedit.close()
# import pymysql
# creedit = pymysql.connect(host='203.245.30.13', user='ehdgus93', password='ehdgus93!', db='db_creedit', charset='utf8')
# manager = creedit.cursor()
# conn = pymysql.connect(host='localhost', user='root', password='gml7594!tn', db='creedit', charset='utf8')
# cursor = conn.cursor()
# sql = "select * from stat where time_stamp > \'2020-05-19\'"
# manager.execute(sql)
# rows = manager.fetchall()
# sql = 'insert into stat(cid, time_stamp, viewCount, subscriberCount, commentCount, hiddenSubscriberCount, videoCount) values(%s, %s, %s, %s, %s, %s, %s)'
# for row in rows:
# cursor.execute(sql, (row[1], row[2], row[3], row[4], row[5], row[6], row[7]))
# creedit.close()
# conn.commit()
# conn.close()