dimwit 0.2.5__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dimwit-0.2.5 → dimwit-0.2.7}/PKG-INFO +1 -1
- {dimwit-0.2.5 → dimwit-0.2.7}/dimwit/main.py +38 -12
- {dimwit-0.2.5 → dimwit-0.2.7}/pyproject.toml +1 -1
- {dimwit-0.2.5 → dimwit-0.2.7}/README.md +0 -0
- {dimwit-0.2.5 → dimwit-0.2.7}/dimwit/__init__.py +0 -0
- {dimwit-0.2.5 → dimwit-0.2.7}/dimwit/air_pollution.py +0 -0
- {dimwit-0.2.5 → dimwit-0.2.7}/dimwit/legacy.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dimwit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: A package containing various functions and classes for fetching, transforming, and visualising data for personal metrics.
|
|
5
5
|
Home-page: https://github.com/danielsoutar/dimwit
|
|
6
6
|
Author: Daniel Soutar
|
|
@@ -2,7 +2,7 @@ import datetime as dat
|
|
|
2
2
|
import dateutil
|
|
3
3
|
|
|
4
4
|
# Import matplotlib before pandas to avoid import ordering issues.
|
|
5
|
-
import matplotlib.pyplot as plt
|
|
5
|
+
import matplotlib.pyplot as plt
|
|
6
6
|
import pandas as pd
|
|
7
7
|
import requests
|
|
8
8
|
import numpy as np
|
|
@@ -274,7 +274,11 @@ def compute_rounded_matrix(ts, events, rounding_unit, rounding_size):
|
|
|
274
274
|
return df.fillna(0)
|
|
275
275
|
|
|
276
276
|
|
|
277
|
-
def
|
|
277
|
+
def zero_padded_df(num_rows, num_cols, index):
|
|
278
|
+
return pd.DataFrame([[0] * num_cols] * num_rows, index=index)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def pad_out_table(df, pad_t, unit, pad_before=True, pad_after=True):
|
|
278
282
|
# Pad out df with entries before and after boundary rows, to ensure correct
|
|
279
283
|
# same- (or zero-) padding.
|
|
280
284
|
pad_t_days = pd.Timedelta(pad_t, unit=unit)
|
|
@@ -283,16 +287,14 @@ def pad_out_table(df, pad_t, unit):
|
|
|
283
287
|
|
|
284
288
|
# The index in df cannot yet be assumed to be dense - so use a date range
|
|
285
289
|
# with the earliest and latest entries as reference points.
|
|
286
|
-
|
|
287
|
-
|
|
290
|
+
index_before = pd.date_range(pad_before_start, periods=pad_t, freq=unit)
|
|
291
|
+
index_after = pd.date_range(pad_after_start, periods=pad_t, freq=unit)
|
|
288
292
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
]
|
|
295
|
-
)
|
|
293
|
+
num_rows, num_cols = pad_t, len(df.columns)
|
|
294
|
+
if pad_before:
|
|
295
|
+
df = pd.concat([zero_padded_df(num_rows, num_cols, index_before), df])
|
|
296
|
+
if pad_after:
|
|
297
|
+
df = pd.concat([zero_padded_df(num_rows, num_cols, index_after), df])
|
|
296
298
|
|
|
297
299
|
return df
|
|
298
300
|
|
|
@@ -338,9 +340,12 @@ def get_aggregated_event_counts(ts, events, period):
|
|
|
338
340
|
df = df.pivot_table(
|
|
339
341
|
index="date", columns="categories", values="value", aggfunc="sum"
|
|
340
342
|
)
|
|
341
|
-
if period not in ["weekly", "daily"]:
|
|
343
|
+
if period.lower() not in ["monthly", "weekly", "daily"]:
|
|
342
344
|
raise Exception("Period argument not recognised")
|
|
343
345
|
|
|
346
|
+
if period == "monthly":
|
|
347
|
+
grouped_df = df.groupby([pd.Grouper(freq="ME")]).sum()
|
|
348
|
+
|
|
344
349
|
if period == "weekly":
|
|
345
350
|
df.index = df.index - pd.to_timedelta(7, unit="d")
|
|
346
351
|
grouped_df = df.groupby([pd.Grouper(freq="W")]).sum()
|
|
@@ -364,3 +369,24 @@ def populate_with_events(ax, events, from_date):
|
|
|
364
369
|
label=event_label,
|
|
365
370
|
)
|
|
366
371
|
return ax
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
def plot_category(
|
|
375
|
+
title, df, categories, window_size, round_size, round_unit, from_date=None
|
|
376
|
+
):
|
|
377
|
+
fig, ax = plt.subplots(1, 1, figsize=(12, 6))
|
|
378
|
+
ax.set_title(title)
|
|
379
|
+
for category in categories:
|
|
380
|
+
if from_date is not None:
|
|
381
|
+
ax = df[from_date:].plot(y=category, ax=ax)
|
|
382
|
+
else:
|
|
383
|
+
ax = df.plot(y=category, ax=ax)
|
|
384
|
+
ax.set_xlabel("Time")
|
|
385
|
+
ax.set_ylabel("Frequency")
|
|
386
|
+
ax.legend(
|
|
387
|
+
[
|
|
388
|
+
f"{category} ({str(round_size) + round_unit}, k={window_size})"
|
|
389
|
+
for category in categories
|
|
390
|
+
],
|
|
391
|
+
)
|
|
392
|
+
return fig, ax
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "dimwit"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.7"
|
|
4
4
|
description = "A package containing various functions and classes for fetching, transforming, and visualising data for personal metrics."
|
|
5
5
|
authors = ["Daniel Soutar <danielsoutar144@gmail.com>"]
|
|
6
6
|
readme = "README.md"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|