-
Notifications
You must be signed in to change notification settings - Fork 1
/
classes_of_cars.py
80 lines (63 loc) · 2.39 KB
/
classes_of_cars.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
import os
import csv
class CarBase:
def __init__(self, brand, photo_file_name, carrying):
self.brand = brand
self.photo_file_name = photo_file_name
self.carrying = float(carrying)
def get_photo_file_ext(self):
return os.path.splitext(self.photo_file_name)[1]
class Car(CarBase):
def __init__(self, brand, photo_file_name, carrying, passenger_seats_count):
CarBase.__init__(self, brand, photo_file_name, carrying)
self.passenger_seats_count = int(passenger_seats_count)
self.car_type = 'car'
def get_photo_file_ext(self):
CarBase.get_photo_file_ext(self)
class Truck(CarBase):
def __init__(self, brand, photo_file_name, carrying, body_whl):
CarBase.__init__(self, brand, photo_file_name, carrying)
self.body_whl = body_whl
self.car_type = 'truck'
list_whl = self.body_whl.split('x')
if len(list_whl) == 1:
self.body_length = 0
self.body_width = 0
self.body_height = 0
else:
self.body_length = float(list_whl[0])
self.body_width = float(list_whl[1])
self.body_height = float(list_whl[2])
def get_body_volume(self):
return self.body_height * self.body_length * self.body_width
def get_photo_file_ext(self):
CarBase.get_photo_file_ext(self)
class SpecMachine(CarBase):
def __init__(self, brand, photo_file_name, carrying, extra):
CarBase.__init__(self, brand, photo_file_name, carrying)
self.extra = extra
self.car_type = 'spec_machine'
def get_photo_file_ext(self):
CarBase.get_photo_file_ext(self)
def get_car_list(csv_filename):
car_list = []
with open(csv_filename) as csv_fd:
reader = csv.reader(csv_fd, delimiter=';')
next(reader)
i = 0
for row in reader:
if len(row) < 7:
continue
if row[0] == 'car':
car_list.append(1)
car_list[i] = Car(row[1], row[3], row[5], row[2])
i += 1
if row[0] == 'truck':
car_list.append(1)
car_list[i] = Truck(row[1], row[3], row[5], row[4])
i += 1
if row[0] == 'spec_machine':
car_list.append(1)
car_list[i] = SpecMachine(row[1], row[3], row[5], row[6])
i += 1
return car_list