Skip to content

Commit 1e234cb

Browse files
committed
B1.1
Add school estimation function.(problems still remains)
1 parent bfbfc82 commit 1e234cb

16 files changed

+681
-72
lines changed
-11.6 KB
Binary file not shown.

Out-of-date Information/StandardGeneral.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

Out-of-date Information/StandardVocational.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

function.py

Lines changed: 96 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def initialise(ifonline = True):
285285
# get 2 school code online or offline, depends on the api's availablity
286286
general_api = "http://www.nnzkzs.com/api/services/app/generalProgress/GetProgress"
287287
vocational_api = "http://www.nnzkzs.com/api/services/app/vocationalProgress/GetProgress"
288-
filePath = os.path.dirname(os.path.abspath (inspect.getsourcefile(lambda:0))) + "\\Out-of-date Information\\schoolCode.json"
288+
filePath = os.path.dirname(os.path.abspath (inspect.getsourcefile(lambda:0))) + "\\resources\\schoolCode.json"
289289
with open(filePath, "r",encoding="utf8") as file:
290290
#get school code list online if api is available
291291
if ifonline:
@@ -304,7 +304,7 @@ def initialise(ifonline = True):
304304
general_list = code_dict["general"]
305305
vocational_list = code_dict["vocational"]
306306

307-
filePath_order = os.path.dirname(os.path.abspath (inspect.getsourcefile(lambda:0))) + "\\gradeOrder.json"
307+
filePath_order = os.path.dirname(os.path.abspath (inspect.getsourcefile(lambda:0))) + "\\resources\\gradeOrder.json"
308308
with open(filePath_order, "r",encoding="utf8") as file:
309309
grade_order = json.load(file)
310310
#get the grade order for sorting
@@ -365,16 +365,19 @@ def __eq__(self, other: "Grade") -> bool:
365365
return self.raw == other.raw
366366

367367
def __gt__(self, other: "Grade") -> bool:
368-
slf_gs = [0 for _ in range(10)]
369-
for g in self.raw:
370-
slf_gs[g] += 1
371-
oth_gs= [0 for _ in range(10)]
372-
for g in other.raw:
373-
oth_gs[g] += 1
374-
if slf_gs != oth_gs:
375-
return slf_gs > oth_gs
376-
377-
return self.raw < other.raw
368+
if self.raw[0] == other.raw[0]:
369+
slf_gs = [0 for _ in range(10)]
370+
for g in self.raw:
371+
slf_gs[g] += 1
372+
oth_gs= [0 for _ in range(10)]
373+
for g in other.raw:
374+
oth_gs[g] += 1
375+
if slf_gs != oth_gs:
376+
return slf_gs > oth_gs
377+
378+
return self.raw < other.raw
379+
else:
380+
return self.raw[0] < other.raw[0]
378381

379382

380383
def single_data_to_grade(data:dict) -> Grade:
@@ -384,7 +387,7 @@ def single_data_to_grade(data:dict) -> Grade:
384387
l = [order.index(subject) for subject in l]
385388
return Grade(l)
386389

387-
def get_grade_list(total_data:dict) -> list[Grade]:
390+
def get_total_grade_list(total_data:dict) -> list[Grade]:
388391
types = ["instruction","directional","alter","guide","vocational"]
389392
data = []
390393
transformed_data = []
@@ -395,3 +398,83 @@ def get_grade_list(total_data:dict) -> list[Grade]:
395398
for d in data:
396399
transformed_data.append(single_data_to_grade(d))
397400
return transformed_data
401+
402+
def get_type_grade_list(data:list) -> list[Grade]:
403+
# get the grade list of a given
404+
transformed_data = []
405+
406+
for d in data:
407+
transformed_data.append(single_data_to_grade(d))
408+
return transformed_data
409+
410+
def get_rank(sorted_data:list[Grade], single_grade:Grade):
411+
# get the rank number
412+
if single_grade in sorted_data:
413+
rank = sorted_data.index(single_grade)+1
414+
415+
else:
416+
for grade_index in range(len(sorted_data)):
417+
if grade_index == len(sorted_data)-1:
418+
rank = len(sorted_data)
419+
break
420+
elif sorted_data[grade_index] > single_grade > sorted_data[grade_index+1]:
421+
rank = grade_index + 2
422+
break
423+
elif single_grade > sorted_data[grade_index]:
424+
rank = 1
425+
break
426+
427+
return rank
428+
429+
def get_combined_score(score:Grade):
430+
order = ["A+","A","B+","B","C+","C","D","E"]
431+
return_str = f"({order[score.raw[0]]})"
432+
dictionary = dict(Counter(score.raw[1:]))
433+
# return without sum score
434+
return_dict = {}
435+
# sort by dict values
436+
for key in sorted(list(dictionary.keys())):
437+
return_dict[key] = dictionary[key]
438+
439+
for d in return_dict:
440+
return_str += f"{return_dict[d]}{order[d]}"
441+
return return_str
442+
443+
def get_enrol_plan(ifGeneral:bool = True) -> dict:
444+
def strict_int(str):
445+
if str!="":
446+
return int(str)
447+
else:
448+
return 0
449+
return_dict = {}
450+
plan_types = ["InstPlan","DirPlan","AlterPlan","GuidePlan"]
451+
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.157',
452+
'X-XSRF-TOKEN': 'c3zy7c3jZL5Jd4v2o33R6-eK7ydTMApwODARCPHHjMchJDmjjvUECZJmmz70NS-lpuRbK2Ya1aHi7ScW-GysCTooH9o1',
453+
'Accept': 'application/json, text/plain, */*',
454+
'Accept-Encoding': 'gzip, deflate',
455+
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
456+
'Host': 'www.nnzkzs.com',
457+
'Referer': 'http://www.nnzkzs.com/'
458+
} # define headers
459+
if ifGeneral:
460+
url = "http://www.nnzkzs.com/api/services/app/generalPublicity/GetPublicity"
461+
res = requests.get(url,headers=headers).json()
462+
plans = json.loads(res["result"])["bmgs_main"]
463+
for plan in plans:
464+
return_dict[int(plan["SchoolCode"])] = {}
465+
for t in plan_types:
466+
return_dict[int(plan["SchoolCode"])][t] = strict_int(plan[t])
467+
else:
468+
url = "http://www.nnzkzs.com/api/services/app/vocationalPublicity/GetPublicity"
469+
res = requests.post(url,headers=headers).json()
470+
plan = json.loads(res["result"])["bmgs_main"]
471+
for plan in plans:
472+
return_dict[int(plan["SchoolCode"])]["countNum"] = strict_int(plan["countNum"])
473+
474+
return return_dict
475+
476+
def type_to_plan_name(type_name:str):
477+
types = ["instruction","directional","alter","guide"]
478+
plan_types = ["InstPlan","DirPlan","AlterPlan","GuidePlan"]
479+
480+
return plan_types[types.index(type_name)]

grade_input.ui

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<x>0</x>
1111
<y>0</y>
1212
<width>400</width>
13-
<height>319</height>
13+
<height>378</height>
1414
</rect>
1515
</property>
1616
<property name="font">
@@ -45,9 +45,9 @@
4545
<property name="geometry">
4646
<rect>
4747
<x>10</x>
48-
<y>282</y>
48+
<y>330</y>
4949
<width>381</width>
50-
<height>31</height>
50+
<height>41</height>
5151
</rect>
5252
</property>
5353
<property name="text">
@@ -60,7 +60,7 @@
6060
<x>10</x>
6161
<y>50</y>
6262
<width>381</width>
63-
<height>231</height>
63+
<height>234</height>
6464
</rect>
6565
</property>
6666
<layout class="QGridLayout" name="gridLayout">
@@ -164,6 +164,19 @@
164164
</item>
165165
</layout>
166166
</widget>
167+
<widget class="QLabel" name="combinedscore_display">
168+
<property name="geometry">
169+
<rect>
170+
<x>10</x>
171+
<y>290</y>
172+
<width>381</width>
173+
<height>31</height>
174+
</rect>
175+
</property>
176+
<property name="text">
177+
<string>Combined Score:</string>
178+
</property>
179+
</widget>
167180
</widget>
168181
<resources/>
169182
<connections/>

0 commit comments

Comments
 (0)