Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 10 #101

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c8b16b3
Think this works, can't do testing because it can't import inventory.…
UncleanlyCleric May 23, 2019
f976c72
It works, as far as I can tell. My testing doesn't though so....
UncleanlyCleric May 23, 2019
0ce95aa
Hey, this one is done.
UncleanlyCleric May 23, 2019
dedef09
Getting closer, I think. I'm not sure.
UncleanlyCleric May 23, 2019
1cdfa63
lesson07, not lesson07-2, is completely caught up and correct
UncleanlyCleric May 24, 2019
fd89cbb
Update
UncleanlyCleric May 24, 2019
19618bc
Update
UncleanlyCleric May 24, 2019
7378aa8
Activity done
UncleanlyCleric May 29, 2019
68e0158
Merge branch 'master' of https://github.com/UncleanlyCleric/py220-onl…
UncleanlyCleric May 29, 2019
279c45d
Initial copying of older files
UncleanlyCleric May 29, 2019
4a91623
Should use the one that works
UncleanlyCleric May 29, 2019
4ec3aac
There we go... all ready to start working
UncleanlyCleric May 29, 2019
1f6180e
Minor modifcations to charges_calc, and created jpgdiscover
UncleanlyCleric May 29, 2019
80de042
Sorting out testing now
UncleanlyCleric May 29, 2019
4d48900
database.py complete
UncleanlyCleric May 29, 2019
718c173
Getting an error on the jpg tests. At first it was because they're a…
UncleanlyCleric May 29, 2019
e101a8d
Linting now 100%
UncleanlyCleric May 31, 2019
9533977
Everything is working, turning in assignment.
UncleanlyCleric May 31, 2019
458cb5f
Setting this up to start working on
UncleanlyCleric May 31, 2019
53a7cd3
Setting up timers and designing the class structure.
UncleanlyCleric May 31, 2019
c450b1e
Insert muppet song here
UncleanlyCleric May 31, 2019
117177e
Super secret push to cover for me being on-call next week
UncleanlyCleric May 31, 2019
f516172
More work
UncleanlyCleric May 31, 2019
a3ed633
Added print statements.
UncleanlyCleric May 31, 2019
ab68829
Finishing up Lesson10
UncleanlyCleric Jun 3, 2019
8261a52
Should be the last little bit
UncleanlyCleric Jun 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion students/jesse_miller/README.rst
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
Python code for UWPCE-PythonCert class, written by Jesse Miller
======================================
Python code for UWPCE-PythonCert class
======================================
Jesse Miller
------------
*April 2019 - June 2019*


Modules
-------
| Lesson 01: Automated Testing
| Lesson 02: Logging & Debugging
| Lesson 03: Relational Databases
| Lesson 04: Iteration
| Lesson 05: Consuming APIs with NoSQL
| Lesson 06: Profiling & Performance
| Lesson 07: Currency & Async
| Lesson 08: Functional Techniques
| Lesson 09: Advanced Python Language Constructs
| Lesson 10: Metaprogramming
15 changes: 15 additions & 0 deletions students/jesse_miller/lesson07/assignment/data/notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,18 @@ Line # Hits Time Per Hit % Time Line Contents

Of course, show_rentals() still doesn't work, and for the life of me I don't
know why... it's showing up empty now.

After some help from Andy, it is now loading everything and behaving as it should:


eve:src jmiller$ python linear_db.py
1.745246162
21.232116215


eve:src jmiller$ python parallel_db.py
1.7145865059999994
18.535026158
Timer unit: 1e-06 s

Shaved a few seconds off on this old MacBook.
153 changes: 0 additions & 153 deletions students/jesse_miller/lesson07/assignment/src/database.py

This file was deleted.

37 changes: 11 additions & 26 deletions students/jesse_miller/lesson07/assignment/src/linear_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
'''
import csv
import logging
# import time
import os
from timeit import timeit
from pathlib import Path
Expand Down Expand Up @@ -72,14 +71,12 @@ def _add_bulk_data(collection, directory_name, filename):
'''
file_path = os.path.join(directory_name, filename)

# start_time = time.time()
initial_records = collection.count_documents({})

collection.insert_many(_import_csv(file_path), ordered=False)

final_records = collection.count_documents({})
records_processed = final_records - initial_records
# run_time = time.time() - start_time

return records_processed, initial_records, final_records #, run_time

Expand All @@ -88,16 +85,6 @@ def import_data(db, directory_name, products_file, customers_file, rentals_file)
'''
Function to import data into three MongoDB tables
'''
# products = db['products']
# products_results = _add_bulk_data(products, directory_name, products_file)
#
# customers = db['customers']
# customers_results = _add_bulk_data(customers, directory_name, customers_file)
#
# rentals = db['rentals']
# rentals_results = _add_bulk_data(rentals, directory_name, rentals_file)

# return [products_results, customers_results, rentals_results]
product_errors = 0
customer_errors = 0
rental_errors = 0
Expand Down Expand Up @@ -129,7 +116,8 @@ def import_data(db, directory_name, products_file, customers_file, rentals_file)

def show_available_products(db):
'''
Returns a dictionary for each product that is available for rent (quantity > 0).
Returns a dictionary for each product that is available for rent
(quantity > 0).
'''
available_products = {}
for product_id in db.products.find():
Expand All @@ -151,19 +139,17 @@ def show_rentals(db, product_id):
for rental in db.rentals.find():
if rental['product_id'] == product_id:
customer_id = rental['user_id']
print(customer_id)

customer_record = db.customers.find_one({'user_id': customer_id})
print(customer_record)

rental_users = {'name': customer_record['name'],
'address': customer_record['address'],
'phone_number': customer_record['phone_number'],
'email': customer_record['email']}
customer_record = db.customers.find_one({'Id': customer_id})

rental_users = {'name': customer_record['Name'] + ' ' +
customer_record['Last_name'],
'address': customer_record['Home_address'],
'phone_number': customer_record['Phone_number'],
'email': customer_record['Email_address']}
rental_users_dict[customer_id] = rental_users
print(db.customers.find_one({'user_id': 'C000003'}))
return rental_users_dict

return rental_users_dict


def clear_data(db):
Expand Down Expand Up @@ -191,9 +177,8 @@ def main():
logging.info('Showing available products')
logging.info(show_available_products(db))

logging.info('\nShowing rental information for P000003')
logging.info('\nShowing rental information for P000004')
logging.info(show_rentals(db, 'P000004'))
print(show_rentals(db, 'P000004'))

logging.info('\nClearing data from database.')
clear_data(db)
Expand Down
30 changes: 16 additions & 14 deletions students/jesse_miller/lesson07/assignment/src/parallel_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def print_mdb_collection(collection_name):
print(doc)


def import_data(filename):
def _import_csv(filename):
'''
Returns a list of dictionaries. One dictionary for each row of data in a
csv file.
Expand All @@ -49,9 +49,9 @@ def import_data(filename):

csv_data = csv.reader(csvfile)

headers = next(csv_data, None)
headers = next(csv_data, None) # Save the first line as the headers

if headers[0].startswith(''):
if headers[0].startswith(''): # Check for weird formatting
headers[0] = headers[0][3:]

for row in csv_data:
Expand Down Expand Up @@ -135,22 +135,24 @@ def show_available_products(db):

def show_rentals(db, product_id):
'''
Returns a dictionary with user information from users who have rented
products matching the product_id.
Function to look up customers who have rented a specific product.
'''

customer_info = {}
rental_users_dict = {}

for rental in db.rentals.find():
if rental["product_id"] == product_id:
customer_id = rental["user_id"]
customer_record = db.customers.find_one({"user_id": customer_id})
if rental['product_id'] == product_id:
customer_id = rental['user_id']

customer_record = db.customers.find_one({'Id': customer_id})

short_dict = {key: value for key, value in customer_record.items() \
if key not in ("_id", "user_id")}
customer_info[customer_id] = short_dict
rental_users = {'name': customer_record['Name'] + ' ' +
customer_record['Last_name'],
'address': customer_record['Home_address'],
'phone_number': customer_record['Phone_number'],
'email': customer_record['Email_address']}
rental_users_dict[customer_id] = rental_users

return customer_info
return rental_users_dict


def clear_data(db):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,10 @@ def test_show_available_products(mongo_database):

def test_show_rentals(mongo_database):
l.import_data(mongo_database, '', 'product.csv', 'customer.csv', 'rental.csv')
result = l.show_rentals(mongo_database, 'prd004')

expected = {'C000002': {'first_name': 'Blanca',
'last_name': 'Bashirian',
'address': '0193 Malvina Lake',
'phone_number': '(240)014-9496 x08349',
'email': '[email protected]',
'status': 'Active', 'credit_limit': '689'},
'C000004': {'first_name': 'Mittie',
'last_name': 'Turner',
'address': '996 Lorenza Points',
'phone_number': '1-324-023-8861 x025',
'email': '[email protected]',
'status': 'Active', 'credit_limit': '565'}}
result = l.show_rentals(mongo_database, 'P000004')

assert len(result) == 2
assert list(result.keys()) == ['C000002', 'C000004']
assert result == expected



def test_clear_data(mongo_database):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,8 @@ def test_show_rentals(mongo_database):

result = d.show_rentals(mongo_database, 'P000004')

expected = {'C000002': {'first_name': 'Blanca',
'last_name': 'Bashirian',
'address': '0193 Malvina Lake',
'phone_number': '(240)014-9496 x08349',
'email': '[email protected]',
'status': 'Active',
'credit_limit': '689'},
'C000004': {'first_name': 'Mittie',
'last_name': 'Turner',
'address': '996 Lorenza Points',
'phone_number': '1-324-023-8861 x025',
'email': '[email protected]',
'status': 'Active',
'credit_limit': '565'}}

assert len(result) == 2
assert list(result.keys()) == ['C000002', 'C000004']
assert result == expected


def test_clear_data(mongo_database):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Amy Sutton,LR01,Small lamp,7.50
Amy Sutton,LR02,Television,28.00
Amy Sutton,BR07,LED lamp,5.50
Amy Sutton,KT08,Basic refrigerator,40.00
Loading