add bayes average
This commit is contained in:
parent
93bd5fb3e9
commit
8861de969a
@ -18,6 +18,30 @@ ORDER BY l.created_at ASC
|
|||||||
LIMIT $1;
|
LIMIT $1;
|
||||||
|
|
||||||
|
|
||||||
|
-- https://fulmicoton.com/posts/bayesian_rating/
|
||||||
|
-- SELECT
|
||||||
|
-- *,
|
||||||
|
-- (SELECT 5 * 4 + coalesce(critic_score, 0) * coalesce(critic_count, 0) / 5 + coalesce(critic_count, 0)) as critic_bayes,
|
||||||
|
-- (SELECT 50 + coalesce(user_score, 0) * coalesce(user_count, 0) / 50 + coalesce(user_count, 0)) as user_bayes,
|
||||||
|
-- ((SELECT 50 + coalesce(user_score, 0) * coalesce(user_count, 0) / 50 + coalesce(user_count, 0)) + (SELECT 5 * 4 + coalesce(critic_score, 0) * coalesce(critic_count, 0) / 5 + coalesce(critic_count, 0)) ) / 2 as avg_bayes
|
||||||
|
-- FROM (
|
||||||
|
-- SELECT
|
||||||
|
-- l.id,
|
||||||
|
-- name,
|
||||||
|
-- thumbnail,
|
||||||
|
-- re.regency_name,
|
||||||
|
-- (SELECT SUM(score) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_score,
|
||||||
|
-- (SELECT COUNT(id) from reviews re where re.is_from_critic = true and re.location_id = l.id) as critic_count,
|
||||||
|
-- (SELECT SUM(score) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_score,
|
||||||
|
-- (SELECT COUNT(id) from reviews re where re.is_from_critic = false and re.location_id = l.id) as user_count
|
||||||
|
-- FROM locations l
|
||||||
|
-- JOIN regencies re on re.id = l.regency_id
|
||||||
|
-- WHERE approved_by IS NOT NULL) iq1
|
||||||
|
-- ORDER BY avg_bayes DESC
|
||||||
|
-- LIMIT $1
|
||||||
|
-- OFFSET $2;
|
||||||
|
|
||||||
|
|
||||||
-- name: GetLocation :one
|
-- name: GetLocation :one
|
||||||
SELECT * FROM locations
|
SELECT * FROM locations
|
||||||
WHERE id = $1;
|
WHERE id = $1;
|
||||||
|
Loading…
Reference in New Issue
Block a user