From edb84ce5a8d7fe04a6f3fef630b722adb9bf91d7 Mon Sep 17 00:00:00 2001 From: schd Date: Wed, 2 Sep 2020 14:23:33 +0200 Subject: [PATCH] Tweek stat computer --- .../exercice-checkpoint.ipynb | 118 ++++++++++++++++++ module2/exo4/exercice.ipynb | 17 +-- 2 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 module2/exo4/.ipynb_checkpoints/exercice-checkpoint.ipynb diff --git a/module2/exo4/.ipynb_checkpoints/exercice-checkpoint.ipynb b/module2/exo4/.ipynb_checkpoints/exercice-checkpoint.ipynb new file mode 100644 index 0000000..dbe26a2 --- /dev/null +++ b/module2/exo4/.ipynb_checkpoints/exercice-checkpoint.ipynb @@ -0,0 +1,118 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# A notebook that gives stats on the notes taken so far\n", + "\n", + "## Useful functions\n", + "\n", + "First, let's define a function that counts how many sections there is in a *log file* : " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "def count_sections(log_file):\n", + " with open(log_file, 'r') as fil: lines = fil.readlines()\n", + " s = 0\n", + " for line in lines : \n", + " print(line[:2])\n", + " if line[:2]==' # ': s += 1\n", + " return s" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Maybe I will add some other useful function later.\n", + "\n", + "Let's list all the *log files* :" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There is 1 log file :\n", + "# \n", + "\n", + "\n", + "- \n", + "- \n", + "\n", + "\n", + "# \n", + "\n", + "\n", + "- \n", + "\n", + "\n", + "\n", + "\n", + "# \n", + "\n", + "\n", + "- \n", + "- \n", + "\tmodule_1.md; contains 0 section.\n" + ] + } + ], + "source": [ + "import os\n", + "\n", + "log_dir = '../../journal/'\n", + "ignored_files = ['Readme.md']\n", + "log_files = [fil for fil in os.listdir(log_dir) if fil not in ignored_files]\n", + "\n", + "if len(log_files)<2 : print(\"There is {:d} log file :\".format(len(log_files)))\n", + "else: print(\"There are {:d} log files :\".format(len(log_files)))\n", + " \n", + "for fil in log_files: \n", + " n_sec = count_sections(log_dir + fil)\n", + " if n_sec <2 : print(\"\\t{:}; contains {:d} section.\".format(fil, n_sec))\n", + " else: print(\"\\t{:}; contains {:d} sections.\".format(fil, n_sec))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.9" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/module2/exo4/exercice.ipynb b/module2/exo4/exercice.ipynb index 3c4f184..5026e21 100644 --- a/module2/exo4/exercice.ipynb +++ b/module2/exo4/exercice.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -21,7 +21,7 @@ " with open(log_file, 'r') as fil: lines = fil.readlines()\n", " s = 0\n", " for line in lines : \n", - " if line[:1]=='# ': s += 1\n", + " if line[:2]=='# ': s += 1\n", " return s" ] }, @@ -36,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -44,7 +44,7 @@ "output_type": "stream", "text": [ "There is 1 log file :\n", - "\tmodule_1.md; contains 0 section.\n" + "\tmodule_1.md; contains 3 sections.\n" ] } ], @@ -64,13 +64,6 @@ " else: print(\"\\t{:}; contains {:d} sections.\".format(fil, n_sec))\n", " " ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -89,7 +82,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.4" + "version": "3.6.9" } }, "nbformat": 4, -- 2.18.1