Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neue property in Goal Objekt #73

Open
xdream77 opened this issue May 23, 2024 · 0 comments
Open

Neue property in Goal Objekt #73

xdream77 opened this issue May 23, 2024 · 0 comments

Comments

@xdream77
Copy link
Contributor

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[]);`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant