**Overview:**
- 合并了12 ;
- ♻️ 对代码进行了重写;
- 💬 优化了部分文字描述。
**Technology Changes:**
- ♻️ 将除预测国庆假期以外的假期的预测算法全部重写,由多次的 if 更改为查表法。
> [!NOTE]
> 下面是一段修改前后的代码对比:
>
> 修改前:
> (main.py)
>
> elif holiday_name in ("--may-day", "-md"): 该部分用于处理五一假期的调休预测。
> if not '--do-not-output-notes' in given_list:
> print(Data.may_day_note)
> may_day_date: datetime.datetime = datetime.datetime(year=forecast_year, month=5, day=1)
> may_day_dateofweek: int = may_day_date.weekday()
> 下述代码对五一假期的调休进行运算。
> if may_day_dateofweek == 0:
> 调休
> hld_days = 5
> hld_startdate = may_day_date - datetime.timedelta(days=2)
> hld_enddate = may_day_date + datetime.timedelta(days=2)
> lieu_1 = may_day_date - datetime.timedelta(days=8)
> lieu_2 = may_day_date + datetime.timedelta(days=5)
> elif may_day_dateofweek == 1:
> 调休
> hld_days = 5
> hld_startdate = may_day_date - datetime.timedelta(days=3)
> hld_enddate = may_day_date + datetime.timedelta(days=1)
> lieu_1 = may_day_date - datetime.timedelta(days=9)
> lieu_2 = may_day_date + datetime.timedelta(days=4)
> elif may_day_dateofweek == 2:
> 不调休
> hld_days = 5
> hld_startdate = may_day_date
> hld_enddate = may_day_date + datetime.timedelta(days=4)
> lieu_1 = may_day_date - datetime.timedelta(days=3)
> lieu_2 = may_day_date + datetime.timedelta(days=10)
> elif may_day_dateofweek == 3:
> 调休
> hld_days = 5
> hld_startdate = may_day_date
> hld_enddate = may_day_date + datetime.timedelta(days=4)
> lieu_1 = may_day_date - datetime.timedelta(days=4)
> lieu_1 = may_day_date + datetime.timedelta(days=9)
> elif may_day_dateofweek == 4:
> 调休
> hld_days = 5
> hld_startdate = may_day_date
> hld_enddate = may_day_date + datetime.timedelta(days=4)
> lieu_1 = may_day_date - datetime.timedelta(days=5)
> lieu_1 = may_day_date + datetime.timedelta(days=8)
> elif may_day_dateofweek == 5:
> 调休
> hld_days = 5
> hld_startdate = may_day_date
> hld_enddate = may_day_date + datetime.timedelta(days=4)
> lieu_1 = may_day_date - datetime.timedelta(days=6)
> lieu_1 = may_day_date + datetime.timedelta(days=7)
> elif may_day_dateofweek == 6:
> 调休
> hld_days = 3
> hld_startdate = may_day_date - datetime.timedelta(days=1)
> hld_enddate = may_day_date + datetime.timedelta(days=3)
> lieu_1 = may_day_date - datetime.timedelta(days=7)
> lieu_1 = may_day_date + datetime.timedelta(days=6)
> else:
> raise AssertionError
>
>
> 修改后:
> (main.py)
>
> elif holiday_name in ("--may-day", "-md"): 该部分用于处理五一假期的调休预测。
> if not '--do-not-output-notes' in given_list:
> print(Data.may_day_note)
> may_day_date: datetime.datetime = datetime.datetime(year=forecast_year, month=5, day=1)
> may_day_dateofweek: int = may_day_date.weekday()
> 下述代码对五一假期的调休进行运算。
> hld_days = Data.may_day_days[may_day_dateofweek]
> hld_startdate = \
> may_day_date + datetime.timedelta(
> Data.may_day_start_delta_day[may_day_dateofweek])
> hld_enddate = \
> may_day_date + datetime.timedelta(Data.may_day_end_delta_day[may_day_dateofweek])
> lieu_1 = \
> may_day_date + datetime.timedelta(
> Data.may_day_lieu1_delta_day[may_day_dateofweek])
> lieu_2 = \
> may_day_date + datetime.timedelta(
> Data.may_day_lieu2_delta_day[may_day_dateofweek])
>
> (data.py)
>
> 以下这五行存储的是五一假期的放假安排,这些数据代表与节日当天差的天数
> may_day_days = [ 5, 5, 5, 5, 5, 5, 5]
> may_day_start_delta_day = [-2, -3, 0, 0, 0, 0, -1]
> may_day_end_delta_day = [ 2, 1, 4, 4, 4, 4, 3]
> may_day_lieu1_delta_day = [-8, -9, -3, -4, -5, -6, -7]
> may_day_lieu2_delta_day = [ 5, 4, 10, 9, 8, 7, 6]
>
>
> 修改后的代码,简洁明了许多。
**Text Changes:**
- 💬 将帮助信息中的“最后,五一放假五天”更为“时至今日,五一放假五天”。使用词更严谨、更准确。