当前位置:   article > 正文

python做考勤统计_使用python统计考勤数据

使用python统计考勤数据

本来想用python做一个考勤统计的软件,但是由于种种原因,暂停了这个想法,这是个软件的雏形,仅供大家参考


这个小玩意涉及了文件的读取,时间的比较,异常的处理,编码处理,可以用于python的初级练手,接下来,我就把代码贴出来供大家参考:


  1. #coding:utf8
  2. '''
  3. Created on 2016年6月27
  4. @author: hehe
  5. '''
  6. import xlrd
  7. import time
  8. import datetime
  9. import sys
  10. default_encoding = 'utf-8'
  11. if sys.getdefaultencoding() != default_encoding:
  12. reload(sys)
  13. sys.setdefaultencoding(default_encoding)
  14. # use for to read all tables
  15. def readtable():
  16. data = xlrd.open_workbook(r'C:\Users\8888\Desktop\haha.xlsx')
  17. table = data.sheet_by_index(0)
  18. return table
  19. def get_num_nrow(table):
  20. return table.nrows
  21. def compute_time(time_begin , time_end):
  22. hour , minu = (int)(str(compare_time(time_begin, time_end))[0]),(int)(str(compare_time(time_begin, time_end))[2])*10+(int)(str(compare_time(time_begin, time_end))[3])
  23. return hour*60 + minu
  24. def compare_time(time_begin, time_end):
  25. date_1 = time.strptime(time_begin,"%H:%M")
  26. date_2 = time.strptime(time_end,"%H:%M")
  27. date1=datetime.datetime(date_1[0],date_1[1],date_1[2],date_1[3],date_1[4],date_1[5])
  28. date2=datetime.datetime(date_2[0],date_2[1],date_2[2],date_2[3],date_2[4],date_2[5])
  29. #print date2-date1
  30. return date2-date1
  31. def com_chidao(time_begin,time_s_beg):
  32. a=0
  33. b=0
  34. try:
  35. a=compute_time(time_begin,time_s_beg)
  36. except Exception:
  37. b=compute_time(time_s_beg,time_begin)
  38. return a,b
  39. def com_zaotui(time_begin,time_s_beg):
  40. c=0
  41. d=0
  42. try:
  43. c=compute_time(time_begin,time_s_beg)
  44. except Exception:
  45. d=compute_time(time_s_beg,time_begin)
  46. return c,d
  47. def judge_morning(time_list):
  48. time_begin = time_list[0]
  49. time_s_beg = u'8:30'
  50. time_end = time_list[1]
  51. time_s_end = u'12:00'
  52. if time_begin=='':
  53. print '早上没来'
  54. elif time_begin!='' and time_end=='':
  55. print '未签退'
  56. elif time_begin!='' and time_end!='':
  57. a,b=com_chidao(time_begin,time_s_beg)
  58. #c,d = com_zaotui(time_s_end,time_end)
  59. if a==0 and b!=0:
  60. print '迟到%d分'%b
  61. #if c==0 and d!=0:
  62. # print '早退%d分'%d
  63. else :
  64. print compare_time(time_begin,time_end)
  65. def judge_afternoon(time_list):
  66. time_begin = time_list[2]
  67. time_s_beg = u'14:30'
  68. time_end = time_list[3]
  69. time_s_end = u'18:00'
  70. if time_begin=='':
  71. print '下午没来'
  72. elif time_begin!='' and time_end=='':
  73. print '未签退'
  74. elif time_begin!='' and time_end!='':
  75. a,b=com_chidao(time_begin,time_s_beg)
  76. #c,d = com_zaotui(time_s_end,time_end)
  77. if a==0 and b!=0:
  78. print '迟到%d分'%b
  79. #if c==0 and d!=0:
  80. # print '早退%d分'%d
  81. else :
  82. print compare_time(time_begin,time_end)
  83. def judge_neight(time_list):
  84. time_begin = time_list[4]
  85. time_s_beg = u'19:30'
  86. time_end = time_list[5]
  87. time_s_end = u'22:00'
  88. if time_begin=='':
  89. print '晚上没来'
  90. elif time_begin!='' and time_end=='':
  91. print '未签退'
  92. elif time_begin!='' and time_end!='':
  93. a,b=com_chidao(time_begin,time_s_beg)
  94. #c,d = com_zaotui(time_s_end,time_end)
  95. if a==0 and b!=0:
  96. print '迟到%d分'%b
  97. #if c==0 and d!=0:
  98. # print '早退%d分'%d
  99. else :
  100. print compare_time(time_begin,time_end)
  101. if __name__ == '__main__':
  102. chidao = 0
  103. kuang = 0
  104. kuang_day = 0
  105. val_time = 0
  106. all_time = 0
  107. data = []
  108. table = readtable()
  109. print 'done'
  110. for i in range(get_num_nrow(table) ):
  111. value = table.row_values(i)
  112. if value[0][3]=='日':
  113. continue
  114. time_1_be , time_1_end , time_2_be ,time_2_end , time_3_be , time_3_end =value[1] ,value[3] ,value[6] ,value[8], value[10] ,value[12]
  115. #print time_1_be , time_1_end , time_2_be ,time_2_end , time_3_be , time_3_end
  116. time_list = [time_1_be , time_1_end , time_2_be ,time_2_end , time_3_be , time_3_end]
  117. if time_list[0]=='旷工':
  118. print '旷工'
  119. kuang_day+=1
  120. kuang+=3
  121. continue
  122. #print time_list[0]
  123. #judje mornaing
  124. judge_morning(time_list)
  125. #judje afternoon
  126. judge_afternoon(time_list)
  127. #judge neight
  128. judge_neight(time_list)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/997363
推荐阅读
相关标签
  

闽ICP备14008679号