Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to calculate seasonal uncertainty reset - Allow inactive users to have larger reset #540

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jauggy
Copy link
Member

@jauggy jauggy commented Dec 9, 2024

Changes

Adds an sql function to allow calculation of seasonal uncertainty reset. The function can be called via Marek's sql season uncertainty script (after adjustments). If you have been not playing for a long time, your uncertainty will reset more. See comments in function for full details.

Testing

Run the below command.

mix ecto.migrate

Check the new function calculate_season_uncertainty exists using a database viewer:
speg3jof

Then you can run the seasonal reset task

mix teiserver.seasonal_uncertainty_reset_task 5

5 is the target uncertainty

Test Marek's sql script

This is optional. The mix task might be just as fast as Marek's script. Marek's script is below.

@jauggy jauggy force-pushed the jauggy/sql-function-calc-uncertainty branch from 14ec2d6 to ef594b2 Compare December 9, 2024 21:49
@jauggy
Copy link
Member Author

jauggy commented Dec 9, 2024

To test the function works, we shall modify Marek's season uncertainty reset sql from: https://gist.github.com/p2004a/ff3f2b6d46d143b085fe495b73e41e2e

Create a test.sql file with contents:

START TRANSACTION ISOLATION LEVEL SERIALIZABLE;

-- Set it however we want
\set uncertainty_target 5.0
\set new_uncertainty calculate_season_uncertainty(uncertainty, last_updated, :uncertainty_target)
-- From https://github.com/beyond-all-reason/teiserver/blob/master/lib/teiserver/battle/libs/balance_lib.ex#L505
\set new_rating GREATEST(0, skill - :new_uncertainty)
-- From https://github.com/beyond-all-reason/teiserver/blob/master/lib/teiserver/battle/libs/balance_lib.ex#L569
\set new_leaderboard_rating skill - 3 * :new_uncertainty

INSERT INTO teiserver_game_rating_logs (inserted_at, rating_type_id, user_id, value)
SELECT
    now(),
    rating_type_id,
    user_id,
    JSON_BUILD_OBJECT(
        'skill', skill,
        'reason', 'Uncertainty minimum override',
        'uncertainty', :new_uncertainty,
        'rating_value', :new_rating,
        'skill_change', 0.0,
        'uncertainty_change', :new_uncertainty - uncertainty,
        'rating_value_change', :new_rating - rating_value
    )
FROM teiserver_account_ratings;

UPDATE teiserver_account_ratings SET
    last_updated = now(),
    uncertainty = :new_uncertainty,
    rating_value = :new_rating,
    leaderboard_rating = :new_leaderboard_rating;

COMMIT; -- Switch to COMMIT to do it for real;

Now you can run this script using commandline psql locally (won't work with a dbviewer):

 psql -d teiserver_dev -U teiserver_dev -W -h 127.0.0.1 -f test.sql

The password for teiserver_dev is 123456789.
It will update the account_ratings table with new uncertainties (check the last_updated column changed).

@jauggy jauggy marked this pull request as ready for review December 10, 2024 04:35
@NortySpock
Copy link
Contributor

Worked when I tried it on my machine, it was easy to follow the directions.

It didn't explode, so seems good to me.

@jauggy jauggy changed the title Add function to calculate seasonal uncertainty Add function to calculate seasonal uncertainty reset - Allow inactive users to have larger reset Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants