File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import matplotlib .pyplot as plt
2+ import os
3+
4+ def generate_statistics_images (stats_data , output_pattern ):
5+ """Generate visualization images from statistics data"""
6+ try :
7+ # Example visualization 1: Period statistics bar chart
8+ periods = list (stats_data ['periodStats' ].keys ())
9+ totals = [v ['total' ] for v in stats_data ['periodStats' ].values ()]
10+ uniques = [v ['unique' ] for v in stats_data ['periodStats' ].values ()]
11+
12+ plt .figure (figsize = (10 , 6 ))
13+ plt .bar (periods , totals , label = 'Total Visits' )
14+ plt .bar (periods , uniques , label = 'Unique Visitors' )
15+ plt .title ('Visitors Statistics' )
16+ plt .legend ()
17+ plt .savefig (output_pattern .format (1 ))
18+ plt .close ()
19+
20+ # Example visualization 2: Pie chart for period distribution
21+ plt .figure (figsize = (8 , 8 ))
22+ plt .pie (totals , labels = periods , autopct = '%1.1f%%' )
23+ plt .title ('Visits Distribution' )
24+ plt .savefig (output_pattern .format (2 ))
25+ plt .close ()
26+
27+ except Exception as e :
28+ print (f"Error generating images: { str (e )} " )
You can’t perform that action at this time.
0 commit comments