Skip to content

Commit

Permalink
Merge pull request #1725 from Selevra/bugfix/player-stats-experience
Browse files Browse the repository at this point in the history
Fix calculation of gained XP in player stats
  • Loading branch information
minj authored Feb 29, 2024
2 parents c515989 + fa29a6e commit 10158d1
Show file tree
Hide file tree
Showing 54 changed files with 406 additions and 397 deletions.
16 changes: 8 additions & 8 deletions content/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,14 @@ PlayerStatsExperience.sum=Sum
PlayerStatsExperience.Experience=Experience
PlayerStatsExperience.PerformanceHistory=Performance history

PlayerStatsExperience.matchFriendly=Friendlies
PlayerStatsExperience.matchCupA=Cup
PlayerStatsExperience.matchCupB1=Emerald Challenger Cup
PlayerStatsExperience.matchCupB2=Ruby Challenger Cup
PlayerStatsExperience.matchCupB3=Sapphire Challenger Cup
PlayerStatsExperience.matchCupC=Consolation Cup
PlayerStatsExperience.matchQualification=Qualification
PlayerStatsExperience.matchLeague=League
PlayerStatsExperience.friendly=Friendlies
PlayerStatsExperience.cup=Cup
PlayerStatsExperience.challenger_cup_1=Emerald Challenger Cup
PlayerStatsExperience.challenger_cup_2=Ruby Challenger Cup
PlayerStatsExperience.challenger_cup_3=Sapphire Challenger Cup
PlayerStatsExperience.consolation_cup=Consolation Cup
PlayerStatsExperience.qualifier=Qualification
PlayerStatsExperience.series=League
PlayerStatsExperience.matchNtFriendly=NT friendlies
PlayerStatsExperience.matchNtFriendlyNew=NT friendlies
PlayerStatsExperience.matchMasters=Hattrick Masters
Expand Down
97 changes: 53 additions & 44 deletions content/information-aggregation/player-stats-experience.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,24 @@ Foxtrick.modules.PlayerStatsExperience = {
/** @typedef {'matchCup'|'matchCupA'|'matchCupB1'|'matchCupB2'|'matchCupB3'|'matchCupC'|'matchFriendly'|'matchLeague'|'matchMasters'|'matchNewbie'|'matchNtAfricaCup'|'matchNtAmericaCup'|'matchNtAsiaCup'|'matchNtEuropeCup'|'matchNtNationsCup'|'matchNtWildcard'|'matchNtWorldCup'|'matchQualification'|'matchSingleMatch'|'matchSingleMatchFast'|'matchTournament'|'matchTournamentFast'|'matchTournamentLadder'} MatchTypeClassRaw */

// eslint-disable-next-line max-len
/** @typedef {'matchCupA'|'matchCupB1'|'matchCupB2'|'matchCupB3'|'matchCupC'|'matchFriendly'|'matchLeague'|'matchMasters'|'matchNtContinental'|'matchNtContinentalKO'|'matchNtNationsCup'|'matchNtNationsCupKO'|'matchNtWildcard'|'matchNtWorldCup'|'matchQualification'|'matchNtFriendly'|'matchNtLeague'|'matchNtFinals'|'matchNtFriendlyNew'|'matchNtWorldCupFinals'} MatchTypeClass */
/** @typedef {'series'|'cup'|'challenger_cup_1'|'challenger_cup_2'|'challenger_cup_3'|'consolation_cup'|'friendly'|'qualifier'|'masters'|'nt_worldcup'|'nations_cup'|'nt_wildcard'|'nt_cup_europe'|'nt_cup_americas'|'nt_cup_africa'|'nt_cup_asia'|'nt_worldcup_u21'|'nations_cup_u21'|'nt_wildcard_u21'|'nt_cup_europe_u21'|'nt_cup_americas_u21'|'nt_cup_africa_u21'|'nt_cup_asia_u21'} GameIconClass */
// eslint-disable-next-line max-len
/** @typedef {'series'|'cup'|'challenger_cup_1'|'challenger_cup_2'|'challenger_cup_3'|'consolation_cup'|'friendly'|'qualifier'|'masters'|'matchNtContinental'|'matchNtContinentalKO'|'matchNtNationsCup'|'matchNtNationsCupKO'|'matchNtWildcard'|'matchNtWorldCup'|'matchNtFriendly'|'matchNtLeague'|'matchNtFinals'|'matchNtFriendlyNew'|'matchNtWorldCupFinals'} MatchTypeClass */

// don't randomly rename, parts of this are taken from hattrick using image classnames
/** @type {Record<MatchTypeClass, number>} */
XP: {
// assume international friendly as default, considered in min-max,
// minimum uses 1/2 of this value
matchFriendly: 0.7,
matchLeague: 3.5,
matchCupA: 7.0,
matchCupB1: 1.75,
matchCupB2: 1.75,
matchCupB3: 1.75,
matchCupC: 1.75,
matchQualification: 7,
matchMasters: 17.5,
friendly: 0.7,
series: 3.5,
cup: 7.0,
challenger_cup_1: 1.75,
challenger_cup_2: 1.75,
challenger_cup_3: 1.75,
consolation_cup: 1.75,
qualifier: 7,
masters: 17.5,

// globe: NaN,
// matchCup: NaN,
Expand Down Expand Up @@ -214,21 +216,25 @@ Foxtrick.modules.PlayerStatsExperience = {
// most games can be identified by the classname directly, NT needs some tricks
/**
* @param {HTMLTableRowElement} node
* @return {MatchTypeClassRaw}
* @return {GameIconClass}
*/
var getBasicGameType = function(node) {
var gametypeParent = node.querySelector('td.keyColumn');
var gameTypeImage = gametypeParent.querySelector('.iconMatchtype img');
return /** @type {MatchTypeClassRaw} */ (gameTypeImage.className);
var getGameIcon = function(node) {
var gameIconParent = node.querySelector('td.keyColumn');
var gameIconImage = gameIconParent.querySelector('.iconMatchtype img');
var gameIconSrc = gameIconImage.getAttribute('src');
const gameIconRegEx = /([\w-]+).svg/g;
var gameIcon = gameIconRegEx.exec(gameIconSrc)[1]; // first match is with ".svg", 2nd match is the group match without ".svg"
var gameIconWithoutDashes = gameIcon.replaceAll('-', '_');
return /** @type {GameIconClass} */ (gameIconWithoutDashes);
};

/**
* @param {MatchTypeClassRaw} raw
* @param {GameIconClass} gameIcon
* @return {MatchTypeClass}
*/
// eslint-disable-next-line complexity
var getNTType = function(raw) {
if (raw == 'matchFriendly') {
var getNTType = function(gameIcon) {
if (gameIcon == 'friendly') {
if (juniors)
// eslint-disable-next-line no-magic-numbers
return season >= 77 ? 'matchNtFriendlyNew' : 'matchNtFriendly';
Expand All @@ -237,21 +243,22 @@ Foxtrick.modules.PlayerStatsExperience = {
return season >= 78 ? 'matchNtFriendlyNew' : 'matchNtFriendly';
}

if (raw == 'matchLeague') {
// old NT
// oldies wc finals are in odd seasons, juniors in even seasons
if (!isFinalSeason)
return 'matchNtLeague';
// TODO: what is this type of game? Do we still need it?
// if (raw == 'matchLeague') {
// // old NT
// // oldies wc finals are in odd seasons, juniors in even seasons
// if (!isFinalSeason)
// return 'matchNtLeague';

let semifinal = date.getDay() == DAY_OF_SEMIS;
let final = date.getDay() === DAY_OF_FINAL;
if (week == WEEK_OF_FINALS && (semifinal || final))
return 'matchNtFinals';
// let semifinal = date.getDay() == DAY_OF_SEMIS;
// let final = date.getDay() === DAY_OF_FINAL;
// if (week == WEEK_OF_FINALS && (semifinal || final))
// return 'matchNtFinals';

return 'matchNtLeague';
}
// return 'matchNtLeague';
// }

if (raw == 'matchNtWorldCup') {
if (gameIcon.includes('nt_worldcup')) { // also catch u21, which has the addition "_u21" at the end
if (!isFinalSeason)
return 'matchNtWorldCup';

Expand All @@ -263,46 +270,48 @@ Foxtrick.modules.PlayerStatsExperience = {
return 'matchNtWorldCup';
}

if (raw == 'matchNtNationsCup') {
if (gameIcon.includes('nations_cup')) { // also catch u21, which has the addition "-u21" at the end
// weeks 14-16 in final season are KO
// eslint-disable-next-line no-magic-numbers
return isFinalSeason && week >= 14
? 'matchNtNationsCupKO'
: 'matchNtNationsCup';
}

/** @type {MatchTypeClassRaw[]} */
/** @type {GameIconClass[]} */
const CONT_CUPS = [
'matchNtAfricaCup',
'matchNtAmericaCup',
'matchNtAsiaCup',
'matchNtEuropeCup',
'nt_cup_europe',
'nt_cup_americas',
'nt_cup_africa',
'nt_cup_asia',
];
if (CONT_CUPS.includes(raw)) {
if (CONT_CUPS.includes(gameIcon)) {
// weeks 11-12 are KO
// eslint-disable-next-line no-magic-numbers
return !isFinalSeason && week >= 11
? 'matchNtContinentalKO'
: 'matchNtContinental';
}

return raw in module.XP ? /** @type {MatchTypeClass} */ (raw) : null;
Foxtrick.log("WARNING: Unmatched gameIcon for NT", gameIcon); // TODO: Can this even happen?

return gameIcon in module.XP ? /** @type {MatchTypeClass} */ (gameIcon) : null;
};

var cls = getBasicGameType(node);
var gameIcon = getGameIcon(node);
var isNT = isNTMatch(node);

if (isNT) {
let nt = getNTType(cls);
let nt = getNTType(gameIcon);
if (nt != null)
return nt;
}

var ret = cls in module.XP ? /** @type {MatchTypeClass} */ (cls) : null;
var ret = gameIcon in module.XP ? /** @type {MatchTypeClass} */ (gameIcon) : null;

if (ret === null) {
// report failure
Foxtrick.log(new Error(`Type dection failed: ${cls},
Foxtrick.log(new Error(`Type dection failed: ${gameIcon},
d=${isodate} (${season}/${week}), isNT=${isNT}, junions=${juniors}
`));
}
Expand Down Expand Up @@ -331,7 +340,7 @@ Foxtrick.modules.PlayerStatsExperience = {
*/
var getXPMinMaxDifference = function(ntMatch, xpGain, gameType) {
var dxp = { min: xpGain, max: xpGain };
if (!ntMatch && gameType == 'matchFriendly')
if (!ntMatch && gameType == 'friendly')
dxp.min /= 2;

return dxp;
Expand Down Expand Up @@ -441,7 +450,7 @@ Foxtrick.modules.PlayerStatsExperience = {
tdXP.textContent = xpGain.toFixed(PRECISION);
}

if (!ntMatch && gameType == 'matchFriendly' && minutes > 0) {
if (!ntMatch && gameType == 'friendly' && minutes > 0) {
tdXP.textContent =
(xpGain / 2.0).toFixed(PRECISION) + '/' + xpGain.toFixed(PRECISION);
}
Expand Down
8 changes: 4 additions & 4 deletions content/locale/ar/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,10 @@ PlayerStatsExperience.sum=المجموع
PlayerStatsExperience.Experience=الخبرة
PlayerStatsExperience.PerformanceHistory=تاريخ الأداء

PlayerStatsExperience.matchFriendly=الوديات
PlayerStatsExperience.matchCupA=الكأس
PlayerStatsExperience.matchQualification=تأهيلية
PlayerStatsExperience.matchLeague=دوري
PlayerStatsExperience.friendly=الوديات
PlayerStatsExperience.cup=الكأس
PlayerStatsExperience.qualifier=تأهيلية
PlayerStatsExperience.series=دوري
PlayerStatsExperience.matchNtFriendly=مباريات ودية للمنتخبات الوطنية
PlayerStatsExperience.matchNtFriendlyNew=مباريات ودية للمنتخبات الوطنية
PlayerStatsExperience.matchMasters=أبطال هاتريك
Expand Down
4 changes: 2 additions & 2 deletions content/locale/az/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ PlayerStatsExperience.NoSkillUpFound=Qeydə təcrübə-bacarıq olmadığından
PlayerStatsExperience.matches=Matçlar
PlayerStatsExperience.PerformanceHistory=Performans tarixi

PlayerStatsExperience.matchFriendly=Hazırlıq matçları
PlayerStatsExperience.matchCupA=Kubok
PlayerStatsExperience.friendly=Hazırlıq matçları
PlayerStatsExperience.cup=Kubok

#Series statistics

Expand Down
4 changes: 2 additions & 2 deletions content/locale/be/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ TransferHistoryFilters.all=Усе

PlayerStatsExperience.matches=Сустрэчы

PlayerStatsExperience.matchFriendly=Таварыскія
PlayerStatsExperience.matchCupA=Кубак
PlayerStatsExperience.friendly=Таварыскія
PlayerStatsExperience.cup=Кубак

#Series statistics

Expand Down
16 changes: 8 additions & 8 deletions content/locale/bg/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -564,14 +564,14 @@ PlayerStatsExperience.sum=Сума
PlayerStatsExperience.Experience=Опит
PlayerStatsExperience.PerformanceHistory=История на представянето

PlayerStatsExperience.matchFriendly=Приятелски мачове
PlayerStatsExperience.matchCupA=Купа
PlayerStatsExperience.matchCupB1=Купа Изумруд
PlayerStatsExperience.matchCupB2=Рубинена купа
PlayerStatsExperience.matchCupB3=Купа Сапфир
PlayerStatsExperience.matchCupC=Утешителна купа
PlayerStatsExperience.matchQualification=Бараж
PlayerStatsExperience.matchLeague=Лига
PlayerStatsExperience.friendly=Приятелски мачове
PlayerStatsExperience.cup=Купа
PlayerStatsExperience.challenger_cup_1=Купа Изумруд
PlayerStatsExperience.challenger_cup_2=Рубинена купа
PlayerStatsExperience.challenger_cup_3=Купа Сапфир
PlayerStatsExperience.consolation_cup=Утешителна купа
PlayerStatsExperience.qualifier=Бараж
PlayerStatsExperience.series=Лига
PlayerStatsExperience.matchNtFriendly=Национални приятелски
PlayerStatsExperience.matchNtFriendlyNew=Национални приятелски
PlayerStatsExperience.matchMasters=Хеттрик Мастърс
Expand Down
16 changes: 8 additions & 8 deletions content/locale/bs/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,14 @@ PlayerStatsExperience.sum=Zbroj
PlayerStatsExperience.Experience=Iskustvo
PlayerStatsExperience.PerformanceHistory=Prošle izvedbe

PlayerStatsExperience.matchFriendly=Prijateljske
PlayerStatsExperience.matchCupA=Kup
PlayerStatsExperience.matchCupB1=Kup regija
PlayerStatsExperience.matchCupB2=Kup mostova
PlayerStatsExperience.matchCupB3=Kup prijateljstva
PlayerStatsExperience.matchCupC=Utješni kup
PlayerStatsExperience.matchQualification=Kvalifikacije
PlayerStatsExperience.matchLeague=Liga
PlayerStatsExperience.friendly=Prijateljske
PlayerStatsExperience.cup=Kup
PlayerStatsExperience.challenger_cup_1=Kup regija
PlayerStatsExperience.challenger_cup_2=Kup mostova
PlayerStatsExperience.challenger_cup_3=Kup prijateljstva
PlayerStatsExperience.consolation_cup=Utješni kup
PlayerStatsExperience.qualifier=Kvalifikacije
PlayerStatsExperience.series=Liga
PlayerStatsExperience.matchNtFriendly=Nacionalni Tim prijateljska
PlayerStatsExperience.matchNtFriendlyNew=Nacionalni Tim prijateljska
PlayerStatsExperience.matchMasters=Hattrick Masters
Expand Down
16 changes: 8 additions & 8 deletions content/locale/ca/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,14 @@ PlayerStatsExperience.sum=Suma
PlayerStatsExperience.Experience=Experiència
PlayerStatsExperience.PerformanceHistory=Historial de rendiment

PlayerStatsExperience.matchFriendly=Amistosos
PlayerStatsExperience.matchCupA=Copa
PlayerStatsExperience.matchCupB1=Copa Maragda
PlayerStatsExperience.matchCupB2=Copa Robí
PlayerStatsExperience.matchCupB3=Copa Safir
PlayerStatsExperience.matchCupC=Copa de consolació
PlayerStatsExperience.matchQualification=Promoció
PlayerStatsExperience.matchLeague=Lliga
PlayerStatsExperience.friendly=Amistosos
PlayerStatsExperience.cup=Copa
PlayerStatsExperience.challenger_cup_1=Copa Maragda
PlayerStatsExperience.challenger_cup_2=Copa Robí
PlayerStatsExperience.challenger_cup_3=Copa Safir
PlayerStatsExperience.consolation_cup=Copa de consolació
PlayerStatsExperience.qualifier=Promoció
PlayerStatsExperience.series=Lliga
PlayerStatsExperience.matchNtFriendly=Amistosos selecció
PlayerStatsExperience.matchNtFriendlyNew=Amistosos selecció
PlayerStatsExperience.matchMasters=Hattrick Masters
Expand Down
16 changes: 8 additions & 8 deletions content/locale/cs/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,14 @@ PlayerStatsExperience.sum=Celkem
PlayerStatsExperience.Experience=Zkušenosti
PlayerStatsExperience.PerformanceHistory=Historie výkonů

PlayerStatsExperience.matchFriendly=Přáteláky
PlayerStatsExperience.matchCupA=Pohár
PlayerStatsExperience.matchCupB1=Pohár druhé šance (smaragdový)
PlayerStatsExperience.matchCupB2=Pohár druhé šance (rubínový)
PlayerStatsExperience.matchCupB3=Pohár druhé šance (safírový)
PlayerStatsExperience.matchCupC=Pohár útěchy
PlayerStatsExperience.matchQualification=Kvalifikace
PlayerStatsExperience.matchLeague=Liga
PlayerStatsExperience.friendly=Přáteláky
PlayerStatsExperience.cup=Pohár
PlayerStatsExperience.challenger_cup_1=Pohár druhé šance (smaragdový)
PlayerStatsExperience.challenger_cup_2=Pohár druhé šance (rubínový)
PlayerStatsExperience.challenger_cup_3=Pohár druhé šance (safírový)
PlayerStatsExperience.consolation_cup=Pohár útěchy
PlayerStatsExperience.qualifier=Kvalifikace
PlayerStatsExperience.series=Liga
PlayerStatsExperience.matchNtFriendly=Přáteláky NT
PlayerStatsExperience.matchNtFriendlyNew=Přáteláky NT
PlayerStatsExperience.matchMasters=Hattrick Masters
Expand Down
16 changes: 8 additions & 8 deletions content/locale/da/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,14 @@ PlayerStatsExperience.sum=Sum
PlayerStatsExperience.Experience=Rutine
PlayerStatsExperience.PerformanceHistory=Præstations historie

PlayerStatsExperience.matchFriendly=Venskabskampe
PlayerStatsExperience.matchCupA=Pokal
PlayerStatsExperience.matchCupB1=Smaragdturneringen
PlayerStatsExperience.matchCupB2=Rubinturneringen
PlayerStatsExperience.matchCupB3=Safirturneringen
PlayerStatsExperience.matchCupC=Underkoppen
PlayerStatsExperience.matchQualification=Kvalifikation
PlayerStatsExperience.matchLeague=Liga
PlayerStatsExperience.friendly=Venskabskampe
PlayerStatsExperience.cup=Pokal
PlayerStatsExperience.challenger_cup_1=Smaragdturneringen
PlayerStatsExperience.challenger_cup_2=Rubinturneringen
PlayerStatsExperience.challenger_cup_3=Safirturneringen
PlayerStatsExperience.consolation_cup=Underkoppen
PlayerStatsExperience.qualifier=Kvalifikation
PlayerStatsExperience.series=Liga
PlayerStatsExperience.matchNtFriendly=Landsholds venskabskampe
PlayerStatsExperience.matchNtFriendlyNew=Landsholds venskabskampe
PlayerStatsExperience.matchMasters=Hattrick Masters
Expand Down
16 changes: 8 additions & 8 deletions content/locale/de/foxtrick.properties
Original file line number Diff line number Diff line change
Expand Up @@ -577,14 +577,14 @@ PlayerStatsExperience.sum=Summe
PlayerStatsExperience.Experience=Erfahrung
PlayerStatsExperience.PerformanceHistory=Leistungsentwicklung

PlayerStatsExperience.matchFriendly=Freundschaftsspiele
PlayerStatsExperience.matchCupA=Pokal
PlayerStatsExperience.matchCupB1=Challenger-Pokal "Smaragd"
PlayerStatsExperience.matchCupB2=Challenger-Pokal "Rubin"
PlayerStatsExperience.matchCupB3=Challenger-Pokal "Saphir"
PlayerStatsExperience.matchCupC=Goldene-Ananas-Pokal
PlayerStatsExperience.matchQualification=Qualifikation
PlayerStatsExperience.matchLeague=Ligaspiele
PlayerStatsExperience.friendly=Freundschaftsspiele
PlayerStatsExperience.cup=Pokal
PlayerStatsExperience.challenger_cup_1=Challenger-Pokal "Smaragd"
PlayerStatsExperience.challenger_cup_2=Challenger-Pokal "Rubin"
PlayerStatsExperience.challenger_cup_3=Challenger-Pokal "Saphir"
PlayerStatsExperience.consolation_cup=Goldene-Ananas-Pokal
PlayerStatsExperience.qualifier=Qualifikation
PlayerStatsExperience.series=Ligaspiele
PlayerStatsExperience.matchNtFriendly=NT Freundschaftspiele
PlayerStatsExperience.matchNtFriendlyNew=NT Freundschaftspiele
PlayerStatsExperience.matchMasters=Hattrick Masters
Expand Down
Loading

0 comments on commit 10158d1

Please sign in to comment.