-
Notifications
You must be signed in to change notification settings - Fork 101
/
Copy pathservice_app.py
140 lines (112 loc) · 3.93 KB
/
service_app.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
import nosql.mongo_setup as mongo_setup
from nosql.car import Car
from nosql.engine import Engine
from nosql.servicehistory import ServiceHistory
def main():
print_header()
config_mongo()
# update_doc_versions()
user_loop()
# noinspection PyProtectedMember
# def update_doc_versions():
# for car in Car.objects():
# car._mark_as_changed('vi_number')
# car.save()
def print_header():
print('----------------------------------------------')
print('| |')
print('| SERVICE CENTRAL v.02 |')
print('| prod edition |')
print('| |')
print('----------------------------------------------')
print()
def config_mongo():
mongo_setup.global_init(
'the_db_admin',
'the-password-3809b81f-ba37-403d-8013-a1ebaf13cf94',
10001,
'107.170.211.24'
)
def user_loop():
while True:
print("Available actions:")
print(" * [a]dd car")
print(" * [l]ist cars")
print(" * [p]oorly serviced")
print(" * perform [s]ervice")
print(" * e[x]it")
print()
ch = input("> ").strip().lower()
if ch == 'a':
add_car()
elif ch == 'l':
list_cars()
elif ch == 's':
service_car()
elif ch == 'p':
show_poorly_serviced_cars()
elif not ch or ch == 'x':
print("Goodbye")
break
def add_car():
model = input("What is the model? ")
make = 'Ferrari' # input("What is the make? ")
year = int(input("Year built? "))
car = Car()
car.year = year
car.make = make
car.model = model
engine = Engine()
engine.horsepower = 590
engine.mpg = 22
engine.liters = 4.0
car.engine = engine
car.save()
def 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():
print("TODO: find_car")
def 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__':
main()