]> ruin.nu Git - ndwebbie.git/blob - database/functions/covop_alert.sql
Updates for round 100
[ndwebbie.git] / database / functions / covop_alert.sql
1 CREATE OR REPLACE FUNCTION covop_alert(secs integer, strucs integer, roids integer
2         , guards integer, gov text, population integer) RETURNS integer
3         AS $_$
4         SELECT ((50 + COALESCE($4*5.0/($3+1.0),$6))
5                 * (1.0+2*LEAST(COALESCE($1::float/CASE $2
6                         WHEN 0 THEN 1 ELSE $2 END,$6),0.30)
7                         + (CASE $5
8                                 WHEN 'Dic' THEN 0.20
9                                 WHEN 'Feu' THEN -0.20
10                                 WHEN 'Uni' THEN -0.10
11                                 ELSE 0
12                         END) + $6/100.0
13                 ))::integer;
14 $_$
15         LANGUAGE sql IMMUTABLE;