다음 demo_class_variables()를 살펴보거나 모듈을 직접 보면서 스트립트를 이해해볼 것
from media_classes import demo_class_variablesdemo_class_variables()
============================================================
🎬 클래스 변수 활용 데모
============================================================
1️⃣ 영화 생성...
📊 총 생성된 영화: 3개
📊 총 러닝타임: 479분
2️⃣ 전체 통계:
총 영화 수: 3
총 러닝타임: 479분 (8.0시간)
평균 러닝타임: 159.7분
총 감독 수: 2
3️⃣ Christopher Nolan의 영화:
- Inception (148분)
- Interstellar (169분)
4️⃣ TOP 감독 (영화 개수 기준):
Christopher Nolan: 2편 (평가 2개)
James Cameron: 1편 (평가 1개)
4️⃣-2 TOP 감독 (평가 개수 기준):
Christopher Nolan: 2개 평가 (2편)
James Cameron: 1개 평가 (1편)
5️⃣ 개별 영화 정보:
[영화 1] Inception (2010)
감독: Christopher Nolan ⭐ | 장르: ['Sci-Fi & Fantasy']
러닝타임: 2시간 28분 (일반 장편)
카테고리: 일반 장편
유명 감독 여부: 예
이 감독의 총 영화 수: 2편
이 감독 영화의 평가 수: 2개
6️⃣ ID로 영화 검색 (O(1) 시간):
찾은 영화: Interstellar
============================================================
### JSON 파일에서 데이터 로드# ViewingAnalyzer 객체 생성analyzer_netflix = ViewingAnalyzer()analyzer_netflix.load_from_json('data/netflix_ratings_titles.json')
data/netflix_ratings_titles_2.json 로드 중...
사용자에 의해 중단됨. 0개까지 로드됨.
m1 = analyzer_netflix.records[0] # 첫 번째 레코드print(m1.media.title)print(m1.media.genre)print(m1.media.director)print(m1.media.release_year)print(m1.media.runtime)print(m1.rating)print(m1.watch_date)
50 First Dates
['Comedies', 'Romantic Movies']
Peter Segal
2004
99
4
2004-06-23 00:00:00
2. 기본 통계
print("기본 통계")print("-"*60)total_records = analyzer_netflix.get_total_count()viewer_count = analyzer_netflix.get_viewer_count()unique_media = analyzer_netflix.get_unique_media_count()total_hours = analyzer_netflix.get_total_watch_time()avg_rating = analyzer_netflix.get_average_rating()print(f"총 시청 기록 수: {total_records}개")print(f"총 시청자 수: {viewer_count}명")print(f"고유 작품 수: {unique_media}개")print(f"총 시청 시간: {total_hours:.1f}시간")print(f"전체 평균 평점: {avg_rating:.2f}/10")
기본 통계
------------------------------------------------------------
총 시청 기록 수: 1246558개
총 시청자 수: 316804명
고유 작품 수: 94개
총 시청 시간: 2391943.3시간
전체 평균 평점: 3.59/10
4. 시청자 분석
# 가장 활발한 시청자 TOP 5print("가장 활발한 시청자 TOP 5")print("-"*60)top_viewers = analyzer_netflix.get_most_active_viewers(n=5)for i, (viewer_id, count) inenumerate(top_viewers, 1):print(f"{i}. {viewer_id}: {count}회 시청")
가장 활발한 시청자 TOP 5
------------------------------------------------------------
1. 387418: 45회 시청
2. 305344: 43회 시청
3. 1664010: 43회 시청
4. 2439493: 40회 시청
5. 2606799: 38회 시청
# 시청자별 통계viewer_stats = analyzer_netflix.get_viewer_statistics()print("시청자별 통계")print("-"*60)for viewer_id insorted(list(analyzer_netflix.viewers))[:5]: # id 순으로 처음 5명 stats = viewer_stats[viewer_id]print(f"\n[{viewer_id}]")print(f" 시청 횟수: {stats['count']}회")print(f" 평균 평점: {stats['avg_rating']:.2f}/10")
시청자별 통계
------------------------------------------------------------
[6]
시청 횟수: 8회
평균 평점: 3.25/10
[7]
시청 횟수: 14회
평균 평점: 4.07/10
[8]
시청 횟수: 1회
평균 평점: 4.00/10
[10]
시청 횟수: 1회
평균 평점: 4.00/10
[59]
시청 횟수: 1회
평균 평점: 4.00/10
5. 작품별 분석
# 작품별 평균 평점 TOP 10print("평균 평점 TOP 10 작품 (최소 3명 이상 평가)")print("-"*60)top_media = analyzer_netflix.get_top_rated_media(n=10, min_ratings=3)for i, (title, stats) inenumerate(top_media, 1):print(f"{i:2d}. {title:30s}")print(f" 평균 평점: {stats['avg_rating']:.2f}/10 ({stats['rating_count']}명 평가)")
평균 평점 TOP 10 작품 (최소 3명 이상 평가)
------------------------------------------------------------
1. Kabhi Khushi Kabhie Gham
평균 평점: 4.24/10 (97명 평가)
2. The Pianist
평균 평점: 4.12/10 (30497명 평가)
3. Coach Carter
평균 평점: 4.07/10 (30022명 평가)
4. Kuch Kuch Hota Hai
평균 평점: 4.00/10 (271명 평가)
5. Doctor Zhivago
평균 평점: 3.98/10 (8810명 평가)
6. Like Water for Chocolate
평균 평점: 3.97/10 (13459명 평가)
7. American Beauty
평균 평점: 3.96/10 (77407명 평가)
8. Lock, Stock and Two Smoking Barrels
평균 평점: 3.93/10 (19899명 평가)
9. Charlotte's Web
평균 평점: 3.92/10 (13693명 평가)
10. Jaws
평균 평점: 3.88/10 (40425명 평가)
6. 장르 분석
# 장르별 통계genre_stats = analyzer_netflix.get_genre_statistics()print("장르별 통계")print("-"*60)for genre, stats insorted(genre_stats.items(), key=lambda x: x[1]['count'], reverse=True):print(f"\n{genre}:")print(f" 시청 횟수: {stats['count']}회")print(f" 평균 평점: {stats['avg_rating']:.2f}/10")print(f" 시청자 수: {stats['viewer_count']}명")print(f" 총 시청 시간: {stats['total_time']:.1f}시간")
장르별 통계
------------------------------------------------------------
Comedies:
시청 횟수: 606749회
평균 평점: 3.51/10
시청자 수: 243514명
총 시청 시간: 1083382.5시간
Action & Adventure:
시청 횟수: 466348회
평균 평점: 3.52/10
시청자 수: 217876명
총 시청 시간: 912268.1시간
Dramas:
시청 횟수: 428928회
평균 평점: 3.75/10
시청자 수: 200592명
총 시청 시간: 874892.6시간
Romantic Movies:
시청 횟수: 177952회
평균 평점: 3.75/10
시청자 수: 135434명
총 시청 시간: 346078.2시간
Classic Movies:
시청 횟수: 140472회
평균 평점: 3.78/10
시청자 수: 92404명
총 시청 시간: 290234.0시간
Thrillers:
시청 횟수: 133365회
평균 평점: 3.55/10
시청자 수: 89527명
총 시청 시간: 271388.8시간
Sci-Fi & Fantasy:
시청 횟수: 118804회
평균 평점: 3.37/10
시청자 수: 93728명
총 시청 시간: 189557.4시간
International Movies:
시청 횟수: 107332회
평균 평점: 3.81/10
시청자 수: 81710명
총 시청 시간: 214808.6시간
Children & Family Movies:
시청 횟수: 106728회
평균 평점: 3.32/10
시청자 수: 69248명
총 시청 시간: 163799.9시간
Independent Movies:
시청 횟수: 70433회
평균 평점: 3.91/10
시청자 수: 59585명
총 시청 시간: 148643.2시간
Cult Movies:
시청 횟수: 67761회
평균 평점: 3.44/10
시청자 수: 52388명
총 시청 시간: 126475.5시간
Sports Movies:
시청 횟수: 49586회
평균 평점: 3.82/10
시청자 수: 45149명
총 시청 시간: 104607.1시간
Horror Movies:
시청 횟수: 35768회
평균 평점: 3.46/10
시청자 수: 32264명
총 시청 시간: 70349.4시간
Documentaries:
시청 횟수: 2004회
평균 평점: 2.98/10
시청자 수: 1943명
총 시청 시간: 3369.2시간
Music & Musicals:
시청 횟수: 2004회
평균 평점: 2.98/10
시청자 수: 1943명
총 시청 시간: 3369.2시간
TV Dramas:
시청 횟수: 731회
평균 평점: 3.76/10
시청자 수: 731명
총 시청 시간: 0.0시간
Anime Series:
시청 횟수: 126회
평균 평점: 3.63/10
시청자 수: 126명
총 시청 시간: 0.0시간
Kids' TV:
시청 횟수: 126회
평균 평점: 3.63/10
시청자 수: 126명
총 시청 시간: 0.0시간
# 장르 분포 시각화plot_genre_distribution(genre_stats)
============================================================
📊 장르별 시청 분포 (텍스트 차트)
============================================================
Comedies ████████████ 606749회 (24.1%)
Action & Adventure █████████ 466348회 (18.5%)
Dramas ████████ 428928회 (17.1%)
Romantic Movies ███ 177952회 (7.1%)
Classic Movies ██ 140472회 (5.6%)
Thrillers ██ 133365회 (5.3%)
Sci-Fi & Fantasy ██ 118804회 (4.7%)
International Movies ██ 107332회 (4.3%)
Children & Family Movies ██ 106728회 (4.2%)
Independent Movies █ 70433회 (2.8%)
Cult Movies █ 67761회 (2.7%)
Sports Movies 49586회 (2.0%)
Horror Movies 35768회 (1.4%)
Documentaries 2004회 (0.1%)
Music & Musicals 2004회 (0.1%)
TV Dramas 731회 (0.0%)
Anime Series 126회 (0.0%)
Kids' TV 126회 (0.0%)
7. 시간대 분석
# 월별 시청 추이monthly_stats = analyzer_netflix.get_monthly_statistics()plot_monthly_trend(monthly_stats)
# 종합 리포트 생성report = analyzer_netflix.generate_summary_report()print(report)
============================================================
📊 시청 기록 종합 리포트
============================================================
총 시청 기록 수: 1246558개
총 시청자 수: 316804명
고유 작품 수: 94개
총 시청 시간: 2391943.3시간
전체 평균 평점: 3.59/10
가장 인기 있는 장르: Comedies
🏆 평균 평점이 가장 높은 TOP 3 작품:
1. Kabhi Khushi Kabhie Gham (평균: 4.24/10, 97명 평가)
2. The Pianist (평균: 4.12/10, 30497명 평가)
3. Coach Carter (평균: 4.07/10, 30022명 평가)