吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4356|回复: 14
收起左侧

[Python 转载] 最近没写平台脚本,开源一个自己写的检测排课冲突

  [复制链接]
xhtdtk 发表于 2021-6-5 20:38
本帖最后由 xhtdtk 于 2021-6-5 22:35 编辑

import xlrd
import re
import time

    set_termstart='2021-03-01'#设置课程该范围时间的开始,若没有特殊要求,可以设置为学期初
    set_termend='2021-07-04'#设置课程该范围时间的结束,若没有特殊要求,可以设置为学期末
    set_course='软件工程'#设置需要可安排时间的课程
    chat_freetime=''#可以设置星期一晚上、星期二晚上等,不设置默认全部

    def basedata():#存储基础数据
    #打开课程安排表,打开工作表
    data_main=xlrd.open_workbook(r'C:\Users\Administrator\Desktop\xxxx大学排课\主要-开课课程计划.xlsx')
    table_main=data_main.sheet_by_name('Sheet2')

    #字典存储各课程上课班级
    dict_CourseListClass={}
    for table_main_row in range(1,table_main.nrows):
            dict_CourseListClass[table_main.cell_value(table_main_row,3)]=[]
    for table_main_row in range(1,table_main.nrows):
            dict_CourseListClass[table_main.cell_value(table_main_row,3)].append(table_main.cell_value(table_main_row,1))
    #print(dict_CourseListClass)

    #字典存储各课程上课老师
    dict_CourseListTeacher={}
    for table_main_row in range(1,table_main.nrows):
            dict_CourseListTeacher[table_main.cell_value(table_main_row,3)]=[]
    for table_main_row in range(1,table_main.nrows):
            dict_CourseListTeacher[table_main.cell_value(table_main_row,3)].append(table_main.cell_value(table_main_row,5))
    #print(dict_CourseListTeacher)
    return dict_CourseListClass,dict_CourseListTeacher

    def return_allformday(table_allform_day):#总表日期
           day=time.strftime('%Y-%m-%d', time.localtime((table_allform_day-25569) * 86400.0))
           allformdayturntime=int(time.mktime(time.strptime(day, "%Y-%m-%d")))
           return day,allformdayturntime

    def return_setday(time_term):
           setdayturntime=int(time.mktime(time.strptime(time_term, "%Y-%m-%d")))
           return setdayturntime

    def time_count():
    #打开课程总表
    data_allform=xlrd.open_workbook(r'C:\Users\Administrator\Desktop\xxxx大学排课\安排-课程总表.xlsx')

    #字典存储教室可上课日期及时间
    dict_timecount={}
    list_classroom=['401','402','403','机房1','机房2','601','602','603','604','605','606','701','702','703','704','705']
    list_weekday=['星期一晚上','星期二晚上','星期三晚上','星期四晚上','星期五晚上','星期六上午','星期六下午1','星期六下午2','星期六晚上','星期日上午','星期日下午1','星期日下午2','星期日晚上']
    for num_classroom in list_classroom:
            dict_timecount[num_classroom]={}
            for num_weekday in list_weekday:
                    dict_timecount[num_classroom][num_weekday]=[]

    #字典存储日期的上课课程
    dict_othertimecount={}

    #for遍历课程总表,存储可上课时间
    for data_allform_sheet in range(1,19):
            table_allform=data_allform.sheet_by_name(str(data_allform_sheet))
            #for遍历教室
            for table_allform_class in range(1,17):
                    try:
                            classroom=re.findall('\\d\\d\\d',table_allform.cell_value((table_allform_class-1)*2+6,0))[0]
                    except:
                            classroom=re.findall('机房\\d',table_allform.cell_value((table_allform_class-1)*2+6,0))[0]
                    #遍历星期时间段
                    for table_allform_weekday in range(2,15):
                            if table_allform.cell_value((table_allform_class-1)*2+5,table_allform_weekday)=='':
                                    dict_timecount[classroom][table_allform.cell_value(2,table_allform_weekday)+table_allform.cell_value(4,table_allform_weekday)].append(return_allformday(table_allform.cell_value(3,table_allform_weekday))[0])
                            else:
                                    try:
                                            dict_othertimecount[return_allformday(table_allform.cell_value(3,table_allform_weekday))[0]+table_allform.cell_value(4,table_allform_weekday)].append(table_allform.cell_value((table_allform_class-1)*2+5,table_allform_weekday))
                                    except:
                                            dict_othertimecount[return_allformday(table_allform.cell_value(3,table_allform_weekday))[0]+table_allform.cell_value(4,table_allform_weekday)]=[]
                                            dict_othertimecount[return_allformday(table_allform.cell_value(3,table_allform_weekday))[0]+table_allform.cell_value(4,table_allform_weekday)].append(table_allform.cell_value((table_allform_class-1)*2+5,table_allform_weekday))

    return dict_timecount,dict_othertimecount

    def time_othercount(dict_CourseListClass,CourseListTeacher,timecount):
    #打开课程总表
    data_allform=xlrd.open_workbook(r'C:\Users\Administrator\Desktop\xxxx大学排课\辅助-课程总表.xlsx')
    #for遍历课程总表
    for data_allform_sheet in range(1,19):
            table_allform=data_allform.sheet_by_name(str(data_allform_sheet))
            #for遍历教室
            for table_allform_class in range(1,17):
                    try:
                            classroom=re.findall('\\d\\d\\d',table_allform.cell_value((table_allform_class-1)*2+6,0))[0]
                    except:
                            classroom=re.findall('机房\\d',table_allform.cell_value((table_allform_class-1)*2+6,0))[0]
                    #遍历星期时间段
                    for table_allform_weekday in range(2,15):
                            #如果在规定时间内
                            if return_setday(set_termstart)<=return_allformday(table_allform.cell_value(3,table_allform_weekday))[1] and return_setday(set_termend)>=return_allformday(table_allform.cell_value(3,table_allform_weekday))[1]:
                                    #如果当日有课且不是节假日
                                    if table_allform.cell_value((table_allform_class-1)*2+5,table_allform_weekday)!='' and (('放假' in table_allform.cell_value((table_allform_class-1)*2+5,table_allform_weekday))==False):
                                            day_eachday=return_allformday(table_allform.cell_value(3,table_allform_weekday))[0]
                                            day_eachcourse=table_allform.cell_value((table_allform_class-1)*2+5,table_allform_weekday)
                                            day_eachweekdayANDeachdaytime=table_allform.cell_value(2,table_allform_weekday)+table_allform.cell_value(4,table_allform_weekday)
                                            try:
                                                    day_eachclass=re.findall('\\d\\d\\d',table_allform.cell_value((table_allform_class-1)*2+6,0))[0]
                                            except:
                                                    day_eachclass=re.findall('机房\\d',table_allform.cell_value((table_allform_class-1)*2+6,0))[0]
                                            #如果两门课的班级和老师不冲突
                                            if list(set(dict_CourseListClass[day_eachcourse]) & set(dict_CourseListClass[set_course]))!=[] or list(set(CourseListTeacher[day_eachcourse]) & set(CourseListTeacher[set_course]))!=[]:
                                                    # print(day_eachcourse)
                                                    # print(day_eachday)
                                                    # print(day_eachweekdayANDeachdaytime)
                                                    # print(day_eachclass)
                                                    list_class=['401','402','403','机房1','机房2','601','602','603','604','605','606','701','702','703','704','705']
                                                    for each_class in list_class:
                                                            try:
                                                                    timecount[0][each_class][day_eachweekdayANDeachdaytime].remove(day_eachday)
                                                            except:
                                                                    continue
    return timecount[0]
    freetime=time_othercount(basedata()[0],basedata()[1],time_count())

    #打印可安排时间
    for chat_eachclassfreetime in ['401','402','403','机房1','机房2','601','602','603','604','605','606','701','702','703','704','705']:
    if chat_freetime!='':
            print(chat_eachclassfreetime+'   '+chat_freetime)
            print(freetime[chat_eachclassfreetime][chat_freetime])
            print('')
    else:
            for chat_eachdayfreetime in ['星期一晚上','星期二晚上','星期三晚上','星期四晚上','星期五晚上','星期六上午','星期六下午1','星期六下午2','星期六晚上','星期日上午','星期日下午1','星期日下午2','星期日晚上']:
                    print(chat_eachclassfreetime+'   '+chat_eachdayfreetime)
                    print(freetime[chat_eachclassfreetime][chat_eachdayfreetime])
                    print('')

    #打印已安排课程
    #print(time_count()[1])


效果
2.png
1.png
因为“JAVA语言”和“软件工程”是同一个班级,所以查到星期一晚上可安排时间就没有2021-03-01,其他就是可安排时间,然后手动将课程填入总表(工作簿以日期设了18个分表)并保存,继续下一个课程的检测。


检测冲突是为了解决:
1、同一班级在同一时间只能上一门课程
2、同一老师在同一时间只能上一门课程
3、同一教室在同一时间只能上一门课程

xxxx大学排课.rar

65.81 KB, 下载次数: 106, 下载积分: 吾爱币 -1 CB

代码、开课计划、课程总表

免费评分

参与人数 4吾爱币 +11 热心值 +4 收起 理由
赠柟 + 1 + 1 我很赞同!
街角转身 + 2 + 1 热心回复!
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
liuqm + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

zhlei1009 发表于 2021-6-5 20:45
好东西,谢谢老板
yf668888 发表于 2021-6-5 21:04
sam喵喵 发表于 2021-6-5 21:12
liuqm 发表于 2021-6-5 21:48
向大佬学习
QingYi. 发表于 2021-6-5 22:14
是不是一行代码写的太长了
海浪8793 发表于 2021-6-6 06:07
感谢分享
zhaotj2021 发表于 2021-6-6 22:35
感谢博主分享,下载了,学习下。
tdjmcqw 发表于 2021-6-7 10:45
点赞,下载学习
yzxqhdx 发表于 2021-6-10 20:56
大佬 国开能再分享下吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-3-29 15:32

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表