-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9_DuFrAppRankData.py
114 lines (90 loc) · 3.99 KB
/
9_DuFrAppRankData.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
from pandas import DataFrame
from twicebursterDataMining.RH_Library import *
from Bunker.Marines import *
#
#
# 수업시간 스마트폰 앱 Duration, Frequency 앱 순위표
studentClassApnoDurationDic, studentClassApnoFrequencyDic = {}, {}
studentClassApnoDurationEntropyArray, studentClassApnoFrequencyEntropyArray = [], []
for studentIndex in range(0, 84):
studentDataPath = getStudentDataPathing(studentIndex)
print(studentDataPath)
#
#
# 데이터 준비하기
classApnoArray, stack = [], []
for index, row in enumerate(sqlite3.connect(studentDataPath + "\\CLASSAPNODATABASE.db").execute("SELECT * FROM CLASSAPNOTABLE")):
if row[2] == "RUNNING":
stack.append(row)
elif row[3] == "screenOff":
startTime = 0
endTime = row[1]
while stack:
startRow = stack.pop()
startTime = startRow[1]
classApnoArray.append([startRow[1], elapsedTimeCalculating(startTime, endTime), startRow[3]])
endTime = startTime
classApnoArray = sorted(classApnoArray, key=lambda low: low[0])
#
#
# 사용시간, 사용횟수 추출하기
deleteAppDic = {"com.lge.signboard":"", "com.lge.launcher2":"", "com.android.systemui":"", "com.lge.launcher3":"", "com.sec.android.app.launcher":"",
"com.buzzpia.aqua.launcher":"", "com.skp.launcher":"", "com.campmobile.launcher":"", "com.phone.launcher.android":"", "com.fihtdc.foxlauncher":"", "android":"",
"com.cashwalk.cashwalk":""}
classApnoTimeDic, classApnoCountDic = {}, {}
for index, row in enumerate(classApnoArray):
if ("lge.signboard" in row[2]) and (row[1] > 60):
classApnoArray[index][2] = classApnoArray[index-1][2]
if row[2] in deleteAppDic.keys():
continue
if row[2] in classApnoTimeDic.keys():
classApnoTimeDic[row[2]] += row[1]
else:
classApnoTimeDic[row[2]] = row[1]
if row[2] in classApnoCountDic.keys():
classApnoCountDic[row[2]] += 1
else:
classApnoCountDic[row[2]] = 1
classApnoDurationArray = sorted(classApnoTimeDic.items(), key=lambda row: row[1], reverse=True)
studentClassApnoDurationDic[getStudentID(studentIndex)] = [(index + 1, row[0], round(row[1], 3)) for index, row in enumerate(classApnoDurationArray) if index < 10]
classApnoFrequencyArray = sorted(classApnoCountDic.items(), key=lambda row: row[1], reverse=True)
studentClassApnoFrequencyDic[getStudentID(studentIndex)] = [(index + 1, row[0], row[1]) for index, row in enumerate(classApnoFrequencyArray) if index < 10]
#
#
# Duration 순위표 그리기
rankDic = {}
for eachStudentClassApnoDurationDicArray in studentClassApnoDurationDic.values():
for appRow in eachStudentClassApnoDurationDicArray:
if appRow[1] not in rankDic.keys():
rankDic[appRow[1]] = 1
else:
rankDic[appRow[1]] += 1
top10Cnt = 1
for name, count in sorted(rankDic.items(), key=lambda row:row[1], reverse=True):
if top10Cnt == 11:
break
print(count, name)
top10Cnt += 1
#
#
# Frequency 순위표 그리기
rankDic = {}
for eachStudentClassApnoFrequencyArray in studentClassApnoFrequencyDic.values():
for appRow in eachStudentClassApnoFrequencyArray:
if appRow[1] not in rankDic.keys():
rankDic[appRow[1]] = 1
else:
rankDic[appRow[1]] += 1
top10Cnt = 1
for name, count in sorted(rankDic.items(), key=lambda row:row[1], reverse=True):
if top10Cnt == 11:
break
print(count, name)
top10Cnt += 1
#
#
# 사용시간, 사용횟수 Top10 앱 데이터 csv 로 출력하기
frame = DataFrame(studentClassApnoDurationDic)
frame.to_csv("C:\\Users\\rihun\Dropbox (KAIST Dr.M)\\htdocs\\Hatchery\\EvolutionChamber\\studentClassApnoTimeDic.csv")
frame = DataFrame(studentClassApnoFrequencyDic)
frame.to_csv("C:\\Users\\rihun\Dropbox (KAIST Dr.M)\\htdocs\\Hatchery\\EvolutionChamber\\studentClassApnoCountDic.csv")