| 
						
						
						
					 | 
					 | 
					@ -1,14 +1,23 @@
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import nosql.mongo_setup as mongo_setup
 | 
					 | 
					 | 
					 | 
					import nosql.mongo_setup as mongo_setup
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from nosql.car import Car
 | 
					 | 
					 | 
					 | 
					from nosql.car import Car
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from nosql.engine import Engine
 | 
					 | 
					 | 
					 | 
					from nosql.engine import Engine
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					from nosql.servicehistory import ServiceHistory
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def main():
 | 
					 | 
					 | 
					 | 
					def main():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    print_header()
 | 
					 | 
					 | 
					 | 
					    print_header()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    config_mongo()
 | 
					 | 
					 | 
					 | 
					    config_mongo()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # update_doc_versions()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    user_loop()
 | 
					 | 
					 | 
					 | 
					    user_loop()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					# noinspection PyProtectedMember
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					# def update_doc_versions():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					#     for car in Car.objects():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					#         car._mark_as_changed('vi_number')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					#         car.save()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def print_header():
 | 
					 | 
					 | 
					 | 
					def print_header():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    print('----------------------------------------------')
 | 
					 | 
					 | 
					 | 
					    print('----------------------------------------------')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    print('|                                             |')
 | 
					 | 
					 | 
					 | 
					    print('|                                             |')
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -28,7 +37,7 @@ def user_loop():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        print("Available actions:")
 | 
					 | 
					 | 
					 | 
					        print("Available actions:")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        print(" * [a]dd car")
 | 
					 | 
					 | 
					 | 
					        print(" * [a]dd car")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        print(" * [l]ist cars")
 | 
					 | 
					 | 
					 | 
					        print(" * [l]ist cars")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        print(" * [f]ind car")
 | 
					 | 
					 | 
					 | 
					        print(" * [p]oorly serviced")
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        print(" * perform [s]ervice")
 | 
					 | 
					 | 
					 | 
					        print(" * perform [s]ervice")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        print(" * e[x]it")
 | 
					 | 
					 | 
					 | 
					        print(" * e[x]it")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        print()
 | 
					 | 
					 | 
					 | 
					        print()
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -37,10 +46,10 @@ def user_loop():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            add_car()
 | 
					 | 
					 | 
					 | 
					            add_car()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        elif ch == 'l':
 | 
					 | 
					 | 
					 | 
					        elif ch == 'l':
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            list_cars()
 | 
					 | 
					 | 
					 | 
					            list_cars()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        elif ch == 'f':
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            find_car()
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        elif ch == 's':
 | 
					 | 
					 | 
					 | 
					        elif ch == 's':
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            service_car()
 | 
					 | 
					 | 
					 | 
					            service_car()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        elif ch == 'p':
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            show_poorly_serviced_cars()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        elif not ch or ch == 'x':
 | 
					 | 
					 | 
					 | 
					        elif not ch or ch == 'x':
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            print("Goodbye")
 | 
					 | 
					 | 
					 | 
					            print("Goodbye")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            break
 | 
					 | 
					 | 
					 | 
					            break
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -67,7 +76,14 @@ def add_car():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def list_cars():
 | 
					 | 
					 | 
					 | 
					def list_cars():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    print("TODO: list_cars")
 | 
					 | 
					 | 
					 | 
					    cars = Car.objects().order_by("-year")
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    for car in cars:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        print("{} -- {} with vin {} (year {})".format(
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            car.make, car.model, car.vi_number, car.year))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        print("{} of service records".format(len(car.service_history)))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        for s in car.service_history:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            print("  * ${:,.0f} {}".format(s.price, s.description))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    print()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def find_car():
 | 
					 | 
					 | 
					 | 
					def find_car():
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -75,7 +91,44 @@ def find_car():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					def service_car():
 | 
					 | 
					 | 
					 | 
					def service_car():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    print("TODO: service_car")
 | 
					 | 
					 | 
					 | 
					    # vin = input("What is the VIN of the car to service? ")
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # car = Car.objects(vi_number=vin).first()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # if not car:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #     print("Car with VIN {} not found!".format(vin))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #     return
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # service = ServiceHistory()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # service.price = float(input("What is the price? "))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # service.description = input("What type of service is this? ")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # service.customer_rating = int(input("How happy is our customer? [1-5] "))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # car.service_history.append(service)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # car.save()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    vin = input("What is the VIN of the car to service? ")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    service = ServiceHistory()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    service.price = float(input("What is the price? "))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    service.description = input("What type of service is this? ")
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    service.customer_rating = int(input("How happy is our customer? [1-5] "))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    updated = Car.objects(vi_number=vin).update_one(push__service_history=service)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    if updated == 0:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        print("Car with VIN {} not found!".format(vin))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					def show_poorly_serviced_cars():
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    level = int(input("What max level of satisfaction are we looking for? [1-5] "))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # { "service_history.customer_rating": {$lte: level} }
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    cars = Car.objects(service_history__customer_rating__lte=level)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    for car in cars:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        print("{} -- {} with vin {} (year {})".format(
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            car.make, car.model, car.vi_number, car.year))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        print("{} of service records".format(len(car.service_history)))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        for s in car.service_history:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            print("  * Satisfaction: {} ${:,.0f} {}".format(
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                s.customer_rating, s.price, s.description))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    print()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					if __name__ == '__main__':
 | 
					 | 
					 | 
					 | 
					if __name__ == '__main__':
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
 
 |