사용하지 않는 코드 정리 및 전송 데이터 포멧팅 변경

This commit is contained in:
skkim committed 2026-02-26 09:17:35 +09:00
1 parent a0c352f567
commit cb267192d2
5 files changed
+137 -208

No files matched your search

+66 -105
View File
@@ -22,10 +22,10 @@ def to_camel(string: str) -> str:
"""snake_case를 camelCase로 변환
Args:
string: snake_case 문자열 (예: "label_en")
string: snake_case 문자열 (예: "content_metrics")
Returns:
camelCase 문자열 (예: "labelEn")
camelCase 문자열 (예: "contentMetrics")
Example:
>>> to_camel("content_metrics")
@@ -43,28 +43,31 @@ class ContentMetric(BaseModel):
대시보드 상단에 표시되는 핵심 성과 지표(KPI) 카드입니다.
Attributes:
id: 지표 고유 ID (예: "total-views", "total-engagement")
label: 한글 라벨 (예: "총 조회수")
label_en: 영문 라벨 (예: "Total Views")
value: 포맷팅된 값 (예: "1.2M", "8.2%")
trend: 증감 추세 값 (예: 12.5 → 12.5% 증가)
trend_direction: 추세 방향 ("up" 또는 "down")
id: 지표 고유 ID (예: "total-views", "total-watch-time", "new-subscribers")
label: 한글 라벨 (예: "조회수")
value: 원시 숫자값 (단위: unit 참조, 포맷팅은 프론트에서 처리)
unit: 값의 단위 — "count" | "hours" | "minutes"
- count: 조회수, 구독자, 좋아요, 댓글, 공유, 업로드 영상
- hours: 시청시간 (estimatedMinutesWatched / 60)
- minutes: 평균 시청시간 (averageViewDuration / 60)
trend: 이전 기간 대비 증감량 (unit과 동일한 단위)
trend_direction: 증감 방향 ("up": 증가, "down": 감소, "-": 변동 없음)
Example:
>>> metric = ContentMetric(
... id="total-views",
... label="총 조회수",
... label_en="Total Views",
... value="1.2M",
... trend=12.5,
... label="조회수",
... value=1200000.0,
... unit="count",
... trend=3800.0,
... trend_direction="up"
... )
"""
id: str
label: str
label_en: str
value: str
value: float
unit: str = "count"
trend: float
trend_direction: Literal["up", "down", "-"] = Field(alias="trendDirection")
@@ -133,7 +136,7 @@ class TopContent(BaseModel):
title: 영상 제목
thumbnail: 썸네일 이미지 URL
platform: 플랫폼 ("youtube" 또는 "instagram")
views: 포맷팅된 조회수 (예: "125K")
views: 원시 조회수 정수 (포맷팅은 프론트에서 처리, 예: 125400)
engagement: 참여율 (예: "8.2%")
date: 업로드 날짜 (예: "2026.01.15")
@@ -143,7 +146,7 @@ class TopContent(BaseModel):
... title="힐링 영상",
... thumbnail="https://i.ytimg.com/...",
... platform="youtube",
... views="125K",
... views=125400,
... engagement="8.2%",
... date="2026.01.15"
... )
@@ -153,7 +156,7 @@ class TopContent(BaseModel):
title: str
thumbnail: str
platform: Literal["youtube", "instagram"]
views: str
views: int
engagement: str
date: str
@@ -169,18 +172,18 @@ class AudienceData(BaseModel):
시청자의 연령대, 성별, 지역 분포 데이터입니다.
Attributes:
age_groups: 연령대별 비율 리스트
age_groups: 연령대별 시청자 비율 리스트
[{"label": "18-24", "percentage": 35}, ...]
gender: 성별 조회수
{"male": 45000, "female": 55000}
top_regions: 상위 지역 리스트
[{"region": "서울", "percentage": 42}, ...]
gender: 성별 시청자 비율 (YouTube viewerPercentage 누적값)
{"male": 45, "female": 55}
top_regions: 상위 국가 리스트 (최대 5개)
[{"region": "대한민국", "percentage": 42}, ...]
Example:
>>> data = AudienceData(
... age_groups=[{"label": "18-24", "percentage": 35}],
... gender={"male": 45, "female": 55},
... top_regions=[{"region": "서울", "percentage": 42}]
... top_regions=[{"region": "대한민국", "percentage": 42}]
... )
"""
@@ -194,90 +197,47 @@ class AudienceData(BaseModel):
)
class PlatformMetric(BaseModel):
"""플랫폼별 메트릭
플랫폼별 세부 지표입니다 (예: 구독자 증가, 구독 취소).
Attributes:
id: 메트릭 고유 ID (예: "subscribers-gained")
label: 지표명 (예: "구독자 증가")
value: 포맷팅된 값 (예: "1.2K")
unit: 단위 (선택, 예: "명", "%")
trend: 증감 추세 값
trend_direction: 추세 방향 ("up" 또는 "down")
Example:
>>> metric = PlatformMetric(
... id="subscribers-gained",
... label="구독자 증가",
... value="1.2K",
... trend=8.5,
... trend_direction="up"
... )
"""
id: str
label: str
value: str
unit: Optional[str] = None
trend: float
trend_direction: Literal["up", "down", "-"] = Field(alias="trendDirection")
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True,
)
class PlatformData(BaseModel):
"""플랫폼별 데이터
플랫폼별로 그룹화된 메트릭 데이터입니다.
Attributes:
platform: 플랫폼 종류 ("youtube" 또는 "instagram")
display_name: 표시할 플랫폼 이름 (예: "YouTube")
metrics: 플랫폼별 메트릭 리스트
Example:
>>> data = PlatformData(
... platform="youtube",
... display_name="YouTube",
... metrics=[
... PlatformMetric(
... id="subscribers",
... label="구독자 증가",
... value="1.2K",
... trend=8.5,
... trend_direction="up"
... )
... ]
... )
"""
platform: Literal["youtube", "instagram"]
display_name: str = Field(alias="displayName")
metrics: list[PlatformMetric]
model_config = ConfigDict(
alias_generator=to_camel,
populate_by_name=True,
)
# class PlatformMetric(BaseModel):
# """플랫폼별 메트릭 (미사용 — platform_data 기능 미구현)"""
#
# id: str
# label: str
# value: str
# unit: Optional[str] = None
# trend: float
# trend_direction: Literal["up", "down", "-"] = Field(alias="trendDirection")
#
# model_config = ConfigDict(
# alias_generator=to_camel,
# populate_by_name=True,
# )
#
#
# class PlatformData(BaseModel):
# """플랫폼별 데이터 (미사용 — platform_data 기능 미구현)"""
#
# platform: Literal["youtube", "instagram"]
# display_name: str = Field(alias="displayName")
# metrics: list[PlatformMetric]
#
# model_config = ConfigDict(
# alias_generator=to_camel,
# populate_by_name=True,
# )
class DashboardResponse(BaseModel):
"""대시보드 전체 응답
GET /api/dashboard/stats 엔드포인트의 전체 응답 스키마입니다.
모든 대시보드 데이터를 포함합니다.
GET /dashboard/stats 엔드포인트의 전체 응답 스키마입니다.
Attributes:
content_metrics: KPI 지표 카드 리스트
monthly_data: 월별 추이 데이터 (전년 대비)
top_content: 인기 영상 리스트
audience_data: 시청자 분석 데이터
platform_data: 플랫폼별 메트릭 데이터
content_metrics: KPI 지표 카드 리스트 (8개)
monthly_data: 월별 추이 데이터 (mode=month 시 채움, 최근 12개월 vs 이전 12개월)
daily_data: 일별 추이 데이터 (mode=day 시 채움, 최근 30일 vs 이전 30일)
top_content: 조회수 기준 인기 영상 TOP 4
audience_data: 시청자 분석 데이터 (연령/성별/지역)
has_uploads: 업로드 영상 존재 여부 (False 시 모든 지표가 0, 빈 상태 UI 표시용)
Example:
>>> response = DashboardResponse(
@@ -285,7 +245,6 @@ class DashboardResponse(BaseModel):
... monthly_data=[...],
... top_content=[...],
... audience_data=AudienceData(...),
... platform_data=[...]
... )
>>> json_str = response.model_dump_json() # JSON 직렬화
"""
@@ -295,7 +254,8 @@ class DashboardResponse(BaseModel):
daily_data: list[DailyData] = Field(default=[], alias="dailyData")
top_content: list[TopContent] = Field(alias="topContent")
audience_data: AudienceData = Field(alias="audienceData")
platform_data: list[PlatformData] = Field(default=[], alias="platformData")
has_uploads: bool = Field(default=True, alias="hasUploads")
# platform_data: list[PlatformData] = Field(default=[], alias="platformData") # 미사용
model_config = ConfigDict(
alias_generator=to_camel,
@@ -307,11 +267,12 @@ class ConnectedAccount(BaseModel):
"""연결된 소셜 계정 정보
Attributes:
id: SocialAccount 테이블 ID (계정 선택 시 이 값을 social_account_id로 전달)
id: SocialAccount 테이블 PK
platform: 플랫폼 (예: "youtube")
platform_username: 플랫폼 사용자명 (예: "@channelname")
platform_user_id: 플랫폼 사용자 고유 ID
channel_title: YouTube 채널 제목 (platform_data에서 추출)
platform_user_id: 플랫폼 채널 고유 ID — 재연동해도 불변.
/dashboard/stats?platform_user_id=<값> 으로 계정 선택에 사용
channel_title: YouTube 채널 제목 (SocialAccount.platform_data JSON에서 추출)
connected_at: 연동 일시
is_active: 활성화 상태
"""