Statistics on class team grouping of (assistant may be required)

Ideas: very simple. First of all student's name and student number read it from the list of students to excel file dict dictionary, and the dictionary dict state students create, save for grouping students are in no state. Then read line by line grouping teams excel file, the students state dict dictionary set.

import re
import xlrd

##################### 班级名单读取 #####################

all_stud=xlrd.open_workbook(r'计算机视觉选课名单.xls')
all_stud_sheet1 = all_stud.sheets()[0]

num_to_name = dict() # 学号转换为姓名
stud_state = dict() # 学生分组状况

for i in range(all_stud_sheet1.nrows):
    tmp = str(all_stud_sheet1.cell(i,1).value)
    if (re.match(r'\d{12}', tmp) != None):
        name = str(all_stud_sheet1.cell(i,2).value)
        num = tmp
        num_to_name[num] = name
        stud_state[num] = 0

assert (len(num_to_name) == len(stud_state))

##################### 小组分组情况统计 #####################

group_excel=xlrd.open_workbook(r'小组分组 - 详细版.xlsx')
group_sheet1 = group_excel.sheets()[0]

not_in_class = []
repeat_join = []
joined_num = 0
group_num = 0

for i in range(group_sheet1.nrows): # 遍历每个小组成员
    if (i == 0):
        continue;
    tmp1 = str(group_sheet1.cell(i,1).value)
    tmp2 = str(group_sheet1.cell(i,2).value)
    
    if (tmp1 == "" and tmp2 == ""):
        continue
    
    nam = tmp1
    num = tmp2

    group_num += 1
    
    if (num == "" or nam == "" or num not in stud_state.keys()): # 不在班级里的人
        not_in_class.append([num, nam])
    elif (stud_state[num] != 0): # 重复加入小组的人
        repeat_join.append([num, nam])
    else: # 未加入的人
        stud_state[num] = 1
        joined_num += 1

not_joined_num = 0
not_joined = []
for num in stud_state.keys():
    if (stud_state[num] == 0):
        not_joined_num += 1
        not_joined.append([num, num_to_name[num]])

assert(len(stud_state) == joined_num + not_joined_num)


print ("##################### 班级名单中的情况 #####################")
print ()
print ("班级总人数:" + str(len(stud_state)))
print ("班级中,已分组人数:" + str(joined_num))
print ("班级中,未分组人数:" + str(not_joined_num))
print ()
print ("未参与分组的人如下:")
for mem in not_joined:
    print (mem)
print ()
print ("##################### 小组分组的情况 #####################")
print ()
print ("参与分组总人数:" + str(group_num))
print ("在班级中的人数:" + str(joined_num))
print ("不在班级中的人数:" + str(len(not_in_class)))
print ()
print ("不在班级中的人如下:")
for  mem in not_in_class:
    print (mem)
print ()
print ("重复分组的人数:" + str(len(repeat_join)))
print ()
print ("重复分组的人如下:")
for  mem in repeat_join:
    print (mem)
    

Published 92 original articles · won praise 2 · Views 3412

Guess you like

Origin blog.csdn.net/zxc120389574/article/details/105132637