Commit edb84ce5 authored by schd's avatar schd

Tweek stat computer

parent 91aba9f7
{
"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
}
......@@ -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,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment