-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.py
185 lines (156 loc) · 6.49 KB
/
process.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
185
import functools
from lxml import etree
import re
import config
def cmp_optional(c1, c2):
return float(dict(c2).get('credit')) - float(dict(c1).get('credit'))
def find_class_in_list(class_list, name):
for i in class_list:
if dict(i).get('name') == name:
return i
return None
def get_base(tree, xpath):
class_and_grade = list(tree.xpath(xpath))
self_eva, class_eva, campus_eva = 0.0, 0.0, 0.0
for i in range(0, len(class_and_grade)):
if str(class_and_grade[i]).__contains__('合计'):
self_eva = float(class_and_grade[i + 1])
class_eva = float(class_and_grade[i + 2])
campus_eva = float(class_and_grade[i + 3])
if class_eva == 0.0:
class_eva = self_eva
if campus_eva == 0.0:
campus_eva = class_eva
base = self_eva * 0.1 + class_eva * 0.6 + campus_eva * 0.3
return round(base, 2)
def get_bonus_point(tree, xpath):
bonus_point_src = list(tree.xpath(xpath))
bonus_point_items = []
for i in bonus_point_src:
item = str(i).strip()
if item == "" or item.find("通过") != -1:
continue
else:
bonus_point_items.append(item)
bonus_count = 0.0
bonus_point_list = []
for i in range(0, int(len(bonus_point_items) / 7)):
start = 7 * i
if bonus_point_items[start + 0].strip() == '算分':
start += 1
one_bonus = {
'index': int(bonus_point_items[start + 0].strip()),
'name': bonus_point_items[start + 1].strip(),
'type': bonus_point_items[start + 2].strip(),
'rank': bonus_point_items[start + 3].strip(),
'reference': bonus_point_items[start + 4].strip(),
'point': float(bonus_point_items[start + 5].strip()),
'status': bonus_point_items[start + 6].strip()
}
if one_bonus.get('status') != '算分':
continue
bonus_point_list.append(one_bonus)
bonus_count += one_bonus.get('point')
return bonus_count
def calc_moral(htmlData):
tree = etree.HTML(htmlData)
base = get_base(tree, '/html/body/form/table/tr[4]/td/table[2]/tr/td/text()')
bonus = get_bonus_point(tree, '/html/body/form/table/tr[6]/td/table[2]/tr/td/text()')
return base, bonus
def calc_gym(htmlData):
tree = etree.HTML(htmlData)
class_and_grade = list(tree.xpath('/html/body/form/table/tr[4]/td/table[2]/tr/td/text()'))
for i in class_and_grade:
if str(i).strip() == "":
class_and_grade.remove(i)
class_list = []
class_name_list = []
exam_base = 0.0
for i in range(0, int(len(class_and_grade) / 7)):
start = 7 * i
class_name = class_and_grade[start + 0].strip()
one_class = {
'name': class_name,
'season': class_and_grade[start + 1].strip(),
'grade': class_and_grade[start + 2].strip(),
'credit': class_and_grade[start + 3].strip(),
'mode': class_and_grade[start + 4].strip(),
'reread': class_and_grade[start + 5].strip(),
'status': class_and_grade[start + 6].strip()
}
class_name_list.append(one_class.get('name'))
class_list.append(one_class)
exam_base += float(one_class.get('grade'))
base = get_base(tree, '/html/body/form/table/tr[6]/td/table[2]/tr/td/text()')
bonus = get_bonus_point(tree, '/html/body/form/table/tr[8]/td/table[2]/tr/td/text()')
return round(exam_base / 2 * 0.55 + base, 2), bonus
def calc_intellectual(htmlData):
tree = etree.HTML(htmlData)
name_str = tree.xpath('/html/body/form/table/tr[2]/td/table/tr/td/text()')
try:
find_name = re.findall(r"(学生:.*\S)", str(name_str[0]))
finally:
pass
try:
student_name = find_name[0].replace("学生:", "")
except IndexError:
student_name = "Unknown"
class_and_grade = list(tree.xpath('/html/body/form/table/tr[4]/td/table[2]/tr/td/text()'))
class_and_grade.extend(tree.xpath('/html/body/form/table/tr[4]/td/table[5]/tr/td/text()'))
for i in class_and_grade:
if str(i).strip() == "":
class_and_grade.remove(i)
class_list = []
class_name_list = []
for i in range(0, int(len(class_and_grade) / 7)):
start = 7 * i
class_name = class_and_grade[start + 0].strip()
try:
grade = float(re.findall(r"[0-9]+", class_and_grade[start + 1].strip())[0])
except IndexError:
grade = 0.0
if class_name in class_name_list:
old_class = find_class_in_list(class_list, class_name)
if grade > old_class.get('grade'):
class_list.remove(old_class)
else:
continue
one_class = {
'name': class_name,
'grade': grade,
'credit': class_and_grade[start + 2].strip(),
'mode': class_and_grade[start + 3].strip(),
'reread': class_and_grade[start + 4].strip(),
'gpa': class_and_grade[start + 5].strip(),
'status': class_and_grade[start + 6].strip()
}
class_name_list.append(one_class.get('name'))
class_list.append(one_class)
counter = 0.0
optional_list = []
for i in class_list:
if not str(dict(i).get('status')).__contains__("通过"):
continue
if dict(i).get('name') in config.offsetClass:
optional_list.append(i)
continue
if dict(i).get('mode') == '必修课和专业必修课(或限定选修课)':
counter += float(dict(i).get('grade')) / 100 * float(dict(i).get('credit'))
elif dict(i).get('mode') == '专业选修课':
optional_list.append(i)
optional_list.sort(key=functools.cmp_to_key(cmp_optional))
optional_counter = 0.0
optional_num_count = 0
optional_credit_count = 0.0
for i in optional_list:
optional_counter += float(dict(i).get('grade')) / 100 * float(dict(i).get('credit'))
optional_num_count += 1
optional_credit_count += float(dict(i).get('credit'))
if optional_num_count >= config.optionalCountLimit \
or optional_credit_count >= config.optionalCreditLimit:
break
if optional_credit_count > config.optionalCreditLimit:
optional_counter = optional_counter / optional_credit_count * config.optionalCreditLimit
counter += optional_counter
bonus_count = get_bonus_point(tree, '/html/body/form/table/tr[6]/td/table[2]/tr/td/text()')
return student_name, round(counter * 2, 2), bonus_count