fix
This commit is contained in:
parent
a0f436c98f
commit
82f69596b8
@ -1,7 +1,8 @@
|
|||||||
|
import pytz
|
||||||
|
from pkg.tool import get_tweets_since_last_friday
|
||||||
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
|
||||||
import pytz
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from dash import html
|
from dash import html
|
||||||
|
|
||||||
@ -10,18 +11,36 @@ from dash import html
|
|||||||
[Input('clock-interval', 'n_intervals')]
|
[Input('clock-interval', 'n_intervals')]
|
||||||
)
|
)
|
||||||
def update_info(n):
|
def update_info(n):
|
||||||
table = html.Table([
|
# 获取所有指标
|
||||||
html.Tr([html.Td('Pace(Xtracker)', style={'textAlign': 'center'}),
|
pace = calculate_tweet_pace()
|
||||||
html.Td(calculate_tweet_pace(),style={'textAlign': 'center'})]),
|
decline_rates = calculate_pace_decline_rate()
|
||||||
], style={
|
pace_increases = calculate_pace_increase_in_hour()
|
||||||
|
table_rows = [
|
||||||
|
html.Tr([html.Td('Pace (Xtracker)', style={'textAlign': 'center'}),
|
||||||
|
html.Td(pace, style={'textAlign': 'center'})]),
|
||||||
|
html.Tr([html.Td('-Minute', style={'textAlign': 'center'}),
|
||||||
|
html.Td(decline_rates['decline_per_minute'], style={'textAlign': 'center'})]),
|
||||||
|
html.Tr([html.Td('+0(1h)', style={'textAlign': 'center'}),
|
||||||
|
html.Td(decline_rates['decline_per_hour'], style={'textAlign': 'center'})]),
|
||||||
|
html.Tr([html.Td('+1(1h)', style={'textAlign': 'center'}),
|
||||||
|
html.Td(pace_increases['increase_1'], style={'textAlign': 'center'})]),
|
||||||
|
html.Tr([html.Td('+5(1h)', style={'textAlign': 'center'}),
|
||||||
|
html.Td(pace_increases['increase_5'], style={'textAlign': 'center'})]),
|
||||||
|
html.Tr([html.Td('+10(1h)', style={'textAlign': 'center'}),
|
||||||
|
html.Td(pace_increases['increase_10'], style={'textAlign': 'center'})]),
|
||||||
|
html.Tr([html.Td('+20(1h)', style={'textAlign': 'center'}),
|
||||||
|
html.Td(pace_increases['increase_20'], style={'textAlign': 'center'})]),
|
||||||
|
html.Tr([html.Td('+30(1h)', style={'textAlign': 'center'}),
|
||||||
|
html.Td(pace_increases['increase_30'], style={'textAlign': 'center'})]),
|
||||||
|
]
|
||||||
|
table = html.Table(table_rows, style={
|
||||||
'width': '100%',
|
'width': '100%',
|
||||||
'textAlign': 'left',
|
'textAlign': 'left',
|
||||||
'borderCollapse': 'collapse'
|
'borderCollapse': 'collapse'
|
||||||
})
|
})
|
||||||
return [table]
|
return [table]
|
||||||
|
|
||||||
|
def get_pace_params():
|
||||||
def calculate_tweet_pace():
|
|
||||||
est = pytz.timezone('US/Eastern')
|
est = pytz.timezone('US/Eastern')
|
||||||
now = datetime.now(est)
|
now = datetime.now(est)
|
||||||
today = now.date()
|
today = now.date()
|
||||||
@ -33,6 +52,34 @@ def calculate_tweet_pace():
|
|||||||
if now > next_friday:
|
if now > next_friday:
|
||||||
next_friday += timedelta(days=7)
|
next_friday += timedelta(days=7)
|
||||||
days_to_next_friday = (next_friday - now).total_seconds() / (24 * 60 * 60)
|
days_to_next_friday = (next_friday - now).total_seconds() / (24 * 60 * 60)
|
||||||
tweet_count = 440
|
tweet_count = get_tweets_since_last_friday()
|
||||||
|
return tweet_count, days_to_next_friday
|
||||||
|
|
||||||
|
def calculate_tweet_pace():
|
||||||
|
tweet_count, days_to_next_friday = get_pace_params()
|
||||||
pace = (tweet_count / (7 - days_to_next_friday)) * days_to_next_friday + tweet_count
|
pace = (tweet_count / (7 - days_to_next_friday)) * days_to_next_friday + tweet_count
|
||||||
return round(pace, 6) if pace > 0 else float(tweet_count)
|
return round(pace, 6) if pace > 0 else float(tweet_count)
|
||||||
|
|
||||||
|
def calculate_pace_decline_rate():
|
||||||
|
tweet_count, days_to_next_friday = get_pace_params()
|
||||||
|
T = 7
|
||||||
|
decline_per_day = -(tweet_count * T) / ((T - days_to_next_friday) ** 2)
|
||||||
|
decline_per_hour = decline_per_day / 24
|
||||||
|
decline_per_minute = decline_per_hour / 60
|
||||||
|
return {
|
||||||
|
'decline_per_hour': round(decline_per_hour, 6),
|
||||||
|
'decline_per_minute': round(decline_per_minute, 6)
|
||||||
|
}
|
||||||
|
|
||||||
|
def calculate_pace_increase_in_hour():
|
||||||
|
tweet_count, days_to_next_friday = get_pace_params()
|
||||||
|
current_pace = (tweet_count / (7 - days_to_next_friday)) * days_to_next_friday + tweet_count
|
||||||
|
future_days = days_to_next_friday - (1 / 24)
|
||||||
|
increments = [1, 5, 10, 20, 30]
|
||||||
|
pace_increases = {}
|
||||||
|
for increment in increments:
|
||||||
|
new_tweet_count = tweet_count + increment
|
||||||
|
new_pace = (new_tweet_count / (7 - future_days)) * future_days + new_tweet_count
|
||||||
|
pace_increase = new_pace - current_pace
|
||||||
|
pace_increases[f'increase_{increment}'] = round(pace_increase, 6)
|
||||||
|
return pace_increases
|
||||||
|
@ -64,13 +64,8 @@ def get_tweets_since_last_friday():
|
|||||||
last_friday_datetime = est.localize(datetime.combine(last_friday, datetime.strptime("12:00", "%H:%M").time()))
|
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:
|
if hasattr(render_data, 'global_df') and not render_data.global_df.empty:
|
||||||
df = render_data.global_df.copy()
|
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
|
mask = df['datetime_est'] >= last_friday_datetime
|
||||||
filtered_df = df[mask]
|
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)
|
tweet_count = len(filtered_df)
|
||||||
print(f"Tweet count: {tweet_count}")
|
|
||||||
return int(tweet_count)
|
return int(tweet_count)
|
||||||
return 0
|
return 0
|
Loading…
x
Reference in New Issue
Block a user