display % with hidden themes
This commit is contained in:
parent
8b4a1c65aa
commit
6600d7ffb7
|
@ -28,20 +28,26 @@ def get_hidden_themes(viewings, token_id, token_secret):
|
|||
|
||||
# Add hidden themes
|
||||
for date, data in viewings_filtered_watch_date.items():
|
||||
hidden_themes = set()
|
||||
keyword_counts = {}
|
||||
|
||||
if len(data['viewings']) > 1:
|
||||
viewings_keywords = []
|
||||
|
||||
for viewing in data['viewings']:
|
||||
if 'keywords' in viewing:
|
||||
viewings_keywords.append(set(viewing['keywords']))
|
||||
for keyword in viewing['keywords']:
|
||||
if keyword in keyword_counts.keys():
|
||||
keyword_counts[keyword] += 1
|
||||
else:
|
||||
keyword_counts[keyword] = 1
|
||||
|
||||
if len(viewings_keywords) > 1:
|
||||
hidden_themes = set.intersection(*viewings_keywords)
|
||||
keyword_counts = {k: v for k, v in sorted(keyword_counts.items(), key=lambda item: item[1], reverse=True)}
|
||||
hidden_themes = {}
|
||||
|
||||
if hidden_themes != set():
|
||||
viewings_filtered_watch_date[date]['hidden_themes'] = list(hidden_themes)
|
||||
for keyword in keyword_counts:
|
||||
rating = float(keyword_counts[keyword]) / float(len(data['viewings']))
|
||||
if rating > 0.5:
|
||||
hidden_themes[keyword] = rating
|
||||
|
||||
viewings_filtered_watch_date[date]['hidden_themes'] = hidden_themes
|
||||
|
||||
return viewings_filtered_watch_date
|
||||
|
||||
|
@ -62,7 +68,11 @@ def build_page(hidden_themes):
|
|||
row_data = []
|
||||
row_data.append(str(date))
|
||||
row_data.append(VCinemaUtils.get_film_list(data['viewings']))
|
||||
row_data.append(("<br>".join(k for k in sorted(data['hidden_themes']))) if 'hidden_themes' in data else "N/A")
|
||||
if 'hidden_themes' in data and data['hidden_themes'] != {}:
|
||||
row_data.append(("<br>".join(
|
||||
"{} ({}%)".format(k, data['hidden_themes'][k] * 100) for k in sorted(data['hidden_themes']))))
|
||||
else:
|
||||
row_data.append("N/A")
|
||||
|
||||
table += " | ".join(row_data)
|
||||
|
||||
|
|
Loading…
Reference in New Issue