OpenLigaDB-Samples icon indicating copy to clipboard operation
OpenLigaDB-Samples copied to clipboard

Neue property in Goal Objekt

Open xdream77 opened this issue 1 year ago • 0 comments

Für meine Anzeige muss ich wissen, für welches Team dieses Tor gefallen ist. Unabhängig davon ob es ein Elfmeter, Eigentor oder was auch immer ist.

Zur Zeit setze ich die property goalFor selbst. Ich denke, dass das eine wichtige Information ist und es wäre cool, wenn wir das in die Source einbauen könnten.

Hier ist meine Implementierung in Javascript (bzw. beschränktem Typescript)

Ich modifiziere die Daten zwar ein bisschen, aber das Ergebnis ist erkennbar.

const modifyGoal = (goal: OldbGoal): WgdGoal => ({
    oldb_id: goal.goalID,
    home   : goal.scoreTeam1,
    away   : goal.scoreTeam2,
    minute : goal.matchMinute,
    scorer : {
        name   : goal.goalGetterName,
        oldb_id: goal.goalGetterID,
    },
    penalty : goal.isPenalty,
    ownGoal : goal.isOwnGoal,
    overtime: goal.isOvertime,
});

const addGoalFor = ({ goals }: OldbData) => goals.reduce( (acc, cur) => {
    const model = modifyGoal(cur);
    if (!acc.length) {
        model.goalFor = model.home > model.away ? 'home' : 'away';
    } else {
        model.goalFor = acc[acc.length - 1].home === model.home ? 'away' : 'home';
    }
    acc.push(model);
    return acc; 
}, [] as `WgdGoal[]);`

xdream77 avatar May 23 '24 15:05 xdream77