88 lines
3.8 KiB
Python
Raw Permalink Normal View History

2025-03-14 15:08:29 +08:00
from pkg.dash.func.info_func import *
from pkg.tool import format_time_str, get_time_since_last_tweet
2025-03-06 13:59:37 +08:00
from pkg.dash.app_init import app
from dash.dependencies import Input, Output
from dash import html
2025-03-07 13:52:35 +08:00
2025-03-06 13:59:37 +08:00
@app.callback(
[Output('info-tooltip', 'children')],
2025-03-12 17:40:20 +08:00
[Input('clock-interval', 'n_intervals'),
Input('target-input', 'value'),
Input('predict-tweets-input', 'value'),
Input('hour-input', 'value')]
2025-03-06 13:59:37 +08:00
)
def update_info(n, target_value, increment_value, hour_value):
2025-03-06 14:53:17 +08:00
pace = calculate_tweet_pace()
decline_rates = calculate_pace_decline_rate()
pace_increases = calculate_pace_increase_in_hour(increment_value, hour_value)
2025-03-12 17:40:20 +08:00
tweet_count, days_to_next_friday = get_pace_params()
remain_hours = days_to_next_friday * 24
now = tweet_count
2025-03-07 13:52:35 +08:00
table_style_border = {'textAlign': 'center', 'border': '1px solid white'}
2025-03-07 14:14:08 +08:00
table_style_c = {'textAlign': 'center'}
table_style_l = {'textAlign': 'left'}
2025-03-07 13:52:35 +08:00
2025-03-12 17:40:20 +08:00
target = int(target_value) if target_value is not None else None
2025-03-12 17:43:24 +08:00
avg_tweets_per_day = calculate_avg_tweets_per_day(target, now, remain_hours) if target is not None else "TBD"
2025-03-12 17:40:20 +08:00
days_passed = 7 - days_to_next_friday
avg_tweets = round(tweet_count / days_passed, 2) if days_passed > 0 else 0
custom_increment = pace_increases.get('custom_increment')
if custom_increment is None:
custom_header = "[TBD]"
custom_value = "TBD"
else:
increment = pace_increases['custom_increment_key']
hours = int(hour_value)
custom_header = f"{increment}({hours}h)"
custom_value = f"{custom_increment:.2f}"
2025-03-07 13:52:35 +08:00
pace_table_rows = [
html.Tr([
html.Th('Pace', style=table_style_border),
html.Th('DCL', style=table_style_border),
html.Th('0(1h)', style=table_style_border),
html.Th('1(1h)', style=table_style_border),
html.Th('5(1h)', style=table_style_border),
html.Th('10(1h)', style=table_style_border),
html.Th('20(1h)', style=table_style_border),
html.Th(custom_header, style=table_style_border)
2025-03-07 13:52:35 +08:00
]),
html.Tr([
html.Td(f"{pace:.2f}", style=table_style_border),
html.Td(decline_rates, style=table_style_border),
html.Td(f"{pace_increases['increase_0']:.2f}", style=table_style_border),
html.Td(f"{pace_increases['increase_1']:.2f}", style=table_style_border),
html.Td(f"{pace_increases['increase_5']:.2f}", style=table_style_border),
html.Td(f"{pace_increases['increase_10']:.2f}", style=table_style_border),
html.Td(f"{pace_increases['increase_20']:.2f}", style=table_style_border),
html.Td(custom_value, style=table_style_border)
2025-03-07 13:52:35 +08:00
]),
html.Tr([
html.Td(f"Remain", colSpan=4, style=table_style_c),
html.Td(format_time_str(days_to_next_friday), colSpan=4, style=table_style_l)
2025-03-07 14:14:08 +08:00
]),
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)
2025-03-11 09:47:44 +08:00
]),
2025-03-12 17:40:20 +08:00
html.Tr([
2025-03-12 17:52:32 +08:00
html.Th("Target", colSpan=2, style=table_style_border),
html.Th("Need's Avg Tweets Per Day", colSpan=4, style=table_style_border),
html.Th("Avg Tweets", colSpan=2, style=table_style_border),
2025-03-12 17:40:20 +08:00
]),
html.Tr([
2025-03-12 17:52:32 +08:00
html.Td(f"{target if target else '[TBD]'}", colSpan=2, style=table_style_border),
html.Td(f"{avg_tweets_per_day}", colSpan=4, style=table_style_border),
html.Td(f"{avg_tweets}", colSpan=2, style=table_style_border),
2025-03-07 13:52:35 +08:00
])
2025-03-06 14:53:17 +08:00
]
2025-03-07 13:52:35 +08:00
pace_table = html.Table(pace_table_rows, style={
2025-03-06 13:59:37 +08:00
'width': '100%',
'textAlign': 'left',
'borderCollapse': 'collapse'
})
2025-03-07 13:52:35 +08:00
return [pace_table]