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", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
datecheck
172019-12-310
182019-12-300
192019-12-290
202019-12-280
212019-12-270
222019-12-260
232019-12-250
242019-12-242
252019-12-231
262019-12-221
272019-12-212
282019-12-202
292019-12-190
302019-12-180
312019-12-170
322019-12-162
332019-12-150
342019-12-140
352019-12-132
362019-12-120
372019-12-110
382019-12-100
392019-12-090
402019-12-080
412019-12-070
422019-12-060
432019-12-050
442019-12-040
452019-12-030
462019-12-020
.........
2932019-03-301
2942019-03-291
2952019-03-282
2962019-03-272
2972019-03-260
2982019-03-250
2992019-03-242
3002019-03-230
3012019-03-221
3022019-03-212
3032019-03-200
3042019-03-192
3052019-03-180
3062019-03-170
3072019-03-162
3082019-03-150
3092019-03-141
3102019-03-132
3112019-03-120
3122019-03-112
3132019-03-100
3142019-03-090
3152019-03-080
3162019-03-070
3172019-03-060
3182019-03-050
3192019-03-040
3202019-03-030
3212019-03-020
3222019-03-010
\n", - "

306 rows × 2 columns

\n", - "
" - ], "text/plain": [ - " date check\n", - "17 2019-12-31 0\n", - "18 2019-12-30 0\n", - "19 2019-12-29 0\n", - "20 2019-12-28 0\n", - "21 2019-12-27 0\n", - "22 2019-12-26 0\n", - "23 2019-12-25 0\n", - "24 2019-12-24 2\n", - "25 2019-12-23 1\n", - "26 2019-12-22 1\n", - "27 2019-12-21 2\n", - "28 2019-12-20 2\n", - "29 2019-12-19 0\n", - "30 2019-12-18 0\n", - "31 2019-12-17 0\n", - "32 2019-12-16 2\n", - "33 2019-12-15 0\n", - "34 2019-12-14 0\n", - "35 2019-12-13 2\n", - "36 2019-12-12 0\n", - "37 2019-12-11 0\n", - "38 2019-12-10 0\n", - "39 2019-12-09 0\n", - "40 2019-12-08 0\n", - "41 2019-12-07 0\n", - "42 2019-12-06 0\n", - "43 2019-12-05 0\n", - "44 2019-12-04 0\n", - "45 2019-12-03 0\n", - "46 2019-12-02 0\n", - ".. ... ...\n", - "293 2019-03-30 1\n", - "294 2019-03-29 1\n", - "295 2019-03-28 2\n", - "296 2019-03-27 2\n", - "297 2019-03-26 0\n", - "298 2019-03-25 0\n", - "299 2019-03-24 2\n", - "300 2019-03-23 0\n", - "301 2019-03-22 1\n", - "302 2019-03-21 2\n", - "303 2019-03-20 0\n", - "304 2019-03-19 2\n", - "305 2019-03-18 0\n", - "306 2019-03-17 0\n", - "307 2019-03-16 2\n", - "308 2019-03-15 0\n", - "309 2019-03-14 1\n", - "310 2019-03-13 2\n", - "311 2019-03-12 0\n", - "312 2019-03-11 2\n", - "313 2019-03-10 0\n", - "314 2019-03-09 0\n", - "315 2019-03-08 0\n", - "316 2019-03-07 0\n", - "317 2019-03-06 0\n", - "318 2019-03-05 0\n", - "319 2019-03-04 0\n", - "320 2019-03-03 0\n", - "321 2019-03-02 0\n", - "322 2019-03-01 0\n", - "\n", - "[306 rows x 2 columns]" + "299" ] }, - "execution_count": 88, + "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "onlyMarch(only2019(meditateChecks))" + "print(72 + 195 + 39)\n", + "longestStreak(onlyMarch(only2019(meditateChecks))) + longestZero(onlyMarch(only2019(meditateChecks)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Why don't the above two numbers match??" ] } ],