diff --git a/notebook.ipynb b/notebook.ipynb index 37524e2..0deedfd 100644 --- a/notebook.ipynb +++ b/notebook.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -11,18 +11,18 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ - "colNames = ['date', 'check']\n", + "colNames = ['date', 'value']\n", "meditateChecks = pd.read_csv('LoopHabits/002 Meditate/Checkmarks.csv', names=colNames, header=None)\n", "meditateScore = pd.read_csv('LoopHabits/002 Meditate/Scores.csv', names=colNames, header=None)" ] }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ @@ -33,16 +33,45 @@ " return df\n", "\n", "def onlyMarch(df):\n", + " # For habits only, lost my phone in late Febuary, didn't have a recent backup\n", " df['drop'] = df['date'].apply(lambda x: 1 if x[5:7] == '01' or x[5:7] == '02' else 0)\n", " df = df.drop(df[df['drop'] == 1].index)\n", " df = df.drop(columns=['drop'])\n", " return df\n", "\n", "def longestZero(df):\n", - " pass\n", + " # reverse the series so dates are ascending (increasing?)\n", + " # pad out the series with 0s, then diff it to track total, use that total to calculate highest streak\n", + " # streak increases when sum is 0\n", + " diffStreak = pd.concat([pd.Series([0]) , df[::-1].value, pd.Series([0])]).diff().tolist()\n", + " runningSum = 0\n", + " streak = 0\n", + " streakList = []\n", + " for e in diffStreak[1:-1]:\n", + " runningSum += e\n", + " if runningSum == 0:\n", + " streak += 1\n", + " else:\n", + " streakList.append(streak)\n", + " streak = 0\n", + " return sum(streakList)\n", "\n", "def longestStreak(df):\n", - " pass\n", + " # reverse the series so dates are ascending (increasing?)\n", + " # pad out the series with 0s, then diff it to track total, use that total to calculate highest streak\n", + " # streak increases when sum is non-zero\n", + " diffStreak = pd.concat([pd.Series([0]) , df[::-1].value, pd.Series([0])]).diff().tolist()\n", + " runningSum = 0\n", + " streak = 0\n", + " streakList = []\n", + " for e in diffStreak[1:-1]:\n", + " runningSum += e\n", + " if runningSum != 0:\n", + " streak += 1\n", + " else:\n", + " streakList.append(streak)\n", + " streak = 0\n", + " return sum(streakList)\n", "\n", "def bestMonth(df):\n", " pass\n", @@ -50,425 +79,73 @@ "def worstMonth(df):\n", " pass\n", "\n", + "def averagePerMonth(df):\n", + " pass\n", + "\n", "def plotScore(df):\n", - " pass" + " pass\n", + "\n", + "def countZeros(df):\n", + " return (df.value == 0).astype(int).sum()\n", + "\n", + "def countValue(countValue, df):\n", + " return (df.value == countValue).astype(int).sum()\n" ] }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 69, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Days done: 72\n", + "Non-streak days: 195\n", + "Streak days: 39\n" + ] + } + ], + "source": [ + "print(\"Days done: \" + str(countValue(2, onlyMarch(only2019(meditateChecks)))))\n", + "print(\"Non-streak days: \" + str(countZeros(onlyMarch(only2019(meditateChecks)))))\n", + "print(\"Streak days: \" + str(countValue(1, onlyMarch(only2019(meditateChecks)))))" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "306\n" + ] + }, { "data": { - "text/html": [ - "
\n", - " | date | \n", - "check | \n", - "
---|---|---|
17 | \n", - "2019-12-31 | \n", - "0 | \n", - "
18 | \n", - "2019-12-30 | \n", - "0 | \n", - "
19 | \n", - "2019-12-29 | \n", - "0 | \n", - "
20 | \n", - "2019-12-28 | \n", - "0 | \n", - "
21 | \n", - "2019-12-27 | \n", - "0 | \n", - "
22 | \n", - "2019-12-26 | \n", - "0 | \n", - "
23 | \n", - "2019-12-25 | \n", - "0 | \n", - "
24 | \n", - "2019-12-24 | \n", - "2 | \n", - "
25 | \n", - "2019-12-23 | \n", - "1 | \n", - "
26 | \n", - "2019-12-22 | \n", - "1 | \n", - "
27 | \n", - "2019-12-21 | \n", - "2 | \n", - "
28 | \n", - "2019-12-20 | \n", - "2 | \n", - "
29 | \n", - "2019-12-19 | \n", - "0 | \n", - "
30 | \n", - "2019-12-18 | \n", - "0 | \n", - "
31 | \n", - "2019-12-17 | \n", - "0 | \n", - "
32 | \n", - "2019-12-16 | \n", - "2 | \n", - "
33 | \n", - "2019-12-15 | \n", - "0 | \n", - "
34 | \n", - "2019-12-14 | \n", - "0 | \n", - "
35 | \n", - "2019-12-13 | \n", - "2 | \n", - "
36 | \n", - "2019-12-12 | \n", - "0 | \n", - "
37 | \n", - "2019-12-11 | \n", - "0 | \n", - "
38 | \n", - "2019-12-10 | \n", - "0 | \n", - "
39 | \n", - "2019-12-09 | \n", - "0 | \n", - "
40 | \n", - "2019-12-08 | \n", - "0 | \n", - "
41 | \n", - "2019-12-07 | \n", - "0 | \n", - "
42 | \n", - "2019-12-06 | \n", - "0 | \n", - "
43 | \n", - "2019-12-05 | \n", - "0 | \n", - "
44 | \n", - "2019-12-04 | \n", - "0 | \n", - "
45 | \n", - "2019-12-03 | \n", - "0 | \n", - "
46 | \n", - "2019-12-02 | \n", - "0 | \n", - "
... | \n", - "... | \n", - "... | \n", - "
293 | \n", - "2019-03-30 | \n", - "1 | \n", - "
294 | \n", - "2019-03-29 | \n", - "1 | \n", - "
295 | \n", - "2019-03-28 | \n", - "2 | \n", - "
296 | \n", - "2019-03-27 | \n", - "2 | \n", - "
297 | \n", - "2019-03-26 | \n", - "0 | \n", - "
298 | \n", - "2019-03-25 | \n", - "0 | \n", - "
299 | \n", - "2019-03-24 | \n", - "2 | \n", - "
300 | \n", - "2019-03-23 | \n", - "0 | \n", - "
301 | \n", - "2019-03-22 | \n", - "1 | \n", - "
302 | \n", - "2019-03-21 | \n", - "2 | \n", - "
303 | \n", - "2019-03-20 | \n", - "0 | \n", - "
304 | \n", - "2019-03-19 | \n", - "2 | \n", - "
305 | \n", - "2019-03-18 | \n", - "0 | \n", - "
306 | \n", - "2019-03-17 | \n", - "0 | \n", - "
307 | \n", - "2019-03-16 | \n", - "2 | \n", - "
308 | \n", - "2019-03-15 | \n", - "0 | \n", - "
309 | \n", - "2019-03-14 | \n", - "1 | \n", - "
310 | \n", - "2019-03-13 | \n", - "2 | \n", - "
311 | \n", - "2019-03-12 | \n", - "0 | \n", - "
312 | \n", - "2019-03-11 | \n", - "2 | \n", - "
313 | \n", - "2019-03-10 | \n", - "0 | \n", - "
314 | \n", - "2019-03-09 | \n", - "0 | \n", - "
315 | \n", - "2019-03-08 | \n", - "0 | \n", - "
316 | \n", - "2019-03-07 | \n", - "0 | \n", - "
317 | \n", - "2019-03-06 | \n", - "0 | \n", - "
318 | \n", - "2019-03-05 | \n", - "0 | \n", - "
319 | \n", - "2019-03-04 | \n", - "0 | \n", - "
320 | \n", - "2019-03-03 | \n", - "0 | \n", - "
321 | \n", - "2019-03-02 | \n", - "0 | \n", - "
322 | \n", - "2019-03-01 | \n", - "0 | \n", - "
306 rows × 2 columns
\n", - "