This repository has been archived by the owner on Oct 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
executable file
·187 lines (141 loc) · 3.26 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env python3
import sys
from FoodLogger import FoodLogger
from Weight import WeightLog
from Plotter import *
from Suggest import Suggest
from Common import daysSince, previousDay
from Config import Config
from Messages import RESULT
class Args:
def usage(self):
print('''
Records progress during weight and food consumption
%s <command> <task> [OPTS]
commands: insert, remove, list, plot, suggest, lookup, test, cleartest
tasks: weight, food
OPTS: foodname, lbs, lowcal, tag
''' % sys.argv[0].split('/')[-1], file=sys.stderr);
exit(-1)
def __init__(self, argv):
if len(argv)<3:
self.usage()
self.argv = argv
self.parse()
self.callProgs()
def parse(self):
self.insert = False
self.remove = False
self.list = False
self.plot = False
self.suggest = False
self.test = 0
self.food = False; self.weight = False
self.task = ""
arg=self.argv[1].lower()
if arg.startswith('insert') or arg.startswith('log'):
self.insert=True
elif arg.startswith('remove') or arg.startswith('delete'):
self.remove=True
elif arg.startswith('list'):
self.list=True
elif arg.startswith('plot'):
self.plot=True
elif arg.startswith('suggest'):
self.suggest=True
elif arg.startswith('test'):
self.test=1
self.insert=True
elif arg.startswith('cleartest'):
self.test=2
arg=self.argv[2].lower()
if arg.startswith('food'):
self.food=True
elif arg.startswith('weight'):
self.weight=True
self.opts = " ".join(self.argv[3:])
def callProgs(self):
Config.resolveAllPaths()
#import pdb
#pdb.set_trace()
if self.weight:
wl = WeightLog()
if self.insert:
wl.checkGaps()
return
if self.remove:
RESULT("TODO: Not implemented")
return
if self.list:
wl.display() # default first
return
if self.plot:
xy = XYGraph(False)
startdate=""
for date in sorted(wl.weightlogmap.keys()):
if startdate=="":
startdate=date
continue
days_since = daysSince(startdate,date)
total = days_since
# print date,total
w = wl.weightlogmap[date]
if w.morn>0:
xy.addPoint(total,w.morn,"x")
if w.night>0:
xy.addPoint(total+.5,w.night,"x")
Printer(xy)
return
RESULT("Nothing to do")
return
if self.food:
fl = FoodLogger(testmode=self.test)
if self.insert:
fl.log(self.opts)
return
if self.remove:
RESULT("Not implemented")
return
if self.list:
date = fl.date
if self.opts!="":
count = int(self.opts)
while count >0:
date = previousDay(date)
count -= 1
fl.showTotals(date, showPie=True)
return
if self.plot:
RESULT("Not implemented")
return
if self.suggest:
fl.makeTotals(fl.date)
p = fl.pie
lowcal=False
tag=""
try:
p.allow_kc = int(self.opts)
except ValueError:
opts = self.opts.lower().split()
if len(opts)!=1:
tag= ' '.join(opts[:-1])
p.allow_kc = int(opts[-1])
else:
tag=self.opts
if tag=="lowcal":
lowcal=True
pass
s = Suggest(fl.foodlist,
p.allow_kc,
p.allow_carb,
p.allow_prot,
p.allow_fat,
tag)
if lowcal:s.lowCalHighPF()
else:s.suggestSomething()
return
try:
Args(sys.argv)
except KeyboardInterrupt:
RESULT("\nQuit")
exit(-1)