-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.py
44 lines (37 loc) · 1.39 KB
/
library.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
import operator
class Library(object):
def __init__(self, idx, nBook, nSign, nScan, books):
self.id = idx
self.nBook = nBook
self.nSign = nSign
self.nScan = nScan
self.books = list(reversed(sorted(books, key=operator.attrgetter('score')) ))
self.tempBooks = self.books[:]
self.registered = False
self.registeredDay = None
self.solBooks = []
def predMaxScore(self, nDays, readBookSet):
restDays = nDays - self.nSign
if restDays < 0:
return 0, []
unReadBooks = set([book.id for book in self.tempBooks]) - readBookSet
newBooks = []
for book in self.tempBooks:
if book.id in unReadBooks:
newBooks.append(book)
self.tempBooks = newBooks
sumScore = 0
bookCap = restDays*self.nScan
readBooks= self.tempBooks[:bookCap]
readBooksId=[book.id for book in self.tempBooks[:bookCap]]
for book in readBooks:
sumScore += book.score
return float(sumScore)/(float(self.nSign)**2), readBooksId
def __repr__(self):
return "Lib[{}:{}:{}--{}]".format(self.nBook, self.nSign, self.nScan, self.books)
class Book(object):
def __init__(self, id, score, scanned=False):
self.id = id
self.score = score
def __repr__(self):
return "Book[{}:{}]".format(self.id, self.score)