From b715e3d8e87babc13d053e1038382e2f8326c2b3 Mon Sep 17 00:00:00 2001 From: Guyot Date: Fri, 1 May 2020 22:50:32 +0200 Subject: [PATCH] Commentaires initiaux et ajout de deux fonctions relatives au BMI --- locale/fr/LC_MESSAGES/base.po | 7 +++-- personal.txt | 1 + weight-cli.py | 50 ++++++++++++++++++++++++++++++++--- 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 personal.txt diff --git a/locale/fr/LC_MESSAGES/base.po b/locale/fr/LC_MESSAGES/base.po index 0724c67..ce47813 100644 --- a/locale/fr/LC_MESSAGES/base.po +++ b/locale/fr/LC_MESSAGES/base.po @@ -23,8 +23,8 @@ msgstr "Un script en ligne de commande pour gérer votre poids." msgid "optional : file data" msgstr "fichier de données : optionnel" -msgid "optional : weight" -msgstr "poids : optionnel" +msgid "optional : weight in kilogram" +msgstr "poids : optionnel en kilogramme" msgid "optional : type" msgstr "type : optionnel" @@ -79,3 +79,6 @@ msgstr "-votre commentaire : {comment}" msgid "-other : {other}" msgstr "-autre : {other}" + +msgid "optional : size in meter" +msgstr "taille en mètre : optionnelle" diff --git a/personal.txt b/personal.txt new file mode 100644 index 0000000..7c483e8 --- /dev/null +++ b/personal.txt @@ -0,0 +1 @@ +1.7 \ No newline at end of file diff --git a/weight-cli.py b/weight-cli.py index 20e163e..a002323 100644 --- a/weight-cli.py +++ b/weight-cli.py @@ -40,7 +40,16 @@ _ = en.gettext # english # Voir : https://medium.com/i18n-and-l10n-resources-for-developers/how-to-translate-python-applications-with-the-gnu-gettext-module-5c1c085041 """ -A measurement is characterized by : +This program allow you to store and visualise your weight. +No database is necessary because all is stored in files. +Three files are important : +- weight-cli.py, the principal program +- data2.csv, the data file and +- Fonctionnel.txt, the code for Gnuplot +But other files are present, as personal.txt with your other +parameters. + +A measure is characterized by : - its value - its type - its date @@ -48,6 +57,12 @@ A measurement is characterized by : - its identifier - one comment - other + +Actually, weight-cli allow to add or remove a measure, +visualise all the measure, plot a graph of these. + +To know witch parameters are available, type : +weight-cli --help or weight-cli -h """ def save_file_data(): @@ -66,7 +81,6 @@ def save_file_data(): f.write(contents) f.close() - def save_mesure(): """ Displaying and recording a measure """ print(_("Your measure has been recorded")) @@ -182,13 +196,34 @@ def plot_graph(): process = Popen(['gnuplot', 'Fonctionnel.txt'])#, stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() #print(stdout) - + +def save_size(): + """ Store the size """ + f = open('personal.txt', "w") + f.write(str(args.size)) + f.close() def tests_subproc(): """ Test of the subprocess module """ process = Popen(['cat', 'data2.csv'], stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() print(stdout) + +def bmi(the_weight): + """ Return the BMI for a given weight """ + f = open('personal.txt', "r") + the_size = float(f.read()) + f.close() + bmi = the_weight / pow(the_size, 2) + return(bmi) + +def bmi_weight_max(): + """ Return the weight for BMI max """ + f = open('personal.txt', "r") + the_size = float(f.read()) + f.close() + weight_max = 29.9 * pow(the_size, 2) + return(weight_max) ### Main ### """ Weight Recording Program @@ -205,10 +240,15 @@ parser.add_argument('-da', '--data', default='data2.csv', help=_('optional : file data') ) +parser.add_argument('-s', '--size', + type=float, + default=-1, + help=_('optional : size in meter') +) parser.add_argument('-w', '--weight', type=float, default=-1, - help=_('optional : weight') + help=_('optional : weight in kilogram') ) parser.add_argument('-t', '--type', default='WEIGHT', @@ -268,6 +308,8 @@ args = parser.parse_args() # Launching of actions if args.data != 'data2.csv': save_file_data() +if args.size != -1: + save_size() if args.weight != -1: save_mesure() if args.read: