Skip to content

Commit 4b6a4b1

Browse files
committed
Day 6 Commit changes and added files
1 parent 3f2a6c6 commit 4b6a4b1

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

days/04-06-collections/Bite 30 Movie Data Analysis.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ def get_movies_by_director():
2222
"""Extracts all movies from csv and stores them in a dict,
2323
where keys are directors, and values are a list of movies,
2424
use the defined Movie namedtuple"""
25+
26+
# ""
27+
# Their code:
28+
#
29+
#
30+
# directors = defaultdict(list)
31+
# with open(data, encoding='utf-8') as f:
32+
# for line in csv.DictReader(f):
33+
# try:
34+
# director = line['director_name']
35+
# movie = line['movie_title'].replace('\xa0', '')
36+
# year = int(line['title_year'])
37+
# score = float(line['imdb_score'])
38+
# except ValueError:
39+
# continue
40+
#
41+
# m = Movie(title=movie, year=year, score=score)
42+
# directors[director].append(m)
43+
# ""
2544
movies = defaultdict(list)
2645
input_file = csv.DictReader(open(f"/tmp/{fname}"))
2746
for row in input_file:
@@ -34,6 +53,7 @@ def get_movies_by_director():
3453
return movies
3554

3655

56+
3757
def calc_mean_score(movies):
3858
"""Helper method to calculate mean of list of Movie namedtuples,
3959
round the mean to 1 decimal place"""
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,68 @@
11

22

33
# 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

Comments
 (0)