mirror of
https://github.com/web3privacy/explorer-app.git
synced 2024-10-15 16:46:26 +02:00
fix: final percentage
This commit is contained in:
parent
9ef956fe63
commit
bf333c66f4
1 changed files with 10 additions and 4 deletions
|
@ -61,10 +61,16 @@ export const useData = defineStore('data', () => {
|
||||||
ranks: Rank[]
|
ranks: Rank[]
|
||||||
}>('/api/data')
|
}>('/api/data')
|
||||||
data.projects.forEach(project => project.ratings = generateProjectRating(project))
|
data.projects.forEach(project => project.ratings = generateProjectRating(project))
|
||||||
projects.value = data.projects.map(project => ({
|
projects.value = data.projects.map((project) => {
|
||||||
|
const totalPoints = project.ratings?.reduce((a, b) => a + b.percentagePoints, 0) || 0
|
||||||
|
const numberOfRatings = project.ratings?.length || 1 // Avoid division by zero
|
||||||
|
const averagePercentage = totalPoints / numberOfRatings
|
||||||
|
return {
|
||||||
...project,
|
...project,
|
||||||
percentage: Math.round((project.ratings?.reduce((a, b) => a + b.points, 0) || 0) / 1.5),
|
percentage: Math.min(Math.max(Math.round(averagePercentage), 0), 100), // Ensure within 0-100%
|
||||||
})).filter(p => p.name)
|
}
|
||||||
|
}).filter(p => p.name)
|
||||||
|
console.log(projects.value.filter(p => p.name === 'ETHBerlin'))
|
||||||
const projectCategories = projects.value.map(p => p.categories).flat()
|
const projectCategories = projects.value.map(p => p.categories).flat()
|
||||||
categories.value = data.categories.filter(c => projectCategories.includes(c.id))
|
categories.value = data.categories.filter(c => projectCategories.includes(c.id))
|
||||||
usecases.value = data.usecases
|
usecases.value = data.usecases
|
||||||
|
|
Loading…
Reference in a new issue