Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

Commit

Permalink
OK en mode charcut' (#95)
Browse files Browse the repository at this point in the history
* Adapt past bool

* Correct scores component

* OK en mode charcut'

* Reprise de l'affichage des matchs terminés (un peu sale)

* Fusion de l'affichage des matchs de phase finale et non phase finale

* Repointer les json sur l'euro

* Fix affichage pour phase finale
  • Loading branch information
naustra authored Apr 5, 2021
1 parent c6a3d52 commit 24865be
Show file tree
Hide file tree
Showing 11 changed files with 3,540 additions and 1,035 deletions.
1,633 changes: 1,632 additions & 1 deletion populate/firestore-data/matches.json

Large diffs are not rendered by default.

2,396 changes: 1,630 additions & 766 deletions populate/firestore-data/matches_euro.json

Large diffs are not rendered by default.

173 changes: 172 additions & 1 deletion populate/firestore-data/teams.json
Original file line number Diff line number Diff line change
@@ -1 +1,172 @@
teams_ldc.json
{
"teams": {
"-Kj2zfp9V5wdpN59exkD": {
"name": "Italie",
"group": "A",
"winOdd": 41,
"code": "it",
"subCollection": {}
},
"-Kj2zfpEdmB6SgyPd85W": {
"group": "A",
"code": "gb-wls",
"name": "Pays de Galles",
"winOdd": 1001,
"subCollection": {}
},
"-Kj2zfpFzqykBwiz5dcL": {
"group": "A",
"name": "Turquie",
"winOdd": 151,
"code": "tr",
"subCollection": {}
},
"-Kj2zfpFzqykBwiz5dcM": {
"group": "A",
"name": "Suisse",
"code": "ch",
"winOdd": 81,
"subCollection": {}
},
"-Kj2zfpFzqykBwiz5dcN": {
"code": "dk",
"name": "Danemark",
"winOdd": 401,
"group": "B",
"subCollection": {}
},
"-Kj2zfpGJmSTghyT06un": {
"group": "B",
"name": "Finlande",
"winOdd": 1001,
"code": "fi",
"subCollection": {}
},
"-Kj2zfpGJmSTghyT06uo": {
"code": "ru",
"winOdd": 17,
"group": "B",
"name": "Russie",
"subCollection": {}
},
"-Kj2zfpHPqNpMy7ZgxmM": {
"name": "Belgique",
"group": "B",
"winOdd": 7,
"code": "be",
"subCollection": {}
},
"-Kj2zfpIxWevwDITiL0V": {
"name": "Ukraine",
"code": "ua",
"group": "C",
"winOdd": 5.5,
"subCollection": {}
},
"-Kj2zfpJov1GY9sA2IgE": {
"group": "C",
"name": "Pays-Bas",
"code": "nl",
"winOdd": 501,
"subCollection": {}
},
"-Kj2zfpJov1GY9sA2IgF": {
"winOdd": 46,
"group": "C",
"name": "Autriche",
"code": "at",
"subCollection": {}
},
"-Kj2zfpKYdjdHhPukkXr": {
"group": "C",
"winOdd": 151,
"name": "Macédoine du N.",
"code": "mk",
"subCollection": {}
},
"-Kj2zfpKYdjdHhPukkXs": {
"code": "gb-eng",
"group": "D",
"name": "Angleterre",
"winOdd": 125,
"subCollection": {}
},
"-Kj2zfpKYdjdHhPukkXt": {
"code": "hr",
"winOdd": 151,
"group": "D",
"name": "Croatie",
"subCollection": {}
},
"-Kj2zfpKYdjdHhPukkXu": {
"code": "gb-sct",
"winOdd": 7,
"group": "D",
"name": "Écosse",
"subCollection": {}
},
"-Kj2zfpLjC03AaK-W8Lo": {
"name": "R. tchèque",
"winOdd": 201,
"group": "D",
"code": "cz",
"subCollection": {}
},
"-Kj2zfpM7z9dtuBQZC4c": {
"name": "Suède",
"code": "se",
"group": "E",
"winOdd": 201,
"subCollection": {}
},
"-Kj2zfpN8l22eNCLSzLj": {
"winOdd": 501,
"group": "E",
"code": "pl",
"name": "Pologne",
"subCollection": {}
},
"-Kj2zfpN8l22eNCLSzLk": {
"code": "es",
"group": "E",
"winOdd": 12,
"name": "Espagne",
"subCollection": {}
},
"-Kj2zfpN8l22eNCLSzLl": {
"code": "sk",
"group": "E",
"name": "Slovaquie",
"winOdd": 301,
"subCollection": {}
},
"-Kj2zfpO3MwCoLIdNuNf": {
"name": "Allemagne",
"code": "de",
"group": "F",
"winOdd": 301,
"subCollection": {}
},
"-Kj2zfpO3MwCoLIdNuNg": {
"winOdd": 31,
"name": "France",
"group": "F",
"code": "fr",
"subCollection": {}
},
"-Kj2zfpPgzwXCT7Bnm1y": {
"name": "Portugal",
"group": "F",
"winOdd": 23,
"code": "pt",
"subCollection": {}
},
"-Kj2zfpRCBdqgDxcBLBQ": {
"group": "F",
"winOdd": 201,
"code": "hu",
"name": "Hongrie",
"subCollection": {}
}
}
}
28 changes: 12 additions & 16 deletions src/screens/Matches/Match/Match.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import './Match.scss'
import MatchInfos from './MatchInfos'
import Odds from './Odds'
import PointsWon from './PointsWon'
import PointsWonPhase from './PointsWonPhase'
import Scores from './Scores'
import ValidIcon from './ValidIcon'

Expand All @@ -33,7 +32,7 @@ const Match = ({ matchSnapshot }) => {
setCurrentBet(bet)
}, [bet])

const past = match.dateTime.toMillis() < Date.now()
const past = match.dateTime.toMillis() <= Date.now()

const isBetValid = (updatedBet) => {
if (
Expand Down Expand Up @@ -106,13 +105,17 @@ const Match = ({ matchSnapshot }) => {
onBetValueUpdated={handleTeamAChange}
past={past}
/>
{!past && (
<Odds
bet_teamA={currentBet.betTeamA}
bet_teamB={currentBet.betTeamB}
odds={match.odds}
/>
)}
<div className="points-odds-container">
{!past && (
<Odds
bet_teamA={currentBet.betTeamA}
bet_teamB={currentBet.betTeamB}
odds={match.odds}
/>
)}
{past && <Scores {...match} />}
{past && <PointsWon {...match} {...bet} />}
</div>
<Bet
team={teamB}
betValue={currentBet.betTeamB}
Expand All @@ -129,13 +132,6 @@ const Match = ({ matchSnapshot }) => {
past={past}
/>
)}
{past && <Scores {...match} />}
{past &&
(match.phase === '0' ? (
<PointsWon {...match} {...bet} />
) : (
<PointsWonPhase {...match} {...bet} />
))}
<Divider />
<MatchInfos match={match} />
{!past && <ValidIcon valid={betSaved()} />}
Expand Down
7 changes: 7 additions & 0 deletions src/screens/Matches/Match/Match.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
display: grid;
grid-template-columns: 45% 10% 45%;
margin-bottom: 10px;

.points-odds-container {
display: flex;
flex-direction: column;
justify-content: space-around;
align-items: center;
}
}
}

Expand Down
110 changes: 72 additions & 38 deletions src/screens/Matches/Match/PointsWon/PointsWon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,98 @@ import isNumber from 'lodash/isNumber'

import './PointsWon.scss'

const findWinner = (scoreA, scoreB) => {
if (scoreA > scoreB) return 'A'
if (scoreA === scoreB) return 'N'
return 'B'
// Proxi points
const proxiCoeff = {
SCORE_PARFAIT: 1,
PROXI1: 0.6,
PROXI2: 0.35,
PROXI3: 0.2,
}

const getMessage = (goodScore, goodWinner, hasBet) => {
// https://docs.google.com/spreadsheets/d/1ZioOtyCblJtJf0WAaRxVWmnibqOeC7eDcJYDVEYRqng/edit?usp=sharing
const getPhaseCoeff = (phase) =>
({
0: 1,
8: 1.67,
4: 3.34,
2: 6.69,
1: 13.37,
}[phase])

const getMessage = (proxi, hasBet) => {
if (!hasBet) return "Vous n'avez pas pronostiqué"
if (goodScore) return 'Vous avez pronostiqué le score parfait!'
else if (goodWinner) return 'Vous avez le bon résultat'
if (proxi === proxiCoeff.SCORE_PARFAIT)
return 'Vous avez pronostiqué le score parfait!'
else if (proxi === proxiCoeff.PROXI1) return 'Vous êtes en première proximité'
else if (proxi === proxiCoeff.PROXI2) return 'Vous êtes en seconde proximité'
else if (proxi === proxiCoeff.PROXI3)
return 'Vous êtes en troisième proximité'
return 'Dommage, vous ferez mieux la prochaine fois'
}

const getOdd = (odds, winner) =>
({
A: odds.A,
B: odds.B,
N: odds.N,
}[winner])
const round = (value, decimals) =>
Number(`${Math.round(`${value}e${decimals}`)}${`e-${decimals}`}`)

const getCalculus = (odds, winner, goodScore, goodWinner) => {
const odd = getOdd(odds, winner)
if (goodScore) return `🤩 4 × ${odd} = ${4 * odd}`
if (goodWinner) return `😐 2 × ${odd} = ${2 * odd}`
const getCalculus = (odd, proxi, phase) => {
const calculText = `${proxi} × ${odd} × ${phase} = ${round(
proxi * odd * phase,
2,
)}`
if (proxi === proxiCoeff.SCORE_PARFAIT) return `🤩 ` + calculText
else if (proxi === proxiCoeff.PROXI1) return `😐 ` + calculText
else if (proxi === proxiCoeff.PROXI2) return `😐 ` + calculText
else if (proxi === proxiCoeff.PROXI3) return `😐 ` + calculText
return '0 + 0 = 😶'
}

const PointsWon = ({ pointsWon, scores, betTeamA, betTeamB, odds }) => {
const PointsWon = ({ pointsWon, scores, phase, betTeamA, betTeamB, odds }) => {
if (!scores) return null

const { A, B } = scores
const matchWinner = findWinner(A, B)
const goodScore = A === betTeamA && B === betTeamB
// No bet ?
const hasBet = isNumber(pointsWon)
const goodWinner =
!goodScore && hasBet && matchWinner === findWinner(betTeamA, betTeamB)

// Check proxi
const { A, B } = scores
const nbButs = A + B
const phaseCoeff = getPhaseCoeff(phase)
const oddScore = nbButs < 7 ? odds[`P${A}${B}`] : odds.Pautre
const proxiArrondie = pointsWon / (oddScore * phaseCoeff) + 0.1 // 0.1 en marge
const realProxi =
proxiArrondie > proxiCoeff.SCORE_PARFAIT
? proxiCoeff.SCORE_PARFAIT
: proxiArrondie > proxiCoeff.PROXI1
? proxiCoeff.PROXI1
: proxiArrondie > proxiCoeff.PROXI2
? proxiCoeff.PROXI2
: proxiArrondie > proxiCoeff.PROXI3
? proxiCoeff.PROXI3
: 0

return (
<div className="points-won-container">
<Typography variant="h4">
{getMessage(goodScore, goodWinner, hasBet)}
</Typography>
{<Typography variant="h4">{getMessage(realProxi, hasBet)}</Typography>}
<div className="points-won-container">
<Typography
variant="body1"
className={`points-won ${goodScore ? 'good-score' : ''} ${
goodWinner ? 'good-winner' : ''
}`}
className={`points-won ${
realProxi === proxiCoeff.SCORE_PARFAIT
? 'good-score'
: realProxi >= proxiCoeff.PROXI3
? 'good-winner'
: ''
} `}
>
{pointsWon > 0 ? '+' : ''} {pointsWon || 0} point
{pointsWon > 1 ? 's' : ''}
{pointsWon || 0} pts
</Typography>
<Tooltip
title={getCalculus(odds, matchWinner, goodScore, goodWinner)}
placement="right"
enterTouchDelay={0}
>
<InfoIcon className="points-won-info-icon" />
</Tooltip>
{
<Tooltip
title={getCalculus(oddScore, realProxi, phaseCoeff)}
placement="right"
enterTouchDelay={0}
>
<InfoIcon className="points-won-info-icon" />
</Tooltip>
}
</div>
</div>
)
Expand All @@ -78,6 +111,7 @@ PointsWon.propTypes = {
A: PropTypes.number.isRequired,
B: PropTypes.number.isRequired,
}),
phase: PropTypes.string,
betTeamA: PropTypes.number,
betTeamB: PropTypes.number,
odds: PropTypes.objectOf(PropTypes.number),
Expand Down
Loading

0 comments on commit 24865be

Please sign in to comment.