import sc3
import re
def get処理月():#処理月を文字列で返す
s=daydef[0] #daydef=['2019-12-01','2019-12-02'...
m=re.search(r'-\d+-', s)#-dd- Regular Pattern search
s=m.group().replace('-','')#dd delete -
#sc3.print(s)
return s
def 支援禁止(person,day,phase):#日勤なら余りを強制する
sam='日勤ならAM余りのみ'+staffdef[person]+' '+daydef[day]
S=sc3.GetShiftVar(person,day,'日勤')
vam=sc3.GetTaskVar(person,day,AM,'半日')#余り
#A->B =!A|B
sc3.AddHard(~S|vam,sam)
spm='日勤ならPM余りのみ'+staffdef[person]+' '+daydef[day]
vpm=sc3.GetTaskVar(person,day,PM,'半日')#余り
#A->B =!A|B
sc3.AddHard(~S|vpm,spm)
def 今月支援禁止(person):
s=staffdef[person]+'を今月支援禁止にします。\n'
sc3.print(s)
for day in 全日:
支援禁止(person,day,AM);
支援禁止(person,day,PM);
def Month支援禁止制約():
for person in 出勤1月属性.keys():
if get処理月()=='1':
今月支援禁止(person)
for person in 出勤2月属性.keys():
if get処理月()=='2':
今月支援禁止(person)
for person in 出勤3月属性.keys():
if get処理月()=='3':
今月支援禁止(person)
for person in 出勤4月属性.keys():
if get処理月()=='4':
今月支援禁止(person)
for person in 出勤5月属性.keys():
if get処理月()=='5':
今月支援禁止(person)
for person in 出勤6月属性.keys():
if get処理月()=='6':
今月支援禁止(person)
for person in 出勤7月属性.keys():
if get処理月()=='7':
今月支援禁止(person)
for person in 出勤8月属性.keys():
if get処理月()=='8':
今月支援禁止(person)
for person in 出勤9月属性.keys():
if get処理月()=='9':
今月支援禁止(person)
for person in 出勤10月属性.keys():
if get処理月()=='10':
今月支援禁止(person)
for person in 出勤12月属性.keys():
if get処理月()=='12':
今月支援禁止(person)

スタッフプロパティ、各月で、支援業務遂行不可能なスタッフに0がついています。
Pythonで、それを拾ってきて、今月がその月になったときだけ制約するという究極のメンテナンスフリーを狙った記述になります。(この部分だけ取れば、Excelを毎月読ませることも不要)
Python記述で必要になるのは、今月が該当月に相当するかどうかの判定部です。それには、今月のmonthを取得するルーチンが必要となり、それが、get処理月()になります。正規表現ライブラリを
importして、正規表現で処理しています。正規表現で、シンプルに文字列処理できます。
pythonインタプリタがどこまで頑張れるかよく分かっていないのですが、標準ライブラリについては大丈夫なようです。巨大なライブラリ、例えばopenpyxlは、動きませんでした。
0 件のコメント:
コメントを投稿