Added stats
This commit is contained in:
@@ -101,6 +101,12 @@ class Lyrics(WithId):
|
||||
)
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Stats:
|
||||
times_played: int
|
||||
sessions_played: list[Session]
|
||||
|
||||
|
||||
@dataclasses.dataclass
|
||||
class Tema:
|
||||
id: int | None = None
|
||||
@@ -117,7 +123,7 @@ class Tema:
|
||||
modification_date: datetime.datetime = dataclasses.field(default_factory=datetime.datetime.now)
|
||||
creation_date: datetime.datetime = dataclasses.field(default_factory=datetime.datetime.now)
|
||||
# Stats
|
||||
played: list[Session] = dataclasses.field(default_factory=list)
|
||||
stats: Stats | None = None
|
||||
|
||||
def compute_ngrams(self):
|
||||
self.ngrams = ngrams.get_text_ngrams(self.title, *self.alternatives)
|
||||
@@ -126,5 +132,13 @@ class Tema:
|
||||
self.compute_ngrams()
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def _is_score(link: Link) -> bool:
|
||||
if link.content_type is not ContentType.PARTITURA:
|
||||
return False
|
||||
if link.link_type is LinkType.PDF:
|
||||
return link.url.startswith("/")
|
||||
return link.link_type is LinkType.IMAGE
|
||||
|
||||
def score(self) -> Link | None:
|
||||
return next(filter(lambda l: l.content_type is ContentType.PARTITURA and l.url.startswith('/'), self.links), None)
|
||||
return next(filter(self._is_score, self.links), None)
|
||||
|
||||
Reference in New Issue
Block a user