This commit is contained in:
NY 2025-03-07 14:14:08 +08:00
parent c4534abe52
commit ab64ec4536
3 changed files with 35 additions and 6 deletions

View File

@ -92,6 +92,7 @@ def layout_config(app):
), ),
html.A( html.A(
href='https://x.com/elonmusk', href='https://x.com/elonmusk',
target='_blank',
children=[ children=[
html.Img( html.Img(
src='https://pbs.twimg.com/profile_images/1893803697185910784/Na5lOWi5_400x400.jpg', src='https://pbs.twimg.com/profile_images/1893803697185910784/Na5lOWi5_400x400.jpg',

View File

@ -1,5 +1,5 @@
import pytz import pytz
from pkg.tool import get_tweets_since_last_friday,format_time_str from pkg.tool import get_tweets_since_last_friday, format_time_str, get_time_since_last_tweet
from pkg.dash.app_init import app from pkg.dash.app_init import app
from dash.dependencies import Input, Output from dash.dependencies import Input, Output
from datetime import timedelta from datetime import timedelta
@ -18,7 +18,8 @@ def update_info(n):
pace_increases = calculate_pace_increase_in_hour() pace_increases = calculate_pace_increase_in_hour()
_, days_to_next_friday = get_pace_params() _, days_to_next_friday = get_pace_params()
table_style_border = {'textAlign': 'center', 'border': '1px solid white'} table_style_border = {'textAlign': 'center', 'border': '1px solid white'}
table_style = {'textAlign': 'center'} table_style_c = {'textAlign': 'center'}
table_style_l = {'textAlign': 'left'}
# First table for Pace # First table for Pace
pace_table_rows = [ pace_table_rows = [
@ -43,9 +44,20 @@ def update_info(n):
html.Td(f"{pace_increases['increase_30']:.2f}", style=table_style_border) html.Td(f"{pace_increases['increase_30']:.2f}", style=table_style_border)
]), ]),
html.Tr([ html.Tr([
html.Td(f"Remain: {format_time_str(days_to_next_friday)}", html.Td(f"Remain",
colSpan=8, colSpan=4,
style=table_style) style=table_style_c),
html.Td(format_time_str(days_to_next_friday),
colSpan=4,
style=table_style_l)
]),
html.Tr([
html.Td(f"Last Tweet",
colSpan=4,
style=table_style_c),
html.Td(format_time_str(get_time_since_last_tweet()),
colSpan=4,
style=table_style_l)
]) ])
] ]
pace_table = html.Table(pace_table_rows, style={ pace_table = html.Table(pace_table_rows, style={

View File

@ -71,6 +71,22 @@ def get_tweets_since_last_friday():
return int(tweet_count) return int(tweet_count)
return 0 return 0
def get_time_since_last_tweet():
est = pytz.timezone('US/Eastern')
now_est = datetime.now(est)
if (not hasattr(render_data, 'global_df') or
render_data.global_df is None or
render_data.global_df.empty):
return 0.0
df = render_data.global_df
if 'datetime_est' not in df.columns:
return 0.0
latest_tweet_time = df['datetime_est'].max()
time_diff = now_est - latest_tweet_time
days_diff = time_diff.total_seconds() / (24 * 60 * 60) # 转换为天数
return days_diff
def format_time_str(days_to_next_friday): def format_time_str(days_to_next_friday):
total_seconds = days_to_next_friday * 24 * 60 * 60 total_seconds = days_to_next_friday * 24 * 60 * 60
days = int(total_seconds // (24 * 60 * 60)) days = int(total_seconds // (24 * 60 * 60))
@ -78,4 +94,4 @@ def format_time_str(days_to_next_friday):
minutes = int((total_seconds % (60 * 60)) // 60) minutes = int((total_seconds % (60 * 60)) // 60)
seconds = int(total_seconds % 60) seconds = int(total_seconds % 60)
total_hours = round(days_to_next_friday * 24, 2) total_hours = round(days_to_next_friday * 24, 2)
return f"{days}d {hours}h {minutes:02d}m {seconds:02d}s ({total_hours}h)" return f"{days}d {hours:02d}h {minutes:02d}m {seconds:02d}s ({total_hours}h)"