]> de.git.xonotic.org Git - xonotic/xonstatdb.git/blobdiff - scripts/update_elos.sql
Add table definitions.
[xonotic/xonstatdb.git] / scripts / update_elos.sql
index 087f21361e5f5f46ff581c2c15aa9cd23c54e0a5..bda0ae25900fd0d921ac94a3423985b348b40fff 100644 (file)
@@ -1,5 +1,12 @@
 begin;
-  update player_elos
-  set elo=greatest(elo-1, 100.00)
-  where update_dt < (current_timestamp at time zone 'UTC' - interval '30 days');
+  update player_elos pe
+  set elo=greatest(100, elo - ((current_date - (update_dt::date)-31)/7+1))
+  where update_dt < (current_timestamp at time zone 'UTC' - interval '30 days')
+  and not exists (
+    select 1
+    from player_elos
+    where player_id = pe.player_id
+    and update_dt >= (current_timestamp at time zone 'UTC' - interval '30 days')
+  )
+  and elo != 100;
 end;