-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata-analysis-script-debug.py
More file actions
59 lines (50 loc) · 2.1 KB
/
data-analysis-script-debug.py
File metadata and controls
59 lines (50 loc) · 2.1 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
import csv
from collections import defaultdict
from datetime import datetime
def analyze_data(file_path):
daily_metrics = defaultdict(lambda: {"new_contacts": 0, "emails_sent": 0, "responses_received": 0})
sequences = defaultdict(lambda: {"sent": 0, "replies": 0})
stages = defaultdict(int)
total_emails = 0
total_responses = 0
with open(file_path, 'r') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
sent_at = row['Sent At (PST)']
try:
date = datetime.strptime(sent_at, '%B %d, %Y %H:%M').date()
except ValueError:
print(f"Error parsing date: {sent_at}")
continue
print(f"Processing row: Date = {date}, To Email = {row['To Email']}, From Email = {row['From Email']}")
# Daily metrics
daily_metrics[date]['emails_sent'] += 1
if row['From Email'] == 'ryan@trunk.io':
total_emails += 1
if not row['Sequence']: # Assuming new contacts don't have a sequence
daily_metrics[date]['new_contacts'] += 1
if row['Replied'] == 'true':
daily_metrics[date]['responses_received'] += 1
total_responses += 1
# Sequence performance
if row['Sequence']:
sequences[row['Sequence']]['sent'] += 1
if row['Replied'] == 'true':
sequences[row['Sequence']]['replies'] += 1
# Contact stages
stages[row['Contact Stage']] += 1
print("\nDaily Metrics:")
for date, metrics in daily_metrics.items():
print(f"{date}: {metrics}")
return {
'daily_metrics': dict(daily_metrics),
'sequences': dict(sequences),
'stages': dict(stages),
'total_emails': total_emails,
'total_responses': total_responses,
'reply_rate': (total_responses / total_emails) * 100 if total_emails > 0 else 0
}
# Usage
results = analyze_data('week of 8.26.24.apollo-messages-export.csv')
print("\nFinal Results:")
print(results)