-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday02_PIPELINE_data_analysis.py
More file actions
169 lines (133 loc) Β· 5.96 KB
/
day02_PIPELINE_data_analysis.py
File metadata and controls
169 lines (133 loc) Β· 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
"""
Synthetic Data Pipeline for Day 02 - Creator Intelligence System
Analyzes pre-loaded synthetic data (no API connection required)
"""
import sys
from datetime import datetime
# Import project modules
from src.data_manager import DataManager
from src.audience_segmentation import AudienceAnalyzer
from src import config
def print_banner():
"""Print pipeline banner"""
print("\n" + "=" * 50)
print("PROJECT 1B: CREATOR INTELLIGENCE - SYNTHETIC DATA ANALYSIS")
print("=" * 50 + "\n")
def print_summary(
growth_metrics: dict,
engagement_stats: dict,
insights: dict,
db_summary: dict
):
"""Print final summary"""
print("\n" + "=" * 50)
print("ANALYSIS COMPLETE - SUMMARY")
print("=" * 50)
# Account Growth
print("\nπ Account Growth:")
print(f" Current Followers: {growth_metrics['current_followers']:,}")
print(f" Weekly Growth Rate: {growth_metrics['weekly_growth_rate']}%")
status = "β ON TRACK" if growth_metrics['on_track'] else "β οΈ BELOW TARGET"
print(f" Target Rate: {growth_metrics['target_rate']}% {status}")
print(f" 90-Day Total Reach: {growth_metrics['total_reach_90d']:,}")
# Engagement
print("\nπ Engagement:")
print(f" Average Engagement Rate: {engagement_stats['avg_engagement_rate']}%")
print(f" Total Posts Analyzed: {engagement_stats['total_posts']}")
print(f" Max Engagement: {engagement_stats['max_engagement_rate']}%")
print(f" Min Engagement: {engagement_stats['min_engagement_rate']}%")
# Content Intelligence
print("\nβ Content Intelligence:")
if insights['best_posting_times']['hours']:
hours = insights['best_posting_times']['hours']
print(f" Best Hours to Post: {hours}")
if insights['best_posting_times']['days']:
days = insights['best_posting_times']['days']
print(f" Best Days to Post: {days}")
print(f" Viral Posts (>2x avg): {insights['viral_posts_count']}")
# Engagement Trend
trend = insights['engagement_trend']
if trend['trend'] == 'improving':
print(f" Trend: π Improving (+{trend['change_pct']}%)")
elif trend['trend'] == 'declining':
print(f" Trend: π Declining ({trend['change_pct']}%)")
else:
print(f" Trend: β‘οΈ Stable")
# Content Type Performance
if insights['content_type_performance']:
print("\n㪠Content Type Performance:")
for media_type, stats in insights['content_type_performance'].items():
print(f" {media_type}:")
print(f" Avg Engagement: {stats['avg_engagement_rate']:.2f}%")
print(f" Posts: {stats['count']}")
print(f" Avg Reach: {stats['avg_reach']:,.0f}")
# Data Storage
print("\nπΎ Data Storage:")
print(f" Database: {config.DB_PATH}")
print(f" Account Metrics: {db_summary['account_metrics_count']} days")
print(f" Posts Analyzed: {db_summary['posts_count']}")
print("\n" + "=" * 50)
print("β
Hour 1 Complete - Ready for Hour 2 (LTV Analysis)")
print("=" * 50 + "\n")
def main():
"""Main pipeline execution for synthetic data"""
try:
print_banner()
# Initialize components (no API extractor needed)
print("Initializing components...")
data_manager = DataManager()
analyzer = AudienceAnalyzer(data_manager)
# Check if data exists in database
print("\nChecking database...")
db_summary = data_manager.get_database_summary()
if db_summary['account_metrics_count'] == 0 or db_summary['posts_count'] == 0:
print("\nβ No data found in database!")
print("\nπ‘ Please run: python experimental/day02_PIPELINE_synthetic_data_loader.py")
print(" to load the synthetic data first.\n")
sys.exit(1)
print(f" β Found {db_summary['account_metrics_count']} days of account metrics")
print(f" β Found {db_summary['posts_count']} posts")
# Step 1: Calculate growth metrics
print("\n1. Calculating growth metrics...")
growth_metrics = data_manager.get_growth_metrics()
print(" β Growth analysis complete")
# Step 2: Get engagement stats
print("\n2. Analyzing engagement statistics...")
engagement_stats = data_manager.get_engagement_stats()
print(" β Engagement analysis complete")
# Step 3: Perform audience segmentation and analysis
print("\n3. Performing audience segmentation...")
insights = analyzer.generate_insights_summary()
# Print comprehensive summary
print_summary(growth_metrics, engagement_stats, insights, db_summary)
# Print actionable recommendations
print("\nπ‘ Actionable Recommendations:")
recommendations = analyzer.get_actionable_recommendations()
for rec in recommendations:
print(f" β’ {rec}")
# Print top posts
print("\n" + "=" * 50)
print("π TOP 10 PERFORMING POSTS")
print("=" * 50)
top_posts = analyzer.get_top_posts(10)
if not top_posts.empty:
for idx, post in top_posts.iterrows():
print(f"\n#{idx + 1} - {post['media_type']}")
caption_preview = post['caption'][:80] + "..." if len(post['caption']) > 80 else post['caption']
print(f" Caption: {caption_preview}")
print(f" Engagement: {post['engagement_rate']:.2f}%")
print(f" Likes: {post['likes']:,} | Comments: {post['comments']:,} | Saves: {post['saves']:,}")
print(f" Reach: {post['reach']:,}")
print("\n" + "=" * 50)
return 0
except KeyboardInterrupt:
print("\n\nβ οΈ Pipeline interrupted by user")
return 1
except Exception as e:
print(f"\n\nβ Pipeline failed with error: {e}")
import traceback
traceback.print_exc()
return 1
if __name__ == "__main__":
exit_code = main()
sys.exit(exit_code)