- Componente A: teto 450 pts - Componente B: teto 180 pts - Componente C: teto 230 pts - Componente D: teto 180 pts Adiciona campo teto no ComponentePontuacao que limita o total
72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
from dataclasses import dataclass
|
|
from typing import Dict
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ComponentePontuacao:
|
|
base: int
|
|
tempo: int
|
|
extras: int
|
|
bonus: int
|
|
retorno: int = 0
|
|
teto: int = 0
|
|
|
|
@property
|
|
def total(self) -> int:
|
|
soma = self.base + self.tempo + self.extras + self.bonus + self.retorno
|
|
if self.teto > 0:
|
|
return min(soma, self.teto)
|
|
return soma
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class PontuacaoCompleta:
|
|
componente_a: ComponentePontuacao
|
|
componente_b: ComponentePontuacao
|
|
componente_c: ComponentePontuacao
|
|
componente_d: ComponentePontuacao
|
|
|
|
@property
|
|
def total(self) -> int:
|
|
return (
|
|
self.componente_a.total
|
|
+ self.componente_b.total
|
|
+ self.componente_c.total
|
|
+ self.componente_d.total
|
|
)
|
|
|
|
@property
|
|
def detalhamento(self) -> Dict[str, Dict[str, int]]:
|
|
return {
|
|
"componente_a": {
|
|
"base": self.componente_a.base,
|
|
"tempo": self.componente_a.tempo,
|
|
"extras": self.componente_a.extras,
|
|
"bonus": self.componente_a.bonus,
|
|
"retorno": self.componente_a.retorno,
|
|
"total": self.componente_a.total,
|
|
},
|
|
"componente_b": {
|
|
"base": self.componente_b.base,
|
|
"tempo": self.componente_b.tempo,
|
|
"extras": self.componente_b.extras,
|
|
"bonus": self.componente_b.bonus,
|
|
"total": self.componente_b.total,
|
|
},
|
|
"componente_c": {
|
|
"base": self.componente_c.base,
|
|
"tempo": self.componente_c.tempo,
|
|
"extras": self.componente_c.extras,
|
|
"bonus": self.componente_c.bonus,
|
|
"total": self.componente_c.total,
|
|
},
|
|
"componente_d": {
|
|
"base": self.componente_d.base,
|
|
"tempo": self.componente_d.tempo,
|
|
"extras": self.componente_d.extras,
|
|
"bonus": self.componente_d.bonus,
|
|
"total": self.componente_d.total,
|
|
},
|
|
"pontuacao_total": self.total,
|
|
}
|