-
Notifications
You must be signed in to change notification settings - Fork 3
/
form.py
168 lines (149 loc) · 4.86 KB
/
form.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
# WHAT A HUGE PIECE OF SH*T!
import random
from dataclasses import dataclass
@dataclass
class Option:
id: str
content: str
pts: float
@dataclass
class Question:
isChoice: bool
type: str
id: str
options: list[Option]
def fill_form(form_info, method='good'):
# 这是活人能想出来的名字?
basic_info = form_info['pjxtPjjgPjjgckb'][1]
question_list = get_question_list(form_info)
choice_list = [q for q in question_list if q.isChoice]
other_list = [q for q in question_list if not q.isChoice]
choice_answer = gen_answer(choice_list, method)
total_score = int(sum(q.pts for q in choice_answer))
answer_list = []
for i in range(len(choice_list)):
answer_list.append({
'sjly': '1', # not sure
'stlx': choice_list[i].type,
'wjid': basic_info['wjid'],
'wjssrwid': basic_info['wjssrwid'],
'wjstctid': "",
'wjstid': choice_list[i].id,
'xxdalist': [
choice_answer[i].id
]
})
for i, q in enumerate(other_list):
answer_list.append({
'sjly': '1', # not sure
'stlx': q.type,
'wjid': basic_info['wjid'],
'wjssrwid': basic_info['wjssrwid'],
'wjstctid': q.options[0].id,
'wjstid': q.id,
'xxdalist': [
"" # empty string
]
})
ret = {
'pjidlist': [],
'pjjglist': [
{
'bprdm': basic_info['bprdm'],
'bprmc': basic_info['bprmc'],
'kcdm': basic_info['kcdm'],
'kcmc': basic_info['kcmc'],
'pjdf': total_score,
'pjfs': basic_info['pjfs'],
'pjid': basic_info['pjid'],
'pjlx': basic_info['pjlx'],
'pjmap': form_info['pjmap'],
'pjrdm': basic_info['pjrdm'],
'pjrjsdm': basic_info['pjrjsdm'],
'pjrxm': basic_info['pjrxm'],
'pjsx': 1, # Not sure
'rwh': basic_info['rwh'],
'stzjid': basic_info['stzjid'],
'wjid': basic_info['wjid'],
'wjssrwid': basic_info['wjssrwid'],
'wtjjy': '',
'xhgs': basic_info['xhgs'],
'xnxq': basic_info['xnxq'],
'sfxxpj': '1', # Not sure, but setting to '2' causes problems
'sqzt': basic_info['sqzt'],
'yxfz': basic_info['yxfz'],
'sdrs': basic_info['sdrs'],
"zsxz": basic_info['pjrjsdm'],
'sfnm': '1', # Anonymous
'pjxxlist': answer_list
}
],
'pjzt': '1' # 2 for save, 1 for submit
}
return ret
def get_question_list(form_info):
ret = []
for entry in form_info['pjxtWjWjbReturnEntity']['wjzblist'][0]['tklist']:
q = Question(
isChoice=entry['tmlx'] == '1',
type=entry['tmlx'],
id=entry['tmid'],
options=[]
)
for option in entry['tmxxlist']:
q.options.append(Option(
id=option['tmxxid'],
content=option['xxmc'],
pts=float(option['xxfz'])
))
q.options.sort(key=lambda x: x.pts, reverse=True)
ret.append(q)
return ret
def gen_answer(choice_list, method):
ret = []
if method == 'good':
ret = gen_good_answer(choice_list)
# the below two methods are not tested
elif method == 'bad':
ret = gen_bad_answer(choice_list)
elif method == 'random':
ret = gen_random_answer(choice_list)
else:
raise ValueError(f"Unknown method {method}")
return ret
def gen_good_answer(choice_list):
ret = []
if len(choice_list) == 1:
ret.append(choice_list[0].options[0])
else:
ret.append(choice_list[0].options[1])
for q in choice_list[1:]:
ret.append(q.options[0])
return ret
def gen_bad_answer(choice_list: list[Question]):
return dp(choice_list, 60)
def gen_random_answer(choice_list):
target = random.randint(60, 100)
return dp(choice_list, target)
def dp(choice_list, threshold):
max_score = sum(q.options[0].pts for q in choice_list)
if max_score >= threshold:
threshold = max_score
dp_list = [0] * (max_score + 1)
dp_list[0] = 1
for q in choice_list:
for i in range(max_score, -1, -1):
for option in q.options:
if i + option.pts <= max_score:
dp_list[i + option.pts] = dp_list[i]
target = threshold
while dp_list[target] == 0:
target += 1
ret = []
for q in choice_list:
for option in q.options:
if target - option.pts >= 0:
target -= option.pts
ret.append(option)
break
return ret