|
1 | 1 |
|
2 | 2 |
|
3 | 3 | # Collections to keep track of fruits and veggies eaten and water drank
|
| 4 | +# defunct because of Pandas or sqlite |
| 5 | +from collections import defaultdict, namedtuple |
| 6 | +import datetime |
| 7 | +from datetime import timedelta |
| 8 | +from datetime import date |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +# Movie = namedtuple('Movie', 'title year score') |
| 15 | +# directors = defaultdict(list) |
| 16 | +# with open(data, encoding='utf-8') as f: |
| 17 | +# for line in csv.DictReader(f): |
| 18 | +# try: |
| 19 | +# director = line['director_name'] |
| 20 | +# movie = line['movie_title'].replace('\xa0', '') |
| 21 | +# year = int(line['title_year']) |
| 22 | +# score = float(line['imdb_score']) |
| 23 | +# except ValueError: |
| 24 | +# continue |
| 25 | +# |
| 26 | +# m = Movie(title=movie, year=year, score=score) |
| 27 | +# directors[director].append(m) |
| 28 | + |
| 29 | + |
| 30 | +Tracker = namedtuple('Tracker', 'date_entered veggie_serving fruit_serving water_amount') |
| 31 | +tracking = {} #dict |
| 32 | + |
| 33 | +# Hard-coded for now |
| 34 | + |
| 35 | +temp_data = [ |
| 36 | + [datetime.datetime.now(), 4, 0, 8], |
| 37 | + [datetime.datetime.now() + timedelta(days=1), 2, 4, 6], |
| 38 | + [datetime.datetime.now(), 6, 7, 23], |
| 39 | + [datetime.datetime(2018, 5, 5, 16, 20, 42, 518352), 3, 5, 7], |
| 40 | + [datetime.datetime(2018, 5, 5, 20, 20, 42, 518352), 3, 5, 7] |
| 41 | + |
| 42 | +] |
| 43 | + |
| 44 | +# load up tracking |
| 45 | +for i in range(len(temp_data)): |
| 46 | + temp = Tracker(date_entered=temp_data[i][0], |
| 47 | + veggie_serving=temp_data[i][1], |
| 48 | + fruit_serving=temp_data[i][2], |
| 49 | + water_amount=temp_data[i][3]) |
| 50 | + tracking[temp_data[i][0]] = temp |
| 51 | + |
| 52 | + |
| 53 | +print(tracking) |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | +def get_daily_tracking_details(tracking): |
| 58 | + # Goes through the total tracking dict and returns a result for each day |
| 59 | + for date_entered, numbers in tracking.items(): |
| 60 | + print(f"/n {date_entered} {numbers.veggie_serving} {numbers.fruit_serving } {numbers.water_amount}") |
| 61 | +# print(tracking[0]) |
| 62 | +# temp = tracking[0] |
| 63 | +# for date_entered, veggie_serving, fruit_serving, water_amount in tracking.items(): |
| 64 | +# print(f"For day {date_entered} the veggies were {veggie_serving}, fruit were {fruit_serving}, and water was {water_amount}") |
| 65 | +# |
| 66 | +# |
| 67 | +get_daily_tracking_details(tracking) |
| 68 | +# |
0 commit comments