Add satisfaction check to DirectorWorker: Introduced a new field for tracking the last satisfaction check and updated the calculation logic to ensure it runs only once every 24 hours. Enhanced SQL query for updating satisfaction to include a salary gap calculation, improving the accuracy of satisfaction updates based on income and title of nobility.
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 1m30s
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 1m30s
This commit is contained in:
@@ -624,14 +624,45 @@ UPDATE falukant_data.director SET last_salary_payout = NOW() WHERE id = $1;
|
||||
"#;
|
||||
|
||||
pub const QUERY_UPDATE_SATISFACTION: &str = r#"
|
||||
WITH new_sats AS (
|
||||
SELECT d.id, ROUND(d.income::numeric / (c.title_of_nobility * POWER(1.231, AVG(k.knowledge) / 1.5)) * 100) AS new_satisfaction
|
||||
WITH salary_gap AS (
|
||||
SELECT
|
||||
d.id,
|
||||
d.employer_user_id,
|
||||
COALESCE(d.satisfaction, 100)::int AS old_satisfaction,
|
||||
(
|
||||
100.0
|
||||
- LEAST(
|
||||
200.0,
|
||||
(d.income::float8 / GREATEST(1.0, (c.title_of_nobility::float8 * POWER(1.231, AVG(k.knowledge) / 1.5)))) * 100.0
|
||||
)
|
||||
) AS gap_percent
|
||||
FROM falukant_data.director d
|
||||
JOIN falukant_data.knowledge k ON d.director_character_id = k.character_id
|
||||
JOIN falukant_data.character c ON c.id = d.director_character_id
|
||||
GROUP BY d.id, c.title_of_nobility, d.income
|
||||
GROUP BY d.id, d.employer_user_id, d.satisfaction, d.income, c.title_of_nobility
|
||||
),
|
||||
new_sats AS (
|
||||
SELECT
|
||||
sg.id,
|
||||
sg.employer_user_id,
|
||||
GREATEST(
|
||||
0,
|
||||
sg.old_satisfaction
|
||||
- CASE
|
||||
WHEN sg.gap_percent <= 0 THEN 0
|
||||
WHEN sg.gap_percent < 20 THEN 1
|
||||
WHEN sg.gap_percent < 50 THEN 2
|
||||
ELSE 3
|
||||
END
|
||||
)::int AS new_satisfaction
|
||||
FROM salary_gap sg
|
||||
)
|
||||
UPDATE falukant_data.director dir SET satisfaction = ns.new_satisfaction FROM new_sats ns WHERE dir.id = ns.id AND dir.satisfaction IS DISTINCT FROM ns.new_satisfaction RETURNING dir.employer_user_id;
|
||||
UPDATE falukant_data.director dir
|
||||
SET satisfaction = ns.new_satisfaction
|
||||
FROM new_sats ns
|
||||
WHERE dir.id = ns.id
|
||||
AND dir.satisfaction IS DISTINCT FROM ns.new_satisfaction
|
||||
RETURNING dir.employer_user_id;
|
||||
"#;
|
||||
|
||||
pub const QUERY_GET_DIRECTOR_USER: &str = r#"
|
||||
|
||||
Reference in New Issue
Block a user