Able to get own poll answer & poll answer percentage

This commit is contained in:
2025-02-13 21:56:54 +08:00
parent 429ca64f9d
commit e16201a3ad
4 changed files with 28 additions and 4 deletions

View File

@ -49,8 +49,14 @@ func GetPollMetric(poll models.Poll) models.PollMetric {
byOptions[answer.Answer]++
}
byOptionsPercentage := make(map[string]float64)
for _, option := range poll.Options {
byOptionsPercentage[option.ID] = float64(byOptions[option.ID]) / float64(len(answers))
}
return models.PollMetric{
TotalAnswer: int64(len(answers)),
ByOptions: byOptions,
TotalAnswer: int64(len(answers)),
ByOptions: byOptions,
ByOptionsPercentage: byOptionsPercentage,
}
}