Add function undo remove a line.

This commit is contained in:
Guyot 2020-04-20 17:42:54 +02:00
parent 0e26143ee2
commit 4e33c77308
3 changed files with 30 additions and 7 deletions

View File

@ -1,6 +1,3 @@
6|WEIGHT|2020-04-15 11:16:58|True| |6e test| 6|WEIGHT|2020-04-15 11:16:58|True| |6e test|
7|WEIGHT|2020-04-15 11:18:06|True| |7e test| 7|WEIGHT|2020-04-15 11:18:06|True| |7e test|
8|WEIGHT|2020-04-15 11:26:06|true||8e test| 13.0|WEIGHT|2020-04-20 17:39:31|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|

1 6 WEIGHT 2020-04-15 11:16:58 True 6e test
2 7 WEIGHT 2020-04-15 11:18:06 True 7e test
3 8 13.0 WEIGHT 2020-04-15 11:26:06 2020-04-20 17:39:31 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

1
remove.txt Normal file
View File

@ -0,0 +1 @@
2 13.0|WEIGHT|2020-04-20 17:39:31|true||8e test|

View File

@ -77,11 +77,15 @@ def read_measures():
data_file.close() data_file.close()
def remove_measure(): def remove_measure():
''' Supprime une mesure ''' ''' Remove a measure '''
f = open(args.data, "r") f = open(args.data, "r")
contents = f.readlines() contents = f.readlines()
f.close() f.close()
# remove the line item from list, by line number, starts from 0 # remove the line item from list, by line number, starts from 0
store_temp = str(args.remove)+' '+contents[args.remove]
g = open('remove.txt', "w")
g.write(str(store_temp))
g.close()
contents.pop(args.remove) contents.pop(args.remove)
f = open(args.data, "w") f = open(args.data, "w")
@ -89,6 +93,22 @@ def remove_measure():
f.write(contents) f.write(contents)
f.close() f.close()
def undo_remove():
''' Undo remove the last line removed '''
f = open(args.data, "r")
contents = f.readlines()
f.close()
g = open('remove.txt', 'r')
store_temp = g.readline().split(' ',1)
g.close()
# insert the line item from list, by line number, starts from 0
contents.insert(int(store_temp[0]), store_temp[1])
f = open(args.data, "w")
contents = "".join(contents)
f.write(contents)
f.close()
def trace_graph(): def trace_graph():
''' Trace le graphe de l'évolution du poids avec Gnuplot ''' ''' 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)
@ -115,7 +135,7 @@ parser = argparse.ArgumentParser()
# Création des arguments # Création des arguments
parser.add_argument('-da', '--data', parser.add_argument('-da', '--data',
default='data2.csv', default='data2.csv',
help='optional data' help='optional file data'
) )
parser.add_argument('-w', '--weight', parser.add_argument('-w', '--weight',
type=float, type=float,
@ -163,6 +183,10 @@ parser.add_argument('-tst', '--tests',
help='optional tests operations', help='optional tests operations',
action='store_true' action='store_true'
) )
parser.add_argument('-ur', '--undoremove',
help='optional undo remove the last line removed',
action='store_true'
)
# Récupération des arguments # Récupération des arguments
args = parser.parse_args() args = parser.parse_args()
# Lancement des actions # Lancement des actions
@ -176,5 +200,6 @@ if args.graph:
trace_graph() trace_graph()
if args.tests: if args.tests:
tests_subproc() tests_subproc()
if args.undoremove:
undo_remove()