From 74f56e813c7b01666b764b57176aee4101f0c4b2 Mon Sep 17 00:00:00 2001 From: Guyot Date: Thu, 23 Apr 2020 17:14:27 +0200 Subject: [PATCH] Ajout du choix des dates minimale et maximale pour le graphe --- Fonctionnel.txt | 7 ++++--- Fonctionnel.txt_ | 17 +++++++++++++++++ weight-cli.py | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 Fonctionnel.txt_ diff --git a/Fonctionnel.txt b/Fonctionnel.txt index e56150b..1f60c49 100644 --- a/Fonctionnel.txt +++ b/Fonctionnel.txt @@ -3,14 +3,15 @@ set term dumb #nofeed set title 'Courbe de poids' set timefmt "%Y-%m-%d %H:%M:%S" set xdata time -set xmtics +#set xmtics set xlabel "Mois" #set xtics format "%Y-%d-%m" +set xtics format "%m" set x2data time set x2label "Années" set x2tics format "%Y" set xtics nomirror - +set xrange [*:*] set datafile separator '|' -plot 'data2.csv' using 3:1 pt '.' title '' +plot 'data2.csv' using 3:1 pt '*' title '' #pause -1 'En attente de RETURN' diff --git a/Fonctionnel.txt_ b/Fonctionnel.txt_ new file mode 100644 index 0000000..6a00a14 --- /dev/null +++ b/Fonctionnel.txt_ @@ -0,0 +1,17 @@ +#set term dumb 50 20 +set term dumb #nofeed +set title 'Courbe de poids' +set timefmt "%Y-%m-%d %H:%M:%S" +set xdata time +#set xmtics +set xlabel "Mois" +#set xtics format "%Y-%d-%m" +set xtics format "%m" +set x2data time +set x2label "Années" +set x2tics format "%Y" +set xtics nomirror +set xrange ['2019-05-01 00:00:00':'2020-10-01 00:00:00'] +set datafile separator '|' +plot 'data2.csv' using 3:1 pt '*' title '' +#pause -1 'En attente de RETURN' diff --git a/weight-cli.py b/weight-cli.py index 6ac1dbd..a9956bb 100644 --- a/weight-cli.py +++ b/weight-cli.py @@ -57,7 +57,7 @@ def save_file_data(): linenum = 0 for row in contents: if row.split(' ',1)[0] == 'plot': - contents.insert(linenum, "plot '"+args.data+"' using 3:1 pt '.' title ''\n") + contents.insert(linenum, "plot '"+args.data+"' using 3:1 pt '*' title ''\n") del(contents[linenum+1]) linenum += 1 f = open("Fonctionnel.txt", "w") @@ -139,6 +139,38 @@ def undo_remove(): def trace_graph(): """ Trace le graphe de l'évolution du poids avec Gnuplot """ + if args.dates != None: + print(args.dates) + # set xrange [*:*] + f = open("Fonctionnel.txt", "r") + contents = f.readlines() + f.close() + linenum = 0 + for row in contents: + motif = row.split(' ',2)[0]+' '+row.split(' ',2)[1] + if motif == 'set xrange': + contents.insert(linenum, "set xrange ['"+args.dates[0]+"':'"+args.dates[1]+"']\n") + del(contents[linenum+1]) + linenum += 1 + f = open("Fonctionnel.txt", "w") + contents = "".join(contents) + f.write(contents) + f.close() + else: + f = open("Fonctionnel.txt", "r") + contents = f.readlines() + f.close() + linenum = 0 + for row in contents: + motif = row.split(' ',2)[0]+' '+row.split(' ',2)[1] + if motif == 'set xrange': + contents.insert(linenum, "set xrange [*:*]\n") + del(contents[linenum+1]) + linenum += 1 + f = open("Fonctionnel.txt", "w") + contents = "".join(contents) + f.write(contents) + f.close() #process = Popen(['gnuplot', 'Fonctionnel.txt'], stdout=PIPE, stderr=PIPE) process = Popen(['gnuplot', 'Fonctionnel.txt'])#, stdout=PIPE, stderr=PIPE) stdout, stderr = process.communicate() @@ -209,6 +241,10 @@ parser.add_argument('-g', '--graph', help=_('optional : plot graph'), action='store_true' ) +parser.add_argument('-ds', '--dates', + nargs=2, + help=_("optional : date_min date_max ; 'Y-m-d hh:mm:ss'") +) parser.add_argument('-tst', '--tests', help='optional tests operations', action='store_true'