python 中的休假报告逻辑和功能需要指导
Guidance needed for leave Report logic and functions in python
我正在使用 python 2.7,Tornado Web 服务,用于数据库的 peewee。
场景获取每个月 26 到下个月 25 的请假报告。
所以我在下面的示例场景中做了这个(但逻辑上我坚持了下来)
我从 UI 得到 from_date,to_date(选择 26 的报告-04-2016 至 25-05-2016)
休假table 是一个 table 名称(它有员工 ID、休假日期、休假日期、working_days)
working_days 只不过是每次休假的次数(29-04-2016 - 02-05-2016)= 2(已排除周六和周日)
单个员工在特定月份的总休假
样本叶子是
24-04-16 - 26-04-16,
28-04-16 - 29-04-16 ,
15-05-2016 至 29-05-2016
我的代码(帮我改一下)
value=0
for report in Leavetable.select().where(Leavetable.Employee_ID==employees_id):
db_from_date = report.From_Date
if (from_date<=db_from_date and to_date>=db_from_date):
workingday=float(report.Working_Days)+value
value= workingday
print value
它在
以上相同的休假中获得价值 = 3
24-04-16 - 26-04-16(需要 1 天但无法锻炼
此代码)
28-04-16 - 29-04-16(拍摄(2 天)
15-05-2016 to 29-05-2016(26,27,28,29要排除这4天)
指导我解决这个逻辑的最简单的解决方案是什么,请做有需要的。
根据 solarflare 指南,我添加了以下代码。
但即使从逻辑上讲,它也不是 fit.The 以上情况,从 2016 年 5 月 15 日到 2016 年 5 月 29 日休假当我在 2016 年 4 月 15 日到 15-05- 做报告时,这个休假也算在内2016
value=0
for report in Leavetable.select().where(Leavetable.Employee_ID==employees_id):
for dt in rrule(DAILY, dtstart=report.From_Date,until=report.To_Date):
if (dt.weekday() < 5):
if (report.To_Date>=from_date and report.From_Date<=to_date):
value += 1
print value
我用基本的if逻辑修改了上面的代码,上面的场景得到了满足我下面列出的代码可能是一些变量名,如果这里有任何评论,可能很难理解:
if (db_from_date>= prev_month and db_to_date<=this_month):
counting = float(working_day)
leave_availed=value+counting
value=leave_availed
elif(db_from_date >= prev_month and db_from_date <= this_month and db_to_date > this_month):
counting = float(working_day)
check_point =counting + 0.5
extra_days = workdays.networkdays(this_month_date,db_to_date,holidays)
if int(check_point)==check_point:
extra_days=extra_days - 0.5
count=counting-extra_days
leave_availed=value+count
value=leave_availed
elif(db_from_date < prev_month and db_to_date>=prev_month and db_to_date <= this_month):
counting = float(working_day)
extra_days = workdays.networkdays(db_from_date,prev_month_date,holidays)
count = counting - extra_days
leave_availed=value+count
value=leave_availed
elif(db_from_date < prev_month and db_to_date > this_month):
count = workdays.networkdays(prev_month,this_month,holidays)
leave_availed=value+count
value=leave_availed
else:
leave_availed=0
我正在使用 python 2.7,Tornado Web 服务,用于数据库的 peewee。
场景获取每个月 26 到下个月 25 的请假报告。
所以我在下面的示例场景中做了这个(但逻辑上我坚持了下来)
我从 UI 得到 from_date,to_date(选择 26 的报告-04-2016 至 25-05-2016)
休假table 是一个 table 名称(它有员工 ID、休假日期、休假日期、working_days)
working_days 只不过是每次休假的次数(29-04-2016 - 02-05-2016)= 2(已排除周六和周日)
单个员工在特定月份的总休假 样本叶子是
24-04-16 - 26-04-16,
28-04-16 - 29-04-16 ,
15-05-2016 至 29-05-2016
我的代码(帮我改一下)
value=0
for report in Leavetable.select().where(Leavetable.Employee_ID==employees_id):
db_from_date = report.From_Date
if (from_date<=db_from_date and to_date>=db_from_date):
workingday=float(report.Working_Days)+value
value= workingday
print value
它在
以上相同的休假中获得价值 = 324-04-16 - 26-04-16(需要 1 天但无法锻炼 此代码)
28-04-16 - 29-04-16(拍摄(2 天)
15-05-2016 to 29-05-2016(26,27,28,29要排除这4天)
指导我解决这个逻辑的最简单的解决方案是什么,请做有需要的。
根据 solarflare 指南,我添加了以下代码。
但即使从逻辑上讲,它也不是 fit.The 以上情况,从 2016 年 5 月 15 日到 2016 年 5 月 29 日休假当我在 2016 年 4 月 15 日到 15-05- 做报告时,这个休假也算在内2016
value=0
for report in Leavetable.select().where(Leavetable.Employee_ID==employees_id):
for dt in rrule(DAILY, dtstart=report.From_Date,until=report.To_Date):
if (dt.weekday() < 5):
if (report.To_Date>=from_date and report.From_Date<=to_date):
value += 1
print value
我用基本的if逻辑修改了上面的代码,上面的场景得到了满足我下面列出的代码可能是一些变量名,如果这里有任何评论,可能很难理解:
if (db_from_date>= prev_month and db_to_date<=this_month):
counting = float(working_day)
leave_availed=value+counting
value=leave_availed
elif(db_from_date >= prev_month and db_from_date <= this_month and db_to_date > this_month):
counting = float(working_day)
check_point =counting + 0.5
extra_days = workdays.networkdays(this_month_date,db_to_date,holidays)
if int(check_point)==check_point:
extra_days=extra_days - 0.5
count=counting-extra_days
leave_availed=value+count
value=leave_availed
elif(db_from_date < prev_month and db_to_date>=prev_month and db_to_date <= this_month):
counting = float(working_day)
extra_days = workdays.networkdays(db_from_date,prev_month_date,holidays)
count = counting - extra_days
leave_availed=value+count
value=leave_availed
elif(db_from_date < prev_month and db_to_date > this_month):
count = workdays.networkdays(prev_month,this_month,holidays)
leave_availed=value+count
value=leave_availed
else:
leave_availed=0