dimwit 0.2.0__tar.gz → 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dimwit
3
- Version: 0.2.0
3
+ Version: 0.2.2
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
@@ -107,56 +107,82 @@ def get_notion_pages_from_db(
107
107
  return results
108
108
 
109
109
 
110
- def extract_airflow_entry(timestamps, data, idx, page):
110
+ def check_page_valid(page, idx):
111
111
  properties = page["properties"]
112
112
  if properties is None:
113
113
  raise Exception(f"Found empty entry at position {idx} (0-based index)")
114
- ts = dateutil.parser.isoparse(properties["date"]["date"]["start"])
115
- vals = [
116
- properties["recording_1"]["number"],
117
- properties["recording_2"]["number"],
118
- properties["recording_3"]["number"],
119
- ]
114
+
115
+
116
+ def get_notion_date(page, property):
117
+ properties = page["properties"]
118
+ return dateutil.parser.isoparse(properties[property]["date"]["start"])
119
+
120
+
121
+ def get_notion_number(page, property):
122
+ return page["properties"][property]["number"]
123
+
124
+
125
+ def get_notion_multi_select(page, property):
126
+ items = page["properties"][property]["multi_select"]
127
+ return [item["name"] for item in items]
128
+
129
+
130
+ def get_notion_text(page, property):
131
+ properties = page["properties"]
132
+ return properties[property]["rich_text"][0]["text"]["content"]
133
+
134
+
135
+ def extract_airflow_entry(timestamps, data, idx, page):
136
+ check_page_valid(page, idx)
137
+ ts = get_notion_date(page, "date")
138
+ vals = [get_notion_number(page, f"recording_{i}") for i in [1, 2, 3]]
120
139
  timestamps.append(ts)
121
140
  data.append(vals)
122
141
  return None
123
142
 
124
143
 
125
144
  def extract_categorical_entry(timestamps, data, idx, page):
126
- properties = page["properties"]
127
- if properties is None:
128
- raise Exception(f"Found empty entry at position {idx} (0-based index)")
129
- ts = dateutil.parser.isoparse(properties["date"]["date"]["start"])
130
- for item in properties["category"]["multi_select"]:
145
+ check_page_valid(page, idx)
146
+ ts = get_notion_date(page, "date")
147
+ categories = get_notion_multi_select(page, "category")
148
+ for category in categories:
131
149
  timestamps.append(ts)
132
- data.append(item["name"])
150
+ data.append(category)
133
151
  return None
134
152
 
135
153
 
136
154
  def extract_weight_entry(timestamps, data, idx, page):
137
- properties = page["properties"]
138
- if properties is None:
139
- raise Exception(f"Found empty entry at position {idx} (0-based index)")
140
- ts = dateutil.parser.isoparse(properties["date"]["date"]["start"])
141
- weight = properties["weight"]["number"]
142
- categories = properties["category"]["multi_select"]
155
+ check_page_valid(page, idx)
156
+ ts = get_notion_date(page, "date")
157
+ weight = get_notion_number(page, "weight")
158
+ categories = get_notion_multi_select(page, "category")
143
159
  timestamps.append(ts)
144
- data.append((weight, *[item["name"] for item in categories]))
160
+ data.append((weight, *categories))
145
161
  return None
146
162
 
147
163
 
148
164
  def extract_sleep_entry(timestamps, data, idx, page):
149
- properties = page["properties"]
150
- if properties is None:
151
- raise Exception(f"Found empty entry at position {idx} (0-based index)")
152
- start = dateutil.parser.isoparse(properties["start_date"]["date"]["start"])
153
- end = dateutil.parser.isoparse(properties["end_date"]["date"]["start"])
165
+ check_page_valid(page, idx)
166
+ start = get_notion_date(page, "start_date")
167
+ end = get_notion_date(page, "end_date")
168
+ duration = get_notion_text(page, "duration")
154
169
  timestamps.append((start, end))
155
- duration = properties["duration"]["rich_text"][0]["text"]["content"]
156
170
  data.append(duration)
157
171
  return None
158
172
 
159
173
 
174
+ def extract_pomodoro_entry(timestamps, data, idx, page):
175
+ check_page_valid(page, idx)
176
+ ts = get_notion_date(page, "date")
177
+ pomodoro_length = get_notion_number(page, "pomodoro_length")
178
+ break_length = get_notion_number(page, "break_length")
179
+ score = get_notion_number(page, "score")
180
+ comment = get_notion_text(page, "comment")
181
+ timestamps.append(ts)
182
+ data.append((pomodoro_length, break_length, score, comment))
183
+ return None
184
+
185
+
160
186
  def get_all_entries(pages, add_data_entry):
161
187
  timestamps, data = [], []
162
188
 
@@ -246,10 +272,10 @@ def compute_rounded_matrix(ts, events, rounding_unit, rounding_size):
246
272
  return df.fillna(0)
247
273
 
248
274
 
249
- def pad_out_table(df, pad_t):
275
+ def pad_out_table(df, pad_t, unit):
250
276
  # Pad out df with entries before and after boundary rows, to ensure correct
251
277
  # copy-on padding.
252
- time_diff = pd.Timedelta(pad_t, unit="d")
278
+ time_diff = pd.Timedelta(pad_t, unit=unit)
253
279
  pad_before = [df.index[i] - time_diff for i in range(pad_t - 1)]
254
280
  pad_after = [df.index[-(pad_t - i)] + time_diff for i in range(pad_t)]
255
281
  df = pd.concat(
@@ -263,6 +289,9 @@ def pad_out_table(df, pad_t):
263
289
  return df
264
290
 
265
291
 
292
+ # TODO: Enable different window sizes for different columns.
293
+ # Either this means returning a set of Series objects, or padding values in a
294
+ # single dataframe.
266
295
  def compute_moving_average_matrix(
267
296
  ts, events, rounding_unit, rounding_size, window_size
268
297
  ):
@@ -274,7 +303,7 @@ def compute_moving_average_matrix(
274
303
  df_needs_padding = window_size > 1
275
304
  if df_needs_padding:
276
305
  pad_t = (window_size - 1) // 2
277
- df = pad_out_table(df, pad_t)
306
+ df = pad_out_table(df, pad_t, rounding_unit)
278
307
 
279
308
  window_string = str(rounding_size) + rounding_unit
280
309
  dense_series = []
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dimwit"
3
- version = "0.2.0"
3
+ version = "0.2.2"
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