2023-08-02 16:44:51 +00:00
|
|
|
CREATE OR REPLACE FUNCTION hot_rank (score numeric, published timestamp without time zone)
|
2023-07-07 09:27:47 +00:00
|
|
|
RETURNS integer
|
|
|
|
AS $$
|
|
|
|
DECLARE
|
|
|
|
hours_diff numeric := EXTRACT(EPOCH FROM (timezone('utc', now()) - published)) / 3600;
|
|
|
|
BEGIN
|
|
|
|
IF (hours_diff > 0) THEN
|
2023-08-02 16:44:51 +00:00
|
|
|
RETURN floor(10000 * log(greatest (1, score + 3)) / power((hours_diff + 2), 1.8))::integer;
|
2023-07-07 09:27:47 +00:00
|
|
|
ELSE
|
|
|
|
RETURN 0;
|
|
|
|
END IF;
|
|
|
|
END;
|
|
|
|
$$
|
|
|
|
LANGUAGE plpgsql
|
|
|
|
IMMUTABLE PARALLEL SAFE;
|
|
|
|
|