-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
63 lines (48 loc) · 1.63 KB
/
models.py
File metadata and controls
63 lines (48 loc) · 1.63 KB
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
class Library():
sorted = False
def __init__(self, id, book_amount, signup, shipping, books, weight):
self.id : int = int(id)
self.book_amount : int = int(book_amount)
self.signup : int = int(signup)
self.shipping : int = int(shipping)
self.books : List = books
self.weight : int = weight
class Data():
def __init__(self, file):
f = open(file, "r")
first_line = f.readline()
nums = first_line.split(' ')
self.total_books = int(nums[0])
self.total_libraries = int(nums[1])
self.number_of_days = int(nums[2])
second_line = f.readline()
book_data = second_line.split(' ')
self.books = []
for book in book_data:
self.books.append(book)
self.libraries = []
c = 0
line = f.readline()
while (line != '' and line != '\n'):
lib_data = line.split(' ')
line = f.readline()
data = line.split(' ')
lib_books = []
for i in data:
lib_books.append(int(i))
lib_books.sort(key = lambda x : self.books[x], reverse=True)
#weight = self.calc_weight(self.books, lib_books, lib_data[1], lib_data[2])
weight = 0
lib = Library(c, lib_data[0], lib_data[1], lib_data[2], lib_books, weight)
lib.weight = self.calc_weight(lib, self.books)
c += 1
#lib.sort() #???
self.libraries.append(lib)
line = f.readline()
f.close()
#def calc_weight(self, book_scores, lib_books, signup, shipping):
def calc_weight(self, lib, book_scores):
total_score = 0
for book in lib.books:
total_score += int(book_scores[book])
return (total_score/int(lib.signup))*int(lib.shipping)