Skip to content

Commit

Permalink
Controversy: be defensive against negative ups/downs (bad data)
Browse files Browse the repository at this point in the history
  • Loading branch information
umbrae committed Jun 18, 2014
1 parent 6ced69c commit 95be363
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion r2/r2/lib/db/_sorts.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ cpdef double _hot(long ups, long downs, double date):

cpdef double controversy(long ups, long downs):
"""The controversy sort."""
if downs == 0 or ups == 0:
if downs <= 0 or ups <= 0:
return 0

magnitude = ups + downs
Expand Down
2 changes: 1 addition & 1 deletion sql/functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ create or replace function score(ups integer, downs integer) returns integer as
$$ language sql immutable;

create or replace function controversy(ups integer, downs integer) returns float as $$
select CASE WHEN $1 = 0 or $2 = 0 THEN 0
select CASE WHEN $1 <= 0 or $2 <= 0 THEN 0
WHEN $1 > $2 THEN power($1 + $2, cast($2 as float) / $1)
ELSE power($1 + $2, cast($1 as float) / $2)
END;
Expand Down

0 comments on commit 95be363

Please sign in to comment.