openfree commited on
Commit
f5c5f9c
·
verified ·
1 Parent(s): bb83351

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -997,13 +997,18 @@ def refresh_data():
997
 
998
  def create_registration_bar_chart(data, type_name="Spaces"):
999
  try:
 
 
 
1000
  # DataFrame인 경우 처리
1001
  if isinstance(data, pd.DataFrame):
1002
  if type_name == "Models":
1003
  # 3000위 이내의 모델만 필터링
1004
  data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
1005
- # '#' 제거하고 숫자로 변환
1006
- data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= 3000]
 
 
1007
 
1008
  # ID 컬럼 선택
1009
  id_column = 'Space ID' if type_name == "Spaces" else 'Model ID'
@@ -1013,11 +1018,9 @@ def create_registration_bar_chart(data, type_name="Spaces"):
1013
  registrations = {}
1014
  for item in data:
1015
  if isinstance(item, dict):
1016
- # Models의 경우 3000위 이내만 처리
1017
- if type_name == "Models":
1018
- rank = item.get('global_rank')
1019
- if isinstance(rank, str) or rank > 3000:
1020
- continue
1021
  creator = item.get('id', '').split('/')[0]
1022
  registrations[creator] = registrations.get(creator, 0) + 1
1023
  registrations = pd.Series(registrations)
@@ -1034,7 +1037,7 @@ def create_registration_bar_chart(data, type_name="Spaces"):
1034
  )])
1035
 
1036
  fig.update_layout(
1037
- title=f"Korean {type_name} Registrations by Creator (Top 3000)",
1038
  xaxis_title="Creator ID",
1039
  yaxis_title="Number of Registrations",
1040
  showlegend=False,
@@ -1049,25 +1052,30 @@ def create_registration_bar_chart(data, type_name="Spaces"):
1049
 
1050
  def create_pie_chart(data, total_count, type_name="Spaces"):
1051
  try:
 
 
 
1052
  # DataFrame인 경우 처리
1053
  if isinstance(data, pd.DataFrame):
1054
  if type_name == "Models":
1055
  # 3000위 이내의 모델만 필터링
1056
  data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
1057
- data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= 3000]
 
 
 
1058
  korean_count = len(data)
1059
  else:
1060
  # 리스트나 다른 형태의 데이터인 경우 처리
1061
  if type_name == "Models":
1062
- # 3000위 이내의 모델만 카운트
1063
- korean_count = sum(1 for item in data if isinstance(item.get('global_rank'), (int, float)) and item.get('global_rank') <= 3000)
1064
  else:
1065
- korean_count = len(data)
1066
 
1067
  other_count = total_count - korean_count
1068
 
1069
  fig = go.Figure(data=[go.Pie(
1070
- labels=[f'Korean {type_name} in Top 3000', f'Other {type_name} in Top 3000'],
1071
  values=[korean_count, other_count],
1072
  hole=.3,
1073
  marker_colors=['#FF6B6B', '#4ECDC4'],
@@ -1078,7 +1086,7 @@ def create_pie_chart(data, total_count, type_name="Spaces"):
1078
  )])
1079
 
1080
  fig.update_layout(
1081
- title=f"Korean vs Other {type_name} Distribution (Top 3000)",
1082
  showlegend=True,
1083
  height=400,
1084
  width=500
 
997
 
998
  def create_registration_bar_chart(data, type_name="Spaces"):
999
  try:
1000
+ # TOP 기준 설정
1001
+ top_limit = 500 if type_name == "Spaces" else 3000
1002
+
1003
  # DataFrame인 경우 처리
1004
  if isinstance(data, pd.DataFrame):
1005
  if type_name == "Models":
1006
  # 3000위 이내의 모델만 필터링
1007
  data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
1008
+ data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= top_limit]
1009
+ elif type_name == "Spaces":
1010
+ # 500위 이내의 스페이스만 필터링
1011
+ data = data[data['Rank'].apply(lambda x: isinstance(x, (int, float))) & (data['Rank'] <= top_limit)]
1012
 
1013
  # ID 컬럼 선택
1014
  id_column = 'Space ID' if type_name == "Spaces" else 'Model ID'
 
1018
  registrations = {}
1019
  for item in data:
1020
  if isinstance(item, dict):
1021
+ rank = item.get('global_rank' if type_name == "Models" else 'rank')
1022
+ if isinstance(rank, str) or rank > top_limit:
1023
+ continue
 
 
1024
  creator = item.get('id', '').split('/')[0]
1025
  registrations[creator] = registrations.get(creator, 0) + 1
1026
  registrations = pd.Series(registrations)
 
1037
  )])
1038
 
1039
  fig.update_layout(
1040
+ title=f"Korean {type_name} Registrations by Creator (Top {top_limit})",
1041
  xaxis_title="Creator ID",
1042
  yaxis_title="Number of Registrations",
1043
  showlegend=False,
 
1052
 
1053
  def create_pie_chart(data, total_count, type_name="Spaces"):
1054
  try:
1055
+ # TOP 기준 설정
1056
+ top_limit = 500 if type_name == "Spaces" else 3000
1057
+
1058
  # DataFrame인 경우 처리
1059
  if isinstance(data, pd.DataFrame):
1060
  if type_name == "Models":
1061
  # 3000위 이내의 모델만 필터링
1062
  data = data[data['Global Rank'].apply(lambda x: isinstance(x, (int, float)) or (isinstance(x, str) and x.startswith('#')))]
1063
+ data = data[data['Global Rank'].apply(lambda x: int(str(x).replace('#', '')) if isinstance(x, str) else x) <= top_limit]
1064
+ elif type_name == "Spaces":
1065
+ # 500위 이내의 스페이스만 필터링
1066
+ data = data[data['Rank'].apply(lambda x: isinstance(x, (int, float))) & (data['Rank'] <= top_limit)]
1067
  korean_count = len(data)
1068
  else:
1069
  # 리스트나 다른 형태의 데이터인 경우 처리
1070
  if type_name == "Models":
1071
+ korean_count = sum(1 for item in data if isinstance(item.get('global_rank'), (int, float)) and item.get('global_rank') <= top_limit)
 
1072
  else:
1073
+ korean_count = sum(1 for item in data if isinstance(item.get('rank'), (int, float)) and item.get('rank') <= top_limit)
1074
 
1075
  other_count = total_count - korean_count
1076
 
1077
  fig = go.Figure(data=[go.Pie(
1078
+ labels=[f'Korean {type_name} in Top {top_limit}', f'Other {type_name} in Top {top_limit}'],
1079
  values=[korean_count, other_count],
1080
  hole=.3,
1081
  marker_colors=['#FF6B6B', '#4ECDC4'],
 
1086
  )])
1087
 
1088
  fig.update_layout(
1089
+ title=f"Korean vs Other {type_name} Distribution (Top {top_limit})",
1090
  showlegend=True,
1091
  height=400,
1092
  width=500