ginipick commited on
Commit
310dcf0
ยท
verified ยท
1 Parent(s): 1492104

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -11
app.py CHANGED
@@ -57,13 +57,16 @@ def create_trend_chart(space_id, daily_ranks_df):
57
  return None
58
 
59
  def get_duplicate_spaces(top_100_spaces):
60
- # ID๋ณ„ trending score ํ•ฉ์‚ฐ
61
- score_sums = top_100_spaces.groupby('id')['trendingScore'].sum()
 
 
 
62
 
63
  # ๋””๋ฒ„๊น…์šฉ ์ถœ๋ ฅ
64
- print("\nID๋ณ„ ํ•ฉ์‚ฐ ์Šค์ฝ”์–ด:")
65
  for id, score in score_sums.sort_values(ascending=False).head(20).items():
66
- print(f"{id}: {score}")
67
 
68
  # ํ•ฉ์‚ฐ๋œ ์Šค์ฝ”์–ด๋กœ ์ •๋ ฌํ•˜์—ฌ ์ƒ์œ„ 20๊ฐœ ์„ ํƒ
69
  top_20_scores = score_sums.sort_values(ascending=False).head(20)
@@ -80,12 +83,17 @@ def create_duplicates_chart(score_sums):
80
  'rank': range(1, len(score_sums) + 1)
81
  })
82
 
 
 
 
 
83
  fig = px.bar(
84
  df,
85
- x='id', # ID๋งŒ ํ‘œ์‹œ
86
  y='rank',
87
  title="Top 20 Spaces by Combined Trending Score",
88
- height=400
 
89
  )
90
 
91
  fig.update_layout(
@@ -95,7 +103,7 @@ def create_duplicates_chart(score_sums):
95
  paper_bgcolor='white',
96
  xaxis_tickangle=-45,
97
  yaxis=dict(
98
- range=[20.5, 0.5], # ์ˆœ์œ„ 1์ด ์œ„์ชฝ์— ์˜ค๋„๋ก
99
  tickmode='linear',
100
  tick0=1,
101
  dtick=1
@@ -104,13 +112,13 @@ def create_duplicates_chart(score_sums):
104
 
105
  fig.update_traces(
106
  marker_color='#4CAF50',
107
- hovertemplate='ID: %{x}<br>Rank: %{y}<br>Total Score: %{customdata:.2f}<extra></extra>',
108
- customdata=df['total_score']
 
109
  )
110
 
111
- # x์ถ• ๋ ˆ์ด๋ธ”์„ ID๋งŒ ํ‘œ์‹œํ•˜๋„๋ก ์„ค์ •
112
  fig.update_xaxes(
113
- title_text="Space ID",
114
  showgrid=True,
115
  gridwidth=1,
116
  gridcolor='lightgray'
 
57
  return None
58
 
59
  def get_duplicate_spaces(top_100_spaces):
60
+ # ID์—์„œ username/spacename ํ˜•์‹์—์„œ username๋งŒ ์ถ”์ถœ
61
+ top_100_spaces['clean_id'] = top_100_spaces['id'].apply(lambda x: x.split('/')[0])
62
+
63
+ # username๋ณ„ trending score ํ•ฉ์‚ฐ
64
+ score_sums = top_100_spaces.groupby('clean_id')['trendingScore'].sum()
65
 
66
  # ๋””๋ฒ„๊น…์šฉ ์ถœ๋ ฅ
67
+ print("\n=== ID๋ณ„ ์Šค์ฝ”์–ด ํ•ฉ์‚ฐ ๊ฒฐ๊ณผ ===")
68
  for id, score in score_sums.sort_values(ascending=False).head(20).items():
69
+ print(f"ID: {id}, Total Score: {score}")
70
 
71
  # ํ•ฉ์‚ฐ๋œ ์Šค์ฝ”์–ด๋กœ ์ •๋ ฌํ•˜์—ฌ ์ƒ์œ„ 20๊ฐœ ์„ ํƒ
72
  top_20_scores = score_sums.sort_values(ascending=False).head(20)
 
83
  'rank': range(1, len(score_sums) + 1)
84
  })
85
 
86
+ # ๋””๋ฒ„๊น…์šฉ ์ถœ๋ ฅ
87
+ print("\n=== ์ฐจํŠธ ๋ฐ์ดํ„ฐ ===")
88
+ print(df)
89
+
90
  fig = px.bar(
91
  df,
92
+ x='id',
93
  y='rank',
94
  title="Top 20 Spaces by Combined Trending Score",
95
+ height=400,
96
+ text='total_score' # ์Šค์ฝ”์–ด ๊ฐ’์„ ๋ฐ” ์œ„์— ํ‘œ์‹œ
97
  )
98
 
99
  fig.update_layout(
 
103
  paper_bgcolor='white',
104
  xaxis_tickangle=-45,
105
  yaxis=dict(
106
+ range=[20.5, 0.5],
107
  tickmode='linear',
108
  tick0=1,
109
  dtick=1
 
112
 
113
  fig.update_traces(
114
  marker_color='#4CAF50',
115
+ texttemplate='%{text:.1f}', # ์Šค์ฝ”์–ด ํฌ๋งท
116
+ textposition='outside',
117
+ hovertemplate='ID: %{x}<br>Rank: %{y}<br>Total Score: %{text:.1f}<extra></extra>'
118
  )
119
 
 
120
  fig.update_xaxes(
121
+ title_text="User ID",
122
  showgrid=True,
123
  gridwidth=1,
124
  gridcolor='lightgray'