File size: 3,559 Bytes
9e0b3ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
import seaborn as sns

# Set style
plt.style.use('ggplot')
sns.set(style="whitegrid")

# Load the data
data_path = Path("data.jsonl")
bookmarks = []
with open(data_path, 'r', encoding='utf-8') as f:
    for line in f:
        bookmarks.append(json.loads(line))

# Convert to DataFrame
df = pd.DataFrame(bookmarks)

print(f"Loaded {len(df)} bookmarks")

# Basic statistics
print("\nSource Distribution:")
source_counts = df['source'].value_counts()
print(source_counts)

print("\nTop Domains:")
domain_counts = df['domain'].value_counts().head(20)
print(domain_counts)

# Create output directory for plots
plots_dir = Path("plots")
plots_dir.mkdir(exist_ok=True)

# Source distribution pie chart
plt.figure(figsize=(10, 7))
source_counts.plot.pie(autopct='%1.1f%%', textprops={'fontsize': 10})
plt.title('Bookmark Sources', fontsize=14)
plt.ylabel('')
plt.savefig(plots_dir / 'source_distribution.png', bbox_inches='tight')
plt.close()
print("Created source distribution chart: plots/source_distribution.png")

# Top domains bar chart
plt.figure(figsize=(12, 8))
domain_counts.head(15).plot.barh()
plt.title('Top 15 Domains', fontsize=14)
plt.xlabel('Count')
plt.ylabel('Domain')
plt.tight_layout()
plt.savefig(plots_dir / 'top_domains.png', bbox_inches='tight')
plt.close()
print("Created top domains chart: plots/top_domains.png")

# Bookmarks by month (if date data is available)
if 'created_at' in df.columns:
    try:
        # Convert to datetime if not already
        if not pd.api.types.is_datetime64_any_dtype(df['created_at']):
            df['created_at'] = pd.to_datetime(df['created_at'], errors='coerce')
        
        # Extract year and month
        df['year_month'] = df['created_at'].dt.to_period('M')
        
        # Count bookmarks by month
        monthly_counts = df.groupby('year_month').size()
        
        plt.figure(figsize=(14, 8))
        monthly_counts.plot.bar()
        plt.title('Bookmarks by Month', fontsize=14)
        plt.xlabel('Month')
        plt.ylabel('Count')
        plt.xticks(rotation=45)
        plt.tight_layout()
        plt.savefig(plots_dir / 'bookmarks_by_month.png', bbox_inches='tight')
        plt.close()
        print("Created bookmarks by month chart: plots/bookmarks_by_month.png")
        
        # Bookmarks by source over time
        source_time = pd.crosstab(df['year_month'], df['source'])
        
        plt.figure(figsize=(14, 8))
        source_time.plot.area(alpha=0.6)
        plt.title('Bookmarks by Source Over Time', fontsize=14)
        plt.xlabel('Month')
        plt.ylabel('Count')
        plt.legend(title='Source')
        plt.tight_layout()
        plt.savefig(plots_dir / 'sources_over_time.png', bbox_inches='tight')
        plt.close()
        print("Created sources over time chart: plots/sources_over_time.png")
    except Exception as e:
        print(f"Error creating time-based charts: {e}")

# Content length distribution
if 'content_length' in df.columns:
    plt.figure(figsize=(12, 8))
    sns.histplot(df['content_length'].clip(upper=5000), bins=50)
    plt.title('Content Length Distribution (clipped at 5000 chars)', fontsize=14)
    plt.xlabel('Content Length (characters)')
    plt.ylabel('Count')
    plt.tight_layout()
    plt.savefig(plots_dir / 'content_length.png', bbox_inches='tight')
    plt.close()
    print("Created content length distribution: plots/content_length.png")

print("\nAnalysis complete. Check the 'plots' directory for visualizations.")