Commentaires initiaux et ajout de deux fonctions relatives au BMI

This commit is contained in:
Guyot 2020-05-01 22:50:32 +02:00
parent d6e4046c8f
commit b715e3d8e8
3 changed files with 52 additions and 6 deletions

View File

@ -23,8 +23,8 @@ msgstr "Un script en ligne de commande pour gérer votre poids."
msgid "optional : file data" msgid "optional : file data"
msgstr "fichier de données : optionnel" msgstr "fichier de données : optionnel"
msgid "optional : weight" msgid "optional : weight in kilogram"
msgstr "poids : optionnel" msgstr "poids : optionnel en kilogramme"
msgid "optional : type" msgid "optional : type"
msgstr "type : optionnel" msgstr "type : optionnel"
@ -79,3 +79,6 @@ msgstr "-votre commentaire : {comment}"
msgid "-other : {other}" msgid "-other : {other}"
msgstr "-autre : {other}" msgstr "-autre : {other}"
msgid "optional : size in meter"
msgstr "taille en mètre : optionnelle"

1
personal.txt Normal file
View File

@ -0,0 +1 @@
1.7

View File

@ -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 # 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 value
- its type - its type
- its date - its date
@ -48,6 +57,12 @@ A measurement is characterized by :
- its identifier - its identifier
- one comment - one comment
- other - 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(): def save_file_data():
@ -66,7 +81,6 @@ def save_file_data():
f.write(contents) f.write(contents)
f.close() f.close()
def save_mesure(): def save_mesure():
""" Displaying and recording a measure """ """ Displaying and recording a measure """
print(_("Your measure has been recorded")) print(_("Your measure has been recorded"))
@ -183,6 +197,11 @@ def plot_graph():
stdout, stderr = process.communicate() stdout, stderr = process.communicate()
#print(stdout) #print(stdout)
def save_size():
""" Store the size """
f = open('personal.txt', "w")
f.write(str(args.size))
f.close()
def tests_subproc(): def tests_subproc():
""" Test of the subprocess module """ """ Test of the subprocess module """
@ -190,6 +209,22 @@ def tests_subproc():
stdout, stderr = process.communicate() stdout, stderr = process.communicate()
print(stdout) 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 ### ### Main ###
""" Weight Recording Program """ Weight Recording Program
Be careful, the data.csv file has a header line that lacks Be careful, the data.csv file has a header line that lacks
@ -205,10 +240,15 @@ parser.add_argument('-da', '--data',
default='data2.csv', default='data2.csv',
help=_('optional : file data') help=_('optional : file data')
) )
parser.add_argument('-s', '--size',
type=float,
default=-1,
help=_('optional : size in meter')
)
parser.add_argument('-w', '--weight', parser.add_argument('-w', '--weight',
type=float, type=float,
default=-1, default=-1,
help=_('optional : weight') help=_('optional : weight in kilogram')
) )
parser.add_argument('-t', '--type', parser.add_argument('-t', '--type',
default='WEIGHT', default='WEIGHT',
@ -268,6 +308,8 @@ args = parser.parse_args()
# Launching of actions # Launching of actions
if args.data != 'data2.csv': if args.data != 'data2.csv':
save_file_data() save_file_data()
if args.size != -1:
save_size()
if args.weight != -1: if args.weight != -1:
save_mesure() save_mesure()
if args.read: if args.read: