1.增加info,目前支持计算Xtracker的Pace。

2.增加Total Tweets(本周多少Tweets)
This commit is contained in:
NY 2025-03-06 13:59:21 +08:00
parent 8a4aa2c0c0
commit 205b1ed311
4 changed files with 76 additions and 10 deletions

View File

@ -63,6 +63,33 @@ def layout_config(app):
'whiteSpace': 'nowrap'
}
),
# 新增按钮和提示框
html.Div(
id='info-button',
children='',
style={
'fontSize': '24px',
'cursor': 'pointer',
'padding': '5px',
'marginTop': '10px'
}
),
html.Div(
id='info-tooltip',
children='这是一个信息按钮示例', # 默认显示的信息
style={
'position': 'absolute',
'left': '35px',
'top': '80px', # 调整位置,避免与其他 tooltip 重叠
'backgroundColor': 'rgba(0, 0, 0, 0.8)',
'color': 'white',
'padding': '10px',
'borderRadius': '5px',
'fontSize': '14px',
'display': 'none',
'whiteSpace': 'nowrap'
}
),
html.A(
href='https://x.com/elonmusk',
children=[

View File

@ -2,7 +2,7 @@ from datetime import datetime, timedelta
from dash.dependencies import Input, Output
from pkg.dash.app_init import app
from pkg.config import render_data
from pkg.tool import aggregate_data, generate_xticks, minutes_to_time
from pkg.tool import aggregate_data, generate_xticks, minutes_to_time, get_tweets_since_last_friday
from dash import dcc
import plotly.graph_objs as go
import pandas as pd
@ -137,5 +137,5 @@ def render_tab_content(tab, selected_dates, interval, time_zones, days_to_displa
yaxis=dict(autorange='reversed') if tab == 'one_day_heatmap' else None
)
summary = f"Total tweets for selected dates: {int(tweet_count_total)}"
summary = f"Total tweets for selected dates: {int(tweet_count_total)}Total tweets: {get_tweets_since_last_friday()}"
return dcc.Graph(figure=fig), warning, summary

View File

@ -1,18 +1,29 @@
from dash.dependencies import Input, Output, State
from dash import clientside_callback
def setting_callback():
clientside_callback(
"""
function(n_intervals) {
const button = document.getElementById('clock-button');
const tooltip = document.getElementById('clock-tooltip');
if (button && tooltip) {
button.addEventListener('mouseover', () => {
tooltip.style.display = 'block';
const clockButton = document.getElementById('clock-button');
const clockTooltip = document.getElementById('clock-tooltip');
if (clockButton && clockTooltip) {
clockButton.addEventListener('mouseover', () => {
clockTooltip.style.display = 'block';
});
button.addEventListener('mouseout', () => {
tooltip.style.display = 'none';
clockButton.addEventListener('mouseout', () => {
clockTooltip.style.display = 'none';
});
}
const infoButton = document.getElementById('info-button');
const infoTooltip = document.getElementById('info-tooltip');
if (infoButton && infoTooltip) {
infoButton.addEventListener('mouseover', () => {
infoTooltip.style.display = 'block';
});
infoButton.addEventListener('mouseout', () => {
infoTooltip.style.display = 'none';
});
}
return window.dash_clientside.no_update;

View File

@ -1,5 +1,7 @@
from datetime import datetime
from datetime import datetime, timedelta
import pandas as pd
from pkg.config import render_data
import pytz
def aggregate_data(data, interval):
all_minutes = pd.DataFrame({'interval_group': range(0, 1440, interval)})
@ -46,3 +48,29 @@ def minutes_to_time(minutes):
hours = minutes // 60
mins = minutes % 60
return f"{hours:02d}:{mins:02d}"
def get_tweets_since_last_friday():
est = pytz.timezone('US/Eastern')
now_est = datetime.now(est)
today = now_est.date()
days_since_last_friday = (today.weekday() - 4) % 7
last_friday = today - timedelta(days=days_since_last_friday)
last_friday_datetime = est.localize(datetime.combine(last_friday, datetime.strptime("12:00", "%H:%M").time()))
this_friday = today - timedelta(days=(today.weekday() - 4) % 7)
this_friday_datetime = est.localize(datetime.combine(this_friday, datetime.strptime("12:00", "%H:%M").time()))
if now_est < this_friday_datetime and today.weekday() != 4:
last_friday -= timedelta(days=7)
last_friday_datetime = est.localize(datetime.combine(last_friday, datetime.strptime("12:00", "%H:%M").time()))
if hasattr(render_data, 'global_df') and not render_data.global_df.empty:
df = render_data.global_df.copy()
print(f"NaT count in datetime_est: {df['datetime_est'].isna().sum()}")
print(f"Data datetime range: {df['datetime_est'].min()} to {df['datetime_est'].max()}")
mask = df['datetime_est'] >= last_friday_datetime
filtered_df = df[mask]
print(f"Filtered rows: {len(filtered_df)}")
print(f"Filtered datetime range: {filtered_df['datetime_est'].min()} to {filtered_df['datetime_est'].max()}")
tweet_count = len(filtered_df)
print(f"Tweet count: {tweet_count}")
return int(tweet_count)
return 0