Fix word cloud font issue and improve logs (#1747)

This commit is contained in:
Greg Kaleka
2025-04-12 19:36:40 -04:00
committed by GitHub
parent 6b58dc3692
commit 5610f14f4c
7 changed files with 16 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
WORDCLOUD_FONT = "notosans_mono.woff"
WORDCLOUD_FONT = "NotoSansMono-Regular.ttf"
WEB_ANALYTICS_DOMAIN = "preview.boost.org"
WEB_ANALYTICS_API_URL = (
f"https://plausible.io/api/stats/{WEB_ANALYTICS_DOMAIN}/top-stats/?period=custom"

View File

@@ -6,6 +6,7 @@ from datetime import datetime
import psycopg2
from django.conf import settings
from django.contrib.staticfiles import finders
from django.db.models import Count
from django.db.models.functions import ExtractWeek, ExtractIsoYear
from matplotlib import pyplot as plt
@@ -26,13 +27,19 @@ def generate_wordcloud(version: Version) -> tuple[str | None, list]:
Returns:
Tuple of (base64_encoded_png_string, wordcloud_top_words)
"""
font_relative_path = f"font/{WORDCLOUD_FONT}"
font_full_path = finders.find(font_relative_path)
if not font_full_path:
raise FileNotFoundError(f"Could not find font at {font_relative_path}")
wc = WordCloud(
mode="RGBA",
background_color=None,
width=1400,
height=700,
stopwords=STOPWORDS | SiteSettings.load().wordcloud_ignore_set,
font_path=f"{settings.STATIC_ROOT}/font/{WORDCLOUD_FONT}",
font_path=font_full_path,
)
word_frequencies = {}
for content in get_mail_content(version):