Added a popular tags feature, greatly cleaned up code, commented spots
This commit is contained in:
@@ -16,26 +16,5 @@ class BuildTotalStatsModel(StatsModel):
|
||||
# Posts ranked from most popular to least popular by notes within each month and year.
|
||||
top_post_urls_by_month_and_year: Dict[str, List[str]] = field(init=False)
|
||||
|
||||
# Tags ranked from most popular to least popular by notes.
|
||||
most_popular_tags: List[Dict[str, Any]] = field(default_factory=list)
|
||||
|
||||
def __post_init__(self):
|
||||
super().__post_init__()
|
||||
self.most_popular_tags = self.determine_most_popular_tags()
|
||||
|
||||
def determine_most_popular_tags(self) -> List[Dict[str, Any]]:
|
||||
tag_dict: Dict[str, Any] = {}
|
||||
for post_key in self.original_post_map:
|
||||
post = self.original_post_map[post_key]
|
||||
tags = post['tags']
|
||||
for tag in tags:
|
||||
if tag in tag_dict:
|
||||
tag_dict[tag] = {
|
||||
'tag': tag, 'note_count': tag_dict[tag] + post['note_count']}
|
||||
else:
|
||||
tag_dict[tag] = {'tag': tag,
|
||||
'note_count': post['note_count']}
|
||||
|
||||
tag_list = sorted(list(tag_dict.values()),
|
||||
key=itemgetter('note_count'), reverse=True)
|
||||
return tag_list
|
||||
super().__post_init__()
|
||||
Reference in New Issue
Block a user