Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Language analysis #44

Merged
merged 1 commit into from
Nov 5, 2023

Conversation

BloodyOcean
Copy link
Contributor

  • Add language analysis via matplotlib chart

- Add language analysis via matplotlib chart
@Salz0
Copy link
Owner

Salz0 commented Oct 29, 2023

Awesome, I will merge it when our Postgres is ready for setup, thanks a lot !

@Salz0
Copy link
Owner

Salz0 commented Oct 29, 2023

#22

Comment on lines +13 to +27
users_lst = list(flatten_tortoise_model(el) for el in User.all())

lang_counts = {}
for user in users_lst:
lang = user.language_code
if lang in lang_counts:
lang[lang] += 1
else:
lang[lang] = 1

# Sort the data by score
sorted_scores = sorted(lang_counts.items())

# Extract the scores and counts for the chart
scores, counts = zip(*sorted_scores)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use GROUP BY equivalent in tortoise-orm to basically get a dict[str, int] with all the languages and the COUNT(*) of users who are using them.

From the top of my mind, the actual query would look like this:

language_counts: dict[str, int] = await User.all().group_by("language").values()

I would suggest looking into it and maybe refactoring. Although the minimal version is clearly here already.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, that will be a good improvement

@Salz0 Salz0 merged commit 5dfdf01 into Salz0:master Nov 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants