bounswe / bounswe2023group2

Disaster Response Platform
9 stars 2 forks source link

Backend - Sort by Reliability #828

Closed higurbuzz closed 9 months ago

higurbuzz commented 9 months ago

Issue Description

Sort by reliability should be provided instead upvote/downvote count.

Deadline of the Issue

24.12.2023

Reviewer

None

rburaksaritas commented 9 months ago

See #894.

Overview

This PR adds a reliability field to the get all method responses of resources, needs, and events. The reliability score is calculated based on the upvotes and downvotes for each item. It is used to assess the credibility and trustworthiness of the information provided by users.

Reliability Score Calculation

The reliability score is calculated using the Wilson Score Interval, a statistical method that takes into account the proportion of upvotes to total votes while considering the %95 confidence interval. The formula is:

z = 1.96  # 95% confidence interval
phat = upvotes / total_votes
reliability = (phat + z^2 / (2 * total_votes) - z * sqrt((phat * (1 - phat) + z^2 / (4 * total_votes)) / total_votes)) / (1 + z^2 / total_votes)

The reliability score ranges from 0 to 1, with higher values indicating higher reliability. Items with more upvotes and a higher proportion of upvotes to total votes will have a higher reliability score, reflecting greater trustworthiness.

Sorting

To sort by reliability, simply add sort_by=reliability&order=desc or sort_by=reliability&order=asc to the query.