-
Notifications
You must be signed in to change notification settings - Fork 3
feat(graph): categories repartition graph #297
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
base: main
Are you sure you want to change the base?
The head ref may contain hidden characters: "122-vue-densemble-graphique-r\u00E9partition-par-cat\u00E9gories"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,38 @@ | ||
| import { getPercentage } from "@/shared/utils/maths"; | ||
| import { PostComment } from "@/shared/model/post/Post"; | ||
| import { isCommentHateful } from "@/shared/utils/post-util"; | ||
| import { | ||
| HatefulCategory, | ||
| HatefulCategoryLabels, | ||
| } from "@/shared/model/HatefulCategory"; | ||
|
|
||
| export type CategoryStat = { | ||
| label: string; | ||
| count: number; | ||
| }; | ||
|
|
||
| const HATEFUL_CATEGORIES = Object.values(HatefulCategory).filter( | ||
| (c) => c !== HatefulCategory.ABSENCE_DE_CYBERHARCELEMENT, | ||
| ); | ||
|
|
||
| const ABSENCE_LABEL = | ||
| HatefulCategoryLabels[HatefulCategory.ABSENCE_DE_CYBERHARCELEMENT]; | ||
|
|
||
| export const getCategoryStats = ( | ||
| postComments: readonly PostComment[], | ||
| ): CategoryStat[] => { | ||
| const hatefulComments = postComments.filter( | ||
| (c) => c.classification?.[0] && c.classification[0] !== ABSENCE_LABEL, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔧 Les deux pourraît déléguer à une méthode isCategoryHateful(categoryLabel: string): boolean |
||
| ); | ||
| return HATEFUL_CATEGORIES.map((cat) => ({ | ||
| label: HatefulCategoryLabels[cat], | ||
| count: hatefulComments.filter( | ||
| (c) => c.classification?.[0] === HatefulCategoryLabels[cat], | ||
| ).length, | ||
| })) | ||
| .filter((s) => s.count > 0) | ||
| .sort((a, b) => b.count - a.count); | ||
| }; | ||
|
|
||
| export type HatefulAuthorStats = { | ||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Etant donnée que le backend renvoie les labels de catégories directement Je ne suis pas sûr que HatefulCategory tel que définit actuellement est beaucoup de sens. Mais bon ce n'est pas gràave pour cette PR.