dataforgoodfr / 12_taxobservatory_dataviz

Repository containing the app for visualizing declared taxes data present in Country-by-country reports
https://www.taxplorer.eu/
MIT License
0 stars 2 forks source link

Ta/fix wordcloud #58

Closed anquetos closed 3 months ago

anquetos commented 3 months ago

Goal

Remove usage of word_cloud library which was causing a resource warning :

ResourceWarning: unclosed file <_io.TextIOWrapper name='C:\\Users\\thoma\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\python-template-Sk64sqGT-py3.12\\Lib\\site-packages\\wordcloud\\stopwords' mode='r' encoding='cp1252'>
  STOPWORDS = set(map(str.strip, open(os.path.join(FILE, 'stopwords')).readlines()))
ResourceWarning: Enable tracemalloc to get the object allocation traceback

This issue is still opened on the repository (https://github.com/amueller/word_cloud/issues/764).

Solution

The word cloud is now created directly with the Pillow library and its ImageDraw and ImageFont modules.

Since it was necessary to specify the ttf file to load in the ImageDraw.truetype() function, font management has been changed from Google API to a local ressource folder app/assets/fonts.

Other ressources of the project as images or CSS files have also been moved to the assets folder.

gaudinnicolas commented 3 months ago

@anquetos , ce serait cool d'intégrer https://github.com/dataforgoodfr/12_taxobservatory_dataviz/pull/45 à ta PR avant merge. d'après ce que j'ai vu il y a aura quelques conflits à gérer mais principalement des paths. et vu le nouveau assets, c'est une bonne occasion. t'en penses quoi?

anquetos commented 3 months ago

@gaudinnicolas, oui ce serait bien. Par contre je ne sais pas trop comment faire pour l'intégrer, peux-tu m'aiguiller ?

@anquetos tu peux prendre le zip de https://github.com/QuentinMadura/12_taxobservatory_dataviz/tree/main et copier les images dans assets (remplacer existantes) et il y a 3 fichiers à modifier car 2 images ont été transformées en jpg d'après https://github.com/QuentinMadura/12_taxobservatory_dataviz/commit/4025c3908511f544a2a2c604e3faf955c548c000

anquetos commented 3 months ago

@gaudinnicolas, ah ok, tout simplement. Je pensais qu'il y avait moyen de faire un truc via GitHub mais c'est plus simple comme ça. Je le ferai demain matin.

anquetos commented 3 months ago

Update