-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup.py
176 lines (152 loc) · 5.28 KB
/
backup.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
import os
import json
from typing import OrderedDict
# backupPath = "/home/gisuperu/Desktop/procon33_sports/backup"
backupPath = "./backup"
backupStatus = backupPath + "/question.json"
backupAnalyzed = backupPath + "/analyzed.json"
backupSimilarity = backupPath + "/similarity.json"
backupAnswer = backupPath + "/answer.json"
def cleanUP():
with open(backupStatus, "w") as file:
json.dump(dict({}), file, indent=4)
with open(backupAnalyzed, "w") as file:
json.dump(dict({}), file, indent=4)
with open(backupSimilarity, "w") as file:
json.dump(dict({}), file, indent=4)
with open(backupAnswer, "w") as file:
json.dump(dict({}), file, indent=4)
def testInit():
question = dict({
"test1" : {
"status" : {
"problems": 1,
"bonus_factor": [1.0],
"penalty": 1
},
"1" : {
"info" : {
"id": "sample_Q_E01",
"chunks": 2,
"starts_at": 1655302266,
"time_limit": 1000,
"data": 3
},
"path" : [
"./origin_data/sample_Q_202205/sample_Q_E01/problem1.wav",
"./origin_data/sample_Q_202205/sample_Q_E01/problem2.wav"
]
}
}
})
with open(backupStatus, "w+") as file:
json.dump(question, file, indent=4)
# Status
def statusWrite(match, status):
d_update = dict()
with open(backupStatus, "rt") as file:
d_update = json.load(file)
d_update.setdefault(match, {})
# d_update.update({match: {}})
# print(d_update)
d_update[match]["status"] = status
with open(backupStatus, "w+") as file:
json.dump(d_update, file, indent=4)
def statusLoad(match):
d_update = dict()
with open(backupStatus, "rt") as file:
d_update = json.load(file)
return d_update[match]["status"]
# probrem info
def infoWrite(match, stage, probrem_info):
d_update = dict()
with open(backupStatus, "rt") as file:
d_update = json.load(file)
d_update.setdefault(match, {})
d_update[match].setdefault(stage, {})
# d_update.update({match: {stage: {}}})
# print(d_update)
d_update[match][stage]["info"]= probrem_info
with open(backupStatus, "w+") as file:
json.dump(d_update, file, indent=4)
def infoLoad(match, stage):
d_update = dict()
with open(backupStatus, "rt") as file:
d_update = json.load(file)
return d_update[match][stage]["info"]
# toiPahtes
def toiPathesWrite(match, stage, toiPathes):
d_update = dict()
with open(backupStatus, "rt") as file:
d_update = json.load(file)
d_update.setdefault(match, {})
d_update[match].setdefault(stage, {})
# d_update.update({match: {stage: {}}})
# print(d_update)
d_update[match][stage]["path"]= toiPathes
with open(backupStatus, "w+") as file:
json.dump(d_update, file, indent=4)
def toiPathesLoad(match, stage):
d_update = dict()
with open(backupStatus, "rt") as file:
d_update = json.load(file)
return d_update[match][stage]["path"]
# analyzed data
def analyzedWrite(match, stage, analyzed_data):
d_update = dict()
with open(backupAnalyzed, "rt") as file:
d_update = json.load(file)
d_update.setdefault(match, {})
d_update[match].setdefault(stage, {})
# d_update.update({match: {stage: {}}})
# print(d_update)
d_update[match][stage] = analyzed_data
with open(backupAnalyzed, "w+") as file:
json.dump(d_update, file, indent=4)
def analyzedLoad(match, stage):
d_update = dict()
with open(backupAnalyzed, "rt") as file:
d_update = json.load(file)
return d_update[match][stage]
# similarity data
def similarityWrite(match, stage, similarity_data):
d_update = dict()
with open(backupSimilarity, "rt") as file:
d_update = json.load(file)
d_update.setdefault(match, {})
d_update[match].setdefault(stage, {})
d_update[match][stage].setdefault("dict", {})
d_update[match][stage].setdefault("soted", {})
# d_update.update({match: {stage: {}}})
# print(d_update)
similarity_data_alt = sorted(similarity_data.items(), key=lambda x : x[1])
d_update[match][stage]["dict"] = similarity_data
d_update[match][stage]["soted"] = similarity_data_alt
with open(backupSimilarity, "w+") as file:
json.dump(d_update, file, indent=4)
def similarityLoad(match, stage):
d_update = dict()
with open(backupSimilarity, "rt") as file:
d_update = json.load(file)
return d_update[match][stage]["dict"]
# answer cards
def answerWrite(match, stage, answer_cards):
d_update = dict()
with open(backupAnswer, "rt") as file:
d_update = json.load(file)
d_update.setdefault(match, {})
d_update[match].setdefault(stage, {})
# d_update.update({match: {stage: {}}})
# print(d_update)
d_update[match][stage] = answer_cards
with open(backupAnswer, "w+") as file:
json.dump(d_update, file, indent=4)
def answerLoad(match, stage):
d_update = dict()
with open(backupAnswer, "rt") as file:
d_update = json.load(file)
return d_update[match][stage]
if __name__ == '__main__':
os.makedirs("./backup", exist_ok=True)
cleanUP()
testInit()