文章目录

  • 前言
  • 解决方案
  • 代码实现
  • version_2

前言

实现对多个人在一周的自动排班表,要求每行每列不能有重复的。排好班之后,以excel的形式输出。

解决方案

  1. 首先输出每行每列不重名的一个矩阵
  2. 统计每个人在一周排班中出现的次数
  3. 将矩阵数据写入excel中并保存

代码实现

from random import shuffle
from random import sample
import numpy as np
import xlwtname_list = ['田','兰','刘','杨','余','唐','于','莫','吴','乔','敏','童','杜','王','豆','黄','苹','磊','曼','陈','皱','谢','果','汪','麒']
name_list_size = len(name_list)print("The are total {} people".format(name_list_size))def get_matrix():while 1:row_1 = sample(name_list, 5)row_2 = sample(name_list, 5)row_3 = sample(name_list, 5)row_4 = sample(name_list, 5)row_5 = sample(name_list, 5)row_6 = sample(name_list, 5)row_7 = sample(name_list, 5)row_8 = sample(name_list, 5)row_9 = sample(name_list, 5)row_10 = sample(name_list, 5)#get a matrix for 10x5 arraymatrix = np.array([row_1,row_2,row_3,row_4,row_5,row_6,row_7,row_8,row_9,row_10])col_1 = matrix[:,0]col_2 = matrix[:,1]col_3 = matrix[:,2]col_4 = matrix[:,3]col_5 = matrix[:,4]set_col_1 = set(col_1)set_col_2 = set(col_2)set_col_3 = set(col_3)set_col_4 = set(col_4)set_col_5 = set(col_5)#check whether all people has been in the listunique_list = []for i in range(10):for j in range(5):if matrix[i][j] not in unique_list:unique_list.append(matrix[i][j])#calculate repeated times for every membermatrix_list_all_num = []for h in range(10):for k in range(5):matrix_list_all_num.append(matrix[h][k])dic = {}for item in unique_list:dic.update({item: matrix_list_all_num.count(item)})if len(unique_list) == len(name_list) and len(set_col_1) == len(col_1) and len(set_col_2) == len(col_2) and len(set_col_3) == len(col_3) and len(set_col_4) == len(col_4) and len(set_col_5) == len(col_5):#print("Totally calculate", i, "times\n")print("All people are scheduled\n")print(matrix)print("The repeat time for every member\n")print(dic)breakreturn matrixdef data_write(file_path, datas):book = xlwt.Workbook()sheet = book.add_sheet('sheet1', cell_overwrite_ok=True)sheet.write(0, 0, '星期一')sheet.write(0, 1, '星期二')sheet.write(0, 2, '星期三')sheet.write(0, 3, '星期四')sheet.write(0, 4, '星期五')#sheet.write(0, 1, '星期六')i = 1for data in datas:for j in range(len(data)):sheet.write(i, j, data[j])i = i + 1book.save(file_path)matrix_copy = get_matrix()
book_name_xls = 'schedule_shift.xls'data_write(book_name_xls, matrix_copy)

version_2

增加了每个人在一个周内排班的总次数到excel中

from random import shuffle
from random import sample
import numpy as np
import xlwtname_list = ['田','兰','刘','杨','余','唐','于','莫','吴','乔','敏','童','杜','王','豆','黄','苹','磊','曼','陈','皱','谢','果','汪','麒']
name_list_size = len(name_list)print("The are total {} people".format(name_list_size))#to convert the name_list to set(name_list)
#unique_list = []
#to store the member to dic
#dic = {}def get_matrix():while 1:row_1 = sample(name_list, 5)row_2 = sample(name_list, 5)row_3 = sample(name_list, 5)row_4 = sample(name_list, 5)row_5 = sample(name_list, 5)row_6 = sample(name_list, 5)row_7 = sample(name_list, 5)row_8 = sample(name_list, 5)row_9 = sample(name_list, 5)row_10 = sample(name_list, 5)#get a matrix for 10x5 arraymatrix = np.array([row_1,row_2,row_3,row_4,row_5,row_6,row_7,row_8,row_9,row_10])col_1 = matrix[:,0]col_2 = matrix[:,1]col_3 = matrix[:,2]col_4 = matrix[:,3]col_5 = matrix[:,4]set_col_1 = set(col_1)set_col_2 = set(col_2)set_col_3 = set(col_3)set_col_4 = set(col_4)set_col_5 = set(col_5)#check whether all people has been in the listunique_list = []for i in range(10):for j in range(5):if matrix[i][j] not in unique_list:unique_list.append(matrix[i][j])#calculate repeated times for every membermatrix_list_all_num = []for h in range(10):for k in range(5):matrix_list_all_num.append(matrix[h][k])dic = {}for item in unique_list:dic.update({item: matrix_list_all_num.count(item)})#generate the excel to save tablebook_name_xls = 'schedule_shift.xls'static_key_list = list(dic)static_value_list = list(dic.values())if len(unique_list) == len(name_list) and len(set_col_1) == len(col_1) and len(set_col_2) == len(col_2) and len(set_col_3) == len(col_3) and len(set_col_4) == len(col_4) and len(set_col_5) == len(col_5):print("All people are scheduled\n")print(matrix)#generate the excelbook = xlwt.Workbook()sheet = book.add_sheet('sheet', cell_overwrite_ok=True)sheet.write(0, 0, '星期一')sheet.write(0, 1, '星期二')sheet.write(0, 2, '星期三')sheet.write(0, 3, '星期四')sheet.write(0, 4, '星期五')#sheet.write(0, 1, '星期六')i = 1for data in matrix:for j in range(len(data)):sheet.write(i, j, data[j])i = i + 1book.save(book_name_xls)j = 13for item in static_key_list:sheet.write(j, 0, item)j = j + 1k = 13for item1 in static_value_list:sheet.write(k, 1, item1)k = k + 1book.save(book_name_xls)print('\n')print("The repeat time for every member\n")print(dic)breakreturn matrixget_matrix()

python自动排班表相关推荐

  1. excel自动排班表怎么做?哪里有免费的自动排班表?2022最新整理30份Excel自动排班表,建议收藏

    你还在手动排班吗?别再这样做了,我有更高效的方法! 在工作中,我们经常需要进行排班,不管是假期值班,还是直播排班,都需要做一个排班表.以前的时候排班都是手动调的,你周一我周二,但这种做法效率比较低,而 ...

  2. excel自动排班表_巧用常见工具:怎样将图片格式数据转换成EXCEL表格

    有时我们需要处理的数据以图片或pdf的形式存储,无法直接粘贴到EXCEL中.今天小白通介绍一种将图片中数据转换成表格的方法,为大家解决这个烦恼. 1. 假设我们需要处理的数据存储在这张图片中. 2. ...

  3. mysql 自动排班表_基于jsp+mysql+Spring的Spring自动排班管理系统

    运行环境: 最好是java jdk 1.8,我们在这个平台上运行的.其他版本理论上也可以. IDE环境: Eclipse,Myeclipse,IDEA都可以 tomcat环境: 最好是Tomcat 7 ...

  4. excel自动排班表_制造工厂如何特殊排班?如何为无固定休息日排班?

    本期为各位HR朋友分享案例:eHR人事管理系统如何给无固定休息日排班?人力资源hr系统如何生成相关报表?具体有哪些功能介绍? 1.考勤免排班功能 考勤管理核心是排班,手工排班需要耗费大量的时间,人力资 ...

  5. python自动客服排班_python自动排班表

    from random import shuffle from random import sample import numpy as np import xlwt name_list = ['田' ...

  6. excel自动排班表_最火8套建筑工程测量计算表,傻瓜式操作,自动计算出结果,速领...

    最火8套建筑工程测量计算表,傻瓜式操作,自动计算出结果,速领 工程测量涉及大量数据的计算,其工作相当繁琐.却又相当重要,不能出现一点差错,熬夜加班是常有的事. 今天给大家整理的这份建筑工程测量自动计算 ...

  7. excel自动排班表_Excel数据分析-如何制作自动更新的数据透视表

    数据透视表是我们工作中一个非常强大的数据汇总分析功能,大家一定会遇到这样的问题,就是数据源如果每天或者经常性需要更新的话,那么我们的数据透视表就要在每次更新后重新选择数据源,如何能让数据源自动更新呢? ...

  8. excel自动排班表_中建最新版施工计划进度横道图,一键自动生成,横道图从此不用愁...

    中建最新版施工计划进度横道图,一键自动生成,横道图从此不用愁 横道图,是一种非常实用的图表类型.施工进度计划的制定在工程项目里是很重要的,这可以大大提高施工单位的管理水平,是项目施工必备.作为一个在工 ...

  9. excel自动排班表_造价拒绝熬夜!全套Excel工程计算表格+必备小工具,无偿领

    造价拒绝熬夜!全套Excel工程计算表格+必备小工具,无偿领 从事造价工作,总是要面临很多繁琐的工程算量数据.对于造价老手来说,有了一定的工作经验,面对复杂多样的数据,还是相当淡定.但对于新手来说,却 ...

最新文章

  1. GoldenGate的Logdump工具使用简介
  2. 计算机科学与技术讲座psd,计算机科学的技术基本.ppt
  3. php 一个简单正则表达式,PHP中正则表达式回顾(3)--编写一个简单的正则表达式工具类...
  4. swagger报错No handler found for GET /swagger-ui.html
  5. 从零点五开始用Unity做半个2D战棋小游戏(四)
  6. js与c语言互相调用,Objc与JS间相互调用
  7. Typecho 动漫单栏主题First
  8. Lucene于搜索引擎技术(Analysis包详解)
  9. 每日一题 2020.05.11
  10. You are here: Prof Andrew Binley's Homepage R3t
  11. 数据结构第三章栈和队列(一)
  12. CPU又烧了,说起来汝可能不信
  13. Linux : 终端命令整理
  14. JDK1.8HashMap底层实现原理
  15. Web.config配置文件详解(转载)
  16. %1 不是有效的 Win32 应用程序
  17. c语言设计无纸化考试系统多少钱,无纸化考试系统解决方案
  18. 实验三+126+黄晟
  19. python之Scapy 中文文档:三、使用方法
  20. 卷毛-网络编程基础(二)什么是socket

热门文章

  1. 关于CH376拷贝U盘文件速度的测试比较
  2. win8怎么查看计算机配置,Win8系统查看电脑显卡配置参数的五个方法
  3. 跟优秀的人一起共事,你会变得越来越优秀
  4. 当比你聪明的人还比你勤奋
  5. 三级网络技术之:网络安全技术
  6. linux cron记录时间,crontab每分钟,5,10分钟,每小时,每天零点,每周日0点,每月1号0点,每年1月1日执行脚本,linux shell定时任务...
  7. C中使用汇编定义的字符串
  8. BOOTMGR is missing问题
  9. P2095 营养膳食
  10. 屏幕截图-QQ/TIM原生截图