Premier commit
This commit is contained in:
parent
c8ac6332b9
commit
0e26143ee2
16
Fonctionnel.txt
Normal file
16
Fonctionnel.txt
Normal file
@ -0,0 +1,16 @@
|
||||
#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 x2data time
|
||||
set x2label "Années"
|
||||
set x2tics format "%Y"
|
||||
set xtics nomirror
|
||||
|
||||
set datafile separator '|'
|
||||
plot 'data.csv' using 3:1 pt '.' title ''
|
||||
#pause -1 'En attente de RETURN'
|
4
data1.csv
Normal file
4
data1.csv
Normal file
@ -0,0 +1,4 @@
|
||||
value|type|date|metric|id|comment|
|
||||
101|WEIGHT|2015-10-03 03:30:13|true|| Après petite grippe|
|
||||
102|WEIGHT|2015-10-04 09:35:57|true||null|
|
||||
101|WEIGHT|2015-10-05 09:50:00|true||null|
|
|
6
data2.csv
Normal file
6
data2.csv
Normal file
@ -0,0 +1,6 @@
|
||||
6|WEIGHT|2020-04-15 11:16:58|True| |6e test|
|
||||
7|WEIGHT|2020-04-15 11:18:06|True| |7e test|
|
||||
8|WEIGHT|2020-04-15 11:26:06|true||8e test|
|
||||
9|WEIGHT|2020-04-15 11:27:45|true||9e test|
|
||||
10|WEIGHT|2020-04-15 11:39:12|true||10e test|
|
||||
10.1|WEIGHT|2020-04-15 15:22:22|true||11e test|
|
|
6
data3.csv
Normal file
6
data3.csv
Normal file
@ -0,0 +1,6 @@
|
||||
6|WEIGHT|2020-04-15 11:16:58
|
||||
7|WEIGHT|2020-04-15 11:18:06
|
||||
8|WEIGHT|2020-04-15 11:26:06
|
||||
9|WEIGHT|2020-04-15 11:27:45
|
||||
10|WEIGHT|2020-04-15 11:39:12
|
||||
10.1|WEIGHT|2020-04-15 15:22:22
|
|
6
data3.txt
Normal file
6
data3.txt
Normal file
@ -0,0 +1,6 @@
|
||||
2020-04-15 11:16:58|6
|
||||
2020-04-15 11:18:06|7
|
||||
2020-04-15 11:26:06|8
|
||||
2020-04-15 11:27:45|9
|
||||
2020-04-15 11:39:12|10
|
||||
2020-04-15 15:22:22|10.1
|
180
weight-cli.py
Normal file
180
weight-cli.py
Normal file
@ -0,0 +1,180 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import csv
|
||||
import argparse
|
||||
from clint.textui import puts, colored, indent
|
||||
from clint.textui import columns
|
||||
#import pytz
|
||||
#import tzlocal
|
||||
import time
|
||||
from datetime import datetime, timedelta, date
|
||||
import dateutil.parser
|
||||
from dateutil.rrule import rrulestr
|
||||
#from icalendar import Calendar,Event,Todo,Journal,Alarm
|
||||
#import caldav
|
||||
#import uuid
|
||||
#import json
|
||||
import os
|
||||
#import logging
|
||||
import sys
|
||||
#import re
|
||||
#import urllib3
|
||||
#from getpass import getpass
|
||||
#from sympy import symbols
|
||||
#from sympy.plotting import textplot
|
||||
import subprocess
|
||||
from subprocess import Popen, PIPE
|
||||
import numpy as np
|
||||
|
||||
"""
|
||||
Une mesure est caractérisée par :
|
||||
- sa valeur
|
||||
- son type
|
||||
- sa date
|
||||
- sa métrique
|
||||
- son identifiant
|
||||
- un commentaire
|
||||
- autre
|
||||
"""
|
||||
|
||||
def save_mesure():
|
||||
''' Affichage et enregistrement d'une mesure '''
|
||||
print("Votre mesure a été enregistrée : ")
|
||||
with indent(4, quote=colored.blue('')):
|
||||
puts(colored.green("-votre poids : {weight} kg").format(weight=args.weight))
|
||||
puts("-son type : {typ}".format(typ=args.type))
|
||||
puts("-la date : {dat}".format(dat=args.date))
|
||||
puts("-la métrique : {metric}".format(metric=args.metric))
|
||||
puts("-l'identifiant : {ide}".format(ide=args.id))
|
||||
puts("-votre commentaire : {comment}".format(comment=args.comment))
|
||||
puts("-autre : {other}".format(other=args.other))
|
||||
with open(str(args.data), 'a', newline='\n') as csvfile:
|
||||
weightwriter = csv.writer(csvfile, delimiter='|', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
||||
weightwriter.writerow([str(args.weight), \
|
||||
str(args.type), \
|
||||
str(datetime.now().strftime("%Y-%m-%d %H:%M:%S")), \
|
||||
str(args.metric), str(args.id), \
|
||||
str(args.comment), \
|
||||
str(args.other)])
|
||||
|
||||
def read_measures():
|
||||
''' Affichage de l'ensemble des mesures '''
|
||||
data_file = open(str(args.data), 'r')
|
||||
data = csv.reader(data_file, delimiter='|')
|
||||
linenum = 0
|
||||
for row in data:
|
||||
with indent(2, quote=colored.blue('')):
|
||||
puts(columns([(colored.red(str(linenum))), 4], \
|
||||
[(colored.green(str(row[0])+' kg')), 15], \
|
||||
[(str(row[1])),10], \
|
||||
[(colored.yellow(str(row[2]))),25], \
|
||||
[(str(row[3])),6], \
|
||||
[(str(row[4])),4], \
|
||||
[(colored.magenta(str(row[5]))),20])), \
|
||||
[(str(row[6])),10]
|
||||
linenum += 1
|
||||
data_file.close()
|
||||
|
||||
def remove_measure():
|
||||
''' Supprime une mesure '''
|
||||
f = open(args.data, "r")
|
||||
contents = f.readlines()
|
||||
f.close()
|
||||
# remove the line item from list, by line number, starts from 0
|
||||
contents.pop(args.remove)
|
||||
|
||||
f = open(args.data, "w")
|
||||
contents = "".join(contents)
|
||||
f.write(contents)
|
||||
f.close()
|
||||
|
||||
def trace_graph():
|
||||
''' Trace le graphe de l'évolution du poids avec Gnuplot '''
|
||||
#process = Popen(['gnuplot', 'Fonctionnel.txt'], stdout=PIPE, stderr=PIPE)
|
||||
process = Popen(['gnuplot', 'Fonctionnel.txt'])#, stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = process.communicate()
|
||||
#print(stdout)
|
||||
|
||||
|
||||
def tests_subproc():
|
||||
''' Test du module subprocess '''
|
||||
process = Popen(['cat', 'data2.csv'], stdout=PIPE, stderr=PIPE)
|
||||
stdout, stderr = process.communicate()
|
||||
print(stdout)
|
||||
|
||||
### Main ###
|
||||
''' Programme de relevé de poids
|
||||
Attention, le fichier data.csv à une ligne d'entête à laquelle
|
||||
il manque un séparateur | final pour que le nombre de champs soit
|
||||
correct.
|
||||
'''
|
||||
|
||||
# Création du parseur pour les arguments
|
||||
parser = argparse.ArgumentParser()
|
||||
# Création des arguments
|
||||
parser.add_argument('-da', '--data',
|
||||
default='data2.csv',
|
||||
help='optional data'
|
||||
)
|
||||
parser.add_argument('-w', '--weight',
|
||||
type=float,
|
||||
default=-1,
|
||||
help='optional weight'
|
||||
)
|
||||
parser.add_argument('-t', '--type',
|
||||
default='WEIGHT',
|
||||
help='optional type'
|
||||
)
|
||||
parser.add_argument('-d', '--date',
|
||||
default=datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
|
||||
help='optional date'
|
||||
)
|
||||
parser.add_argument('-i', '--id',
|
||||
default='',
|
||||
help='optional id'
|
||||
)
|
||||
parser.add_argument('-m', '--metric',
|
||||
default='true',
|
||||
help='optional metric'
|
||||
)
|
||||
parser.add_argument('-c', '--comment',
|
||||
default=' ',
|
||||
help='optional comment'
|
||||
)
|
||||
parser.add_argument('-o', '--other',
|
||||
default='',
|
||||
help='optional other'
|
||||
)
|
||||
parser.add_argument('-r', '--read',
|
||||
help='optional read measures',
|
||||
action='store_true'
|
||||
)
|
||||
parser.add_argument('-rem', '--remove',
|
||||
type=int,
|
||||
default='-1',
|
||||
help='optional delete a measure by its number in the list'
|
||||
)
|
||||
parser.add_argument('-g', '--graph',
|
||||
help='optional delete a measure by its number in the list',
|
||||
action='store_true'
|
||||
)
|
||||
parser.add_argument('-tst', '--tests',
|
||||
help='optional tests operations',
|
||||
action='store_true'
|
||||
)
|
||||
# Récupération des arguments
|
||||
args = parser.parse_args()
|
||||
# Lancement des actions
|
||||
if args.weight != -1:
|
||||
save_mesure()
|
||||
if args.read:
|
||||
read_measures()
|
||||
if args.remove >= 0:
|
||||
remove_measure()
|
||||
if args.graph:
|
||||
trace_graph()
|
||||
if args.tests:
|
||||
tests_subproc()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user