Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
data_report
/
data-report
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit bac8d242
authored
Oct 14, 2026
by
章家宝
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:红黄门店如果按周,则根据选择的周的时间来计算
1 parent
bc11eed4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
data-process/common_equity_processor.py
data-process/common_equity_processor.py
View file @
bac8d24
...
@@ -1384,32 +1384,32 @@ class CommonEquityProcessor:
...
@@ -1384,32 +1384,32 @@ class CommonEquityProcessor:
# ============================================================
# ============================================================
@staticmethod
@staticmethod
def
_weekly_ranges
(
period_start
):
def
_weekly_ranges
(
period_start
,
period_end
):
"""以 period_start 所在月份为基准生成累计制周窗口(每周都从 1 号起算)。
"""以 period_start 所在月份为基准生成累计制周窗口(每周都从 1 号起算)。
W1 = 1 号 ~ 当月第一个周日,W2 = 1 号 ~ 第二个周日,以此类推;最后一个
W1 = 1 号 ~ 当月第一个周日,W2 = 1 号 ~ 第二个周日,以此类推;
周日之后到月末的余段直接截到月底、单独作最后一周。
周数按 period_end 截断:页面按周生成时 period_end 为所选周的周日,
周数动态 = 当月周日个数 + (最后一个周日不在月末时为 1):通常 5 周;
只生成到该周为止(如选 W4 则只有 W1~W4,不会再出 W5/W6);
当月有 5 个周日且月末落在周中时为 6 周(如 2026-03 / 08 / 11);2 月
period_end 不在周日时(理论上不会出现),最后一周直接截到 period_end。
恰为 28 天且 1 号为周一时只有 4 周(如 2027-02)。
例:2026-09(1 号为周二)整月 → W1 1~6、W2 1~13、W3 1~20、W4 1~27、W5 1~30。
例:2026-09(1 号为周二)→ W1 1~6、W2 1~13、W3 1~20、W4 1~27、W5 1~30。
与任务周期的 week/month 粒度无关,始终按自然月划分。
"""
"""
last_day
=
calendar
.
monthrange
(
period_start
.
year
,
period_start
.
month
)[
1
]
last_day
=
calendar
.
monthrange
(
period_start
.
year
,
period_start
.
month
)[
1
]
month_start
=
date
(
period_start
.
year
,
period_start
.
month
,
1
)
month_start
=
date
(
period_start
.
year
,
period_start
.
month
,
1
)
month_end
=
date
(
period_start
.
year
,
period_start
.
month
,
last_day
)
month_end
=
date
(
period_start
.
year
,
period_start
.
month
,
last_day
)
effective_end
=
min
(
month_end
,
period_end
)
# 当月第一个周日:weekday() 周一=0 .. 周日=6,1 号本身就是周日时取当天
# 当月第一个周日:weekday() 周一=0 .. 周日=6,1 号本身就是周日时取当天
first_sunday
=
month_start
+
timedelta
(
days
=
(
6
-
month_start
.
weekday
())
%
7
)
first_sunday
=
month_start
+
timedelta
(
days
=
(
6
-
month_start
.
weekday
())
%
7
)
ranges
=
[]
ranges
=
[]
cursor
=
first_sunday
cursor
=
first_sunday
while
cursor
<=
month
_end
:
while
cursor
<=
effective
_end
:
ranges
.
append
((
f
"W{len(ranges) + 1}"
,
month_start
,
cursor
))
ranges
.
append
((
f
"W{len(ranges) + 1}"
,
month_start
,
cursor
))
cursor
+=
timedelta
(
days
=
7
)
cursor
+=
timedelta
(
days
=
7
)
# 末尾不足一周的余段(如 9/28~9/30)直接到月底,单独作最后一周
# 末尾余段:period_end 不是周日(或最后一个周日之后仍有余量到月末)时,
if
ranges
[
-
1
][
2
]
<
month_end
:
# 从 1 号累计到 effective_end 作为最后一周
ranges
.
append
((
f
"W{len(ranges) + 1}"
,
month_start
,
month_end
))
if
not
ranges
or
ranges
[
-
1
][
2
]
<
effective_end
:
ranges
.
append
((
f
"W{len(ranges) + 1}"
,
month_start
,
effective_end
))
return
ranges
return
ranges
def
_fetch_weekly_cumulative
(
self
,
merchant_ids
,
ranges
):
def
_fetch_weekly_cumulative
(
self
,
merchant_ids
,
ranges
):
...
@@ -1491,7 +1491,7 @@ class CommonEquityProcessor:
...
@@ -1491,7 +1491,7 @@ class CommonEquityProcessor:
cleaned
=
self
.
_validate_red_yellow_rows
(
parsed
,
store_rows
,
threshold_map
)
cleaned
=
self
.
_validate_red_yellow_rows
(
parsed
,
store_rows
,
threshold_map
)
merchant_ids
=
list
(
store_index
.
keys
())
merchant_ids
=
list
(
store_index
.
keys
())
ranges
=
self
.
_weekly_ranges
(
task
.
period_start
)
ranges
=
self
.
_weekly_ranges
(
task
.
period_start
,
task
.
period_end
)
weekly
=
self
.
_fetch_weekly_cumulative
(
merchant_ids
,
ranges
)
weekly
=
self
.
_fetch_weekly_cumulative
(
merchant_ids
,
ranges
)
week_labels
=
[
label
for
label
,
_s
,
_e
in
ranges
]
week_labels
=
[
label
for
label
,
_s
,
_e
in
ranges
]
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment