python中休假报告逻辑和函数所需的指导

2024-07-02 11:24:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python2.7中工作,tornado web服务,peewee for database。在

获取每月26日至下个月25日的休假报告。在

所以我在下面的示例场景中做了这个(但从逻辑上讲,我坚持了下来)

我正在从用户界面获取起始日期(选择2016年4月26日至2016年5月25日的报告)

Leavetable是一个表名(它有员工id、休假起始日期、假期结束日期、工作天数)

工作日只算一次休假(2016年4月29日-2016年5月2日)=2(周六、周日已不包括在内)

对于单个员工在特定月份的总假期 样本叶是

  • 2016年4月24日-2016年4月26日,

  • 2016年4月28日-2016年4月29日,

  • 2016年5月15日至2016年5月29日

我的代码(帮助我更改)

       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天时间,但不能在 此代码)

  • 2016年4月28日-2016年4月29日(2天)

  • 2016年5月15日至2016年5月29日(26、27、28、29日必须排除这4天)

指导我什么是最简单的解决办法,使这个逻辑工作请做必要的。在

根据solarflare指南,我添加了以下代码。在

但即使在逻辑上也不是合适的。那个上述情况假期为2016年5月15日至2016年5月29日,当我领取2016年4月15日至2016年5月15日的报告时,此假期也算作假期

^{pr2}$

Tags: 代码fromreportwebidfordbdate
1条回答
网友
1楼 · 发布于 2024-07-02 11:24:54

我用基本的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

相关问题 更多 >