Merge pull request #44 from web3privacy/dk/fix-rating-percentage

Dk/fix rating percentage
This commit is contained in:
DanielKlein 2024-09-25 20:39:50 +02:00 committed by GitHub
commit beeeed3acc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 25 additions and 16 deletions

View file

@ -165,7 +165,7 @@ const projectItems: { label: string | string[], type: string, rating?: ProjectRa
</div> </div>
<ProjectRating <ProjectRating
v-if="projectItem.type! === 'rating' && projectItem.rating" v-if="projectItem.type! === 'rating' && projectItem.rating"
:percentage="projectItem.rating.points" :percentage="projectItem.rating.percentagePoints"
:rating="projectItem.rating" :rating="projectItem.rating"
:type="projectItem.rating.type" :type="projectItem.rating.type"
/> />
@ -210,7 +210,7 @@ const projectItems: { label: string | string[], type: string, rating?: ProjectRa
</div> </div>
<ProjectRating <ProjectRating
v-if="(filter.sortby === 'openess' || filter.sortby === 'technology' || filter.sortby === 'privacy') && project.ratings?.find((r) => r.type === filter.sortby) && !isLargeScreen" v-if="(filter.sortby === 'openess' || filter.sortby === 'technology' || filter.sortby === 'privacy') && project.ratings?.find((r) => r.type === filter.sortby) && !isLargeScreen"
:percentage="project.ratings.find((r) => r.type === filter.sortby)!.points" :percentage="project.ratings.find((r) => r.type === filter.sortby)!.percentagePoints"
:rating="project.ratings.find((r) => r.type === filter.sortby)!" :rating="project.ratings.find((r) => r.type === filter.sortby)!"
compact compact
/> />

View file

@ -215,7 +215,7 @@ const logo = props.project?.logos?.at(0)?.url
</p> </p>
<ProjectRating <ProjectRating
:rating="rating" :rating="rating"
:percentage="rating.points" :percentage="rating.percentagePoints"
:disable-popover="!isLargeScreen" :disable-popover="!isLargeScreen"
compact compact
:selected="rating.type === selectedMobileRating?.type && !isLargeScreen" :selected="rating.type === selectedMobileRating?.type && !isLargeScreen"
@ -267,7 +267,7 @@ const logo = props.project?.logos?.at(0)?.url
> >
<ProjectRating <ProjectRating
:rating="selectedMobileRating" :rating="selectedMobileRating"
:percentage="selectedMobileRating.points" :percentage="selectedMobileRating.percentagePoints"
:disable-popover="!isLargeScreen" :disable-popover="!isLargeScreen"
compact compact
show-only-popover show-only-popover

View file

@ -64,7 +64,7 @@ defineProps<{
bold bold
title="Compliance with" title="Compliance with"
> >
{{ project.compliance ? 'YES' : 'NO' }} {{ project.compliance ? project.compliance : 'NO' }}
</ProjectInfoItem> </ProjectInfoItem>
<ProjectInfoItem <ProjectInfoItem
:check-undefined="project.tracebility?.sign_in_type_requirments" :check-undefined="project.tracebility?.sign_in_type_requirments"

View file

@ -14,16 +14,16 @@ const props = defineProps<{
const emits = defineEmits(['selected']) const emits = defineEmits(['selected'])
const colors = [ const colors = [
'#ff0000', // 0-10% '#EA171D', // 0-10%
'#ff4500', // 11-20% '#FB2D00', // 11-20%
'#ff8c00', // 21-30% '#FD6515', // 21-30%
'#ffd700', // 31-40% '#FD941A', // 31-40%
'#adff2f', // 41-50% '#FECD0A', // 41-50%
'#7fff00', // 51-60% '#FFD806', // 51-60%
'#00ff00', // 61-70% '#D2EF1F', // 61-70%
'#32cd32', // 71-80% '#95DF1C', // 71-80%
'#00fa9a', // 81-90% '#42FF00', // 81-90%
'#00ffff', // 91-100% '#42FF00', // 91-100%
] ]
const backgroundColorByScore = computed(() => { const backgroundColorByScore = computed(() => {

View file

@ -233,6 +233,7 @@ export const useData = defineStore('data', () => {
const generateProjectRating = (project: Project) => { const generateProjectRating = (project: Project) => {
const projectRatings: ProjectRating[] = ranks.value?.map((rank) => { const projectRatings: ProjectRating[] = ranks.value?.map((rank) => {
let rankPoints = 0 let rankPoints = 0
let maxPoints = 0
const ratingStats: ProjectRatingItem[] = rank.references?.map((ref) => { const ratingStats: ProjectRatingItem[] = rank.references?.map((ref) => {
let isValid = false let isValid = false
@ -240,6 +241,7 @@ export const useData = defineStore('data', () => {
let value let value
let positive let positive
let negative
if (ref.condition.minLength !== undefined) { if (ref.condition.minLength !== undefined) {
value = (field as any[])?.length value = (field as any[])?.length
@ -259,12 +261,17 @@ export const useData = defineStore('data', () => {
if (value !== undefined) if (value !== undefined)
isValid = !!value isValid = !!value
} }
if (ref.field === 'compliance') {
negative = value
}
rankPoints += isValid ? ref.points : 0 rankPoints += isValid ? ref.points : 0
maxPoints += ref.points
return { return {
isValid, isValid,
label: ref.label.name, label: ref.label.name,
positive: positive ? positive : ref.label.positive, positive: positive ? positive : ref.label.positive,
negative: ref.label.negative, negative: negative ? negative : ref.label.negative,
value, value,
} as ProjectRatingItem } as ProjectRatingItem
}) })
@ -273,6 +280,7 @@ export const useData = defineStore('data', () => {
name: rank.name, name: rank.name,
items: ratingStats, items: ratingStats,
points: rankPoints, points: rankPoints,
percentagePoints: rankPoints / maxPoints * 100,
} }
}) })

View file

@ -165,6 +165,7 @@ export interface ProjectRating {
name: string name: string
items: ProjectRatingItem[] items: ProjectRatingItem[]
points: number points: number
percentagePoints: number
} }
export interface ProjectRatingItem { export interface ProjectRatingItem {