Skip to content

Commit

Permalink
重新计算今日预测
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetree committed Dec 20, 2023
1 parent 5ea0646 commit 5af71ce
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions apps/blog/templatetags/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,22 @@ def get_today_views_by_forecast():
'article_every_hours')
thi_page_hours = ArticleViewsTool.get_date_value_by_key(thi_date_str, 'page_every_hours')
# 如果有上周的今天的数据,则使用上周数据,否使用昨天数据
if last_week_article_hours and last_week_page_hours:
yes_article_hours = last_week_article_hours
yes_page_hours = last_week_page_hours
# 昨天数据必须满24小时,今天数据最少有一个小时的才能计算
if all([yes_article_hours.get('23'), yes_page_hours.get('23'),
yes_article_hours.get(last_hour), yes_page_hours.get(last_hour),
if all([last_week_article_hours.get('23'), last_week_page_hours.get('23'),
last_week_article_hours.get(last_hour), last_week_page_hours.get(last_hour),
yes_article_hours.get('23'), yes_page_hours.get('23'),
thi_article_hours.get(last_hour), thi_page_hours.get(last_hour)]):
last_week_total_views = last_week_article_hours['23'] + last_week_page_hours['23']
last_week_done_views = last_week_article_hours[last_hour] + last_week_page_hours[last_hour]
yes_total_views = yes_article_hours['23'] + yes_page_hours['23'] # 昨日总计
thi_done_views = thi_article_hours[last_hour] + thi_page_hours[last_hour] # 今日此时总计
result = thi_done_views + (last_week_total_views - last_week_done_views) - yes_total_views
elif all([yes_article_hours.get('23'), yes_page_hours.get('23'),
yes_article_hours.get(last_hour), yes_page_hours.get(last_hour),
thi_article_hours.get(last_hour), thi_page_hours.get(last_hour)]):
yes_total_views = yes_article_hours['23'] + yes_page_hours['23'] # 昨日总计
yes_done_views = yes_article_hours[last_hour] + yes_page_hours[last_hour] # 昨日此时总计
thi_done_views = thi_article_hours[last_hour] + thi_page_hours[last_hour] # 今日此时总计
result = thi_done_views + (yes_total_views - yes_done_views)
result = thi_done_views + (yes_total_views - yes_done_views) - yes_total_views
return result


Expand Down

0 comments on commit 5af71ce

Please sign in to comment.