References
Analytics
The analytics module provides a facade class for analyzing calendar events and generating charts. The module uses a CalendarDataCollector to retrieve events from the Google Calendar API and a DataTransformer to transform the data into the format required by the plotting functions. The plotting is done by creating instances of PlotFactory.
The AnalyzerFacade class provides three methods for analyzing events: analyze_one
,
analyze_many
, and analyze_one_with_periods
. The analyze_one
method analyzes a single
event, the analyze_many method analyzes multiple events, and the analyze_one_with_periods
method analyzes a single event over a period of time.
The AnalyzerBuilder class is a builder class that allows for creating instances of the AnalyzerFacade class with different options.
AnalyzerFacade
Facade class for analyzing calendar events and generating charts.
The class provides three methods for analyzing events:
analyze_one
, 'analyze_many', and 'analyze_one_with_periods'.
It uses a CalendarDataCollector to retrieve events from Google Calendar API and a DataTransformer
to transform the data into the format required by the plotting functions. The plotting is done by
creating instances of PlotFactory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
creds |
Credentials
|
Google credentials class instance. |
required |
Attributes:
Name | Type | Description |
---|---|---|
creds |
Credentials
|
An instance of the Credentials class. |
plot_type |
str
|
The type of chart to be generated. |
max_events |
int
|
The maximum number of events to be analyzed. |
ascending |
bool
|
If True, sort the events in ascending order of duration. |
data_collector |
AsyncCalendarDataCollector
|
An instance of the CalendarDataCollector class. |
Examples:
# Initialize AnalyzerFacade and analyze a single event
analyzer = AnalyzerBuilder().with_credentials(creds).build()
start_time = datetime(2023, 3, 1, tzinfo=pytz.UTC)
end_time = datetime(2023, 3, 18, tzinfo=pytz.UTC)
event_name = "Meeting"
plot = await analyzer.analyze_one(start_time, end_time, event_name)
# Initialize AnalyzerFacade and analyze multiple events
analyzer = AnalyzerBuilder().with_credentials(creds).build()
start_time = datetime(2023, 3, 1, 0, 0, 0)
end_time = datetime(2023, 3, 31, 23, 59, 59)
fig = await analyzer.analyze_many(start_time=start_time, end_time=end_time)
fig.show()
# Initialize AnalyzerFacade and analyze a single event over a period of time
analyzer = AnalyzerBuilder().with_credentials(creds).build()
start_time = datetime(2023, 3, 1, tzinfo=pytz.UTC)
end_time = datetime(2023, 3, 31, tzinfo=pytz.UTC)
event_name = "Meeting"
period_days = 7
num_periods = 2
plot = await analyzer.analyze_one_with_periods(
start_time=start_time,
end_time=end_time,
event_name=event_name,
period_days=period_days,
num_periods=num_periods,
)
Source code in google_calendar_analytics/analytics.py
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 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
analyze_many(start_time, end_time, plot_type, max_events=5, ascending=False, style_class=base_plot_design, **kwargs)
async
Analyze multiple calendar events and generate a plot of their durations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time |
datetime
|
The start time for the analysis. |
required |
end_time |
datetime
|
The end time for the analysis. |
required |
plot_type |
str
|
The type of plot to generate. |
required |
max_events |
int
|
The maximum number of events to analyze. |
5
|
ascending |
bool
|
If True, sort the events in ascending order of duration. |
False
|
style_class |
Type[VisualDesign]
|
The class that defines the style of the plot. |
base_plot_design
|
**kwargs |
Additional keyword arguments for the plot creation. |
{}
|
Returns:
Type | Description |
---|---|
go.Figure
|
go.Figure: The plot generated by the PlotFactory. |
Examples:
analyzer = AnalyzerBuilder().with_credentials(creds).build()
start_time = datetime(2023, 3, 1, 0, 0, 0)
end_time = datetime(2023, 3, 31, 23, 59, 59)
fig = await analyzer.analyze_many(start_time=start_time, end_time=end_time)
fig.show()
Source code in google_calendar_analytics/analytics.py
analyze_one(start_time, end_time, event_name, plot_type, style_class=base_plot_design, **kwargs)
async
Analyze a single event and generate a plot.
This method analyzes a single event from the specified start time to end time and generates a plot using the OneEventDurationStrategy. The method uses a CalendarDataCollector to retrieve events from the Google Calendar API, a DataTransformer to transform the data into the required format, and a PlotFactory to generate the plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time |
datetime
|
The start time for the analysis. |
required |
end_time |
datetime
|
The end time for the analysis. |
required |
event_name |
str
|
The name of the event to analyze. |
required |
plot_type |
str
|
The type of plot to generate. |
required |
style_class |
Type[VisualDesign]
|
The class that defines the style of the plot. |
base_plot_design
|
**kwargs |
Additional keyword arguments for the plot creation. |
{}
|
Returns:
Type | Description |
---|---|
go.Figure
|
go.Figure: The plot generated by the PlotFactory. |
Examples:
To analyze a single event from March 1, 2023 to March 18, 2023 with the name "Meeting" and generate a plot, use:
analyzer = AnalyzerBuilder().with_credentials(creds).build()
start_time = datetime(2023, 3, 1, tzinfo=pytz.UTC)
end_time = datetime(2023, 3, 18, tzinfo=pytz.UTC)
event_name = "Meeting"
plot = await analyzer.analyze_one(start_time, end_time, event_name)
Source code in google_calendar_analytics/analytics.py
analyze_one_with_periods(start_time, end_time, event_name, plot_type, period_days=7, num_periods=2, style_class=base_plot_design, **kwargs)
async
Analyze a single event over multiple periods of time and generate a plot.
This method analyzes a single event from the specified start time to end time over multiple periods of time using the EventDurationPeriodsStrategy. The method uses a CalendarDataCollector to retrieve events from the Google Calendar API, a DataTransformer to transform the data into the required format, and a PlotFactory to generate the plot.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time |
datetime
|
The start time for the analysis. |
required |
end_time |
datetime
|
The end time for the analysis. |
required |
event_name |
str
|
The name of the event to analyze. |
required |
period_days |
int
|
The number of days in each period. Defaults to 7. |
7
|
num_periods |
int
|
The number of periods to analyze. Defaults to 2. |
2
|
plot_type |
str
|
The type of plot to generate. |
required |
style_class |
Type[VisualDesign]
|
The class that defines the style of the plot. |
base_plot_design
|
**kwargs |
Additional keyword arguments for the plot creation. |
{}
|
Returns:
Type | Description |
---|---|
go.Figure
|
go.Figure: The plot generated by the PlotFactory. |
Examples:
To analyze a single event named "Meeting" from March 1, 2023 to March 31, 2023 over two periods of 7 days and generate a plot, use:
analyzer = AnalyzerBuilder().with_credentials(creds).build()
start_time = datetime(2023, 3, 1, tzinfo=pytz.UTC)
end_time = datetime(2023, 3, 31, tzinfo=pytz.UTC)
event_name = "Meeting"
period_days = 7
num_periods = 2
plot = await analyzer.analyze_one_with_periods(start_time, end_time, event_name, period_days, num_periods)
Source code in google_calendar_analytics/analytics.py
VisualizerFactory
This module provides classes for generating visualizations of event data using Pandas and Plotly libraries. It includes classes for bar charts, pie charts, and line charts of event durations, as well as multiple line charts for events over multiple periods. The Plot class defines some common properties for all visualization classes, while the ManyEventPlot and OneEventPlot classes define required abstract methods. The factory method PlotFactory returns an object of the specified visualization class based on input parameters.
BarPlot
Bases: ManyEventPlot
Source code in google_calendar_analytics/visualization/visualizer_factory.py
plot(events, title='Top events with the Longest Duration', **kwargs)
async
Plot a bar chart of the event durations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events |
pd.DataFrame
|
A DataFrame containing the event names as the index and the event durations as values. |
required |
title |
str
|
The title of the chart. |
'Top events with the Longest Duration'
|
Source code in google_calendar_analytics/visualization/visualizer_factory.py
LinePlot
Bases: OneEventPlot
Source code in google_calendar_analytics/visualization/visualizer_factory.py
plot(events, event_name, **kwargs)
async
Plot a line chart of the event durations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events |
pd.DataFrame
|
A DataFrame containing the event dates as the index and the event durations as the values. |
required |
event_name |
str
|
The name of the event. |
required |
Source code in google_calendar_analytics/visualization/visualizer_factory.py
ManyEventPlot
Bases: Plot
Source code in google_calendar_analytics/visualization/visualizer_factory.py
plot(events, title='Title')
abstractmethod
async
MultyLinePlot
Bases: OneEventPlot
Source code in google_calendar_analytics/visualization/visualizer_factory.py
plot(events, event_name, **kwargs)
async
Plot a line chart of the event durations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events |
pd.DataFrame
|
A DataFrame containing the event dates as the index and the event durations as the values. |
required |
event_name |
str
|
The name of the event. |
required |
Source code in google_calendar_analytics/visualization/visualizer_factory.py
OneEventPlot
Bases: Plot
Source code in google_calendar_analytics/visualization/visualizer_factory.py
plot(events, event_name)
abstractmethod
async
PiePlot
Bases: ManyEventPlot
Source code in google_calendar_analytics/visualization/visualizer_factory.py
plot(events, title='Top events with the Longest Duration', **kwargs)
async
Plot a pie chart of the event durations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
events |
pd.DataFrame
|
A DataFrame containing the event names as the index and the event durations as the values. |
required |
title |
str
|
The title of the chart. |
'Top events with the Longest Duration'
|
Source code in google_calendar_analytics/visualization/visualizer_factory.py
PlotFactory(style_class, plot_type='Pie', event_name='Event')
async
Factory method to create a plot object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
plot_type |
str
|
The type of plot to create. |
'Pie'
|
event_name |
str
|
The name of the event. |
'Event'
|
style_class |
Type[base_plot_design]
|
The style class to use for the plot. |
required |