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

Adds beta plugin for Euro2024 #689

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions store/Euro2024/Euro2024.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"id": "Euro2024",
"version": "0.1.0",
"version": "0.2.0",
"description": "This is for the 2024 European Championship. This is right now in beta. Player forecast does not work.",
"files": [
"https://raw.githubusercontent.com/Lukasdotcom/fantasy-manager/main/store/Europe2024/index.ts",
"https://raw.githubusercontent.com/Lukasdotcom/fantasy-manager/main/store/Europe2024/types.ts"
"https://raw.githubusercontent.com/Lukasdotcom/fantasy-manager/main/store/Euro2024/index.ts",
"https://raw.githubusercontent.com/Lukasdotcom/fantasy-manager/main/store/Euro2024/types.ts",
"https://raw.githubusercontent.com/Lukasdotcom/fantasy-manager/main/store/Euro2024/typeClubs.ts",
"https://raw.githubusercontent.com/Lukasdotcom/fantasy-manager/main/store/Euro2024/typeMatchday.ts",
"https://raw.githubusercontent.com/Lukasdotcom/fantasy-manager/main/store/Euro2024/typePlayers.ts"
]
}
103 changes: 92 additions & 11 deletions store/Euro2024/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { position } from "#/types/database";
import dataGetter, { players } from "#type/data";
import { PStatus, PlayersResult } from "./types";

import dataGetter, { clubs, players } from "#type/data";
import { Status as GameStatus, Item as GameItem } from "./typeClubs";
import { PStatus } from "./typePlayers";
import { ResultClubs, ResultMatchday, ResultPlayers } from "./types";
const headers = {
"User-Agent":
// This adds a valid user agent
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
};
const Main: dataGetter = async function () {
const nowTime = Math.floor(Date.now() / 1000);
// Gets the data for the league
const data: PlayersResult = await fetch(
const data: ResultPlayers = await fetch(
"https://gaming.uefa.com/en/eurofantasy/services/feeds/players/players_2_en_1.json",
{
headers: {
"User-Agent":
// This adds a valid user agent
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36",
},
headers,
},
).then(async (e) => {
return e.json();
Expand All @@ -26,7 +29,7 @@ const Main: dataGetter = async function () {
pictureUrl: `https://img.uefa.com/imgml/TP/players/3/2024/324x324/${player.id}.jpg`,
height: 324,
width: 324,
value: player.value,
value: player.value * 1000000,
position:
player.skill >= positions.length ? "gk" : positions[player.skill],
total_points: player.totPts,
Expand All @@ -35,6 +38,84 @@ const Main: dataGetter = async function () {
exists: player.pStatus !== PStatus.Nis,
};
});
return [true, 5, players, []];
let countdown = 0;
let transferOpen = true;
const game_data: ResultClubs = await fetch(
"https://gaming.uefa.com/en/uclpredictor/api/v1/competition/3/season/current/predictor/match_days",
{
headers,
},
).then(async (e) => {
const json_data: ResultMatchday = await e.json();
const last_matchday_id =
json_data.data.items[json_data.data.items.length - 1].id;
for (const matchday of json_data.data.items) {
// Before the matchday
if (matchday.start_at > nowTime) {
countdown = matchday.start_at - nowTime;
return fetch(
`https://gaming.uefa.com/en/uclpredictor/api/v1/competition/3/season/current/predictor/matches/${matchday.id}`,
{
headers,
},
).then((e) => e.json());
}
// During the matchday
else if (matchday.end_at > nowTime) {
const data = await fetch(
`https://gaming.uefa.com/en/uclpredictor/api/v1/competition/3/season/current/predictor/matches/${matchday.id}`,
{
headers,
},
).then((e) => e.json());
// Checks if any game is not finished note that the last matchday never ends
const finished =
matchday.id !== last_matchday_id &&
data.data.items.exists((game: GameItem) => {
return game.status !== GameStatus.Finished;
});
if (!finished) {
transferOpen = false;
return data;
}
}
}
// Should never get here, but just in case throws an error
throw new Error("Failed to find the matchday for unknown reason");
});

const clubs: clubs[] = [];
for (const game of game_data.data.items) {
const gameStart = Date.parse(game.start_at) / 1000;
let gameEnd = nowTime;
if (game.status !== GameStatus.Finished) {
gameEnd = gameStart + 60 * 60 * 3;
// Makes sure the game will still take 5 minutes to end
if (gameEnd <= nowTime + 300) {
gameEnd = nowTime + 300;
}
}
clubs.push({
club: game.home_team.name_short,
gameStart,
gameEnd,
opponent: game.away_team.name_short,
teamScore: game.home_team_score,
opponentScore: game.away_team_score,
league: "Euro2024",
home: true,
});
clubs.push({
club: game.away_team.name_short,
gameStart,
gameEnd,
opponent: game.home_team.name_short,
teamScore: game.away_team_score,
opponentScore: game.home_team_score,
league: "Euro2024",
home: false,
});
}
return [transferOpen, countdown, players, clubs];
};
export default Main;
107 changes: 107 additions & 0 deletions store/Euro2024/typeClubs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Generated by https://jsonformatter.org/json-to-typescript for https://gaming.uefa.com/en/uclpredictor/api/v1/competition/3/season/current/predictor/matches/${matchday_id}
export default interface Result {
data: Data_club;
}

export interface Data_club {
items: Item[];
share_page: null;
share_page_hash: null;
sync: Sync;
}

export interface Item {
id: number;
home_team: Team;
away_team: Team;
winner_team_id: number | null;
status: Status;
home_team_score: number;
away_team_score: number;
home_team_pen_score: number;
away_team_pen_score: number;
home_team_agg_score: null | number;
away_team_agg_score: null | number;
related_match_score: null | number;
leg_number: null | number;
points_count_finished: boolean;
start_at: string;
match_id: number;
predictable: boolean;
has_penalties: boolean;
has_extra_time: boolean;
phase: null;
prediction_types: PredictionType[];
tbc: boolean;
joker_multiplier: number;
prediction: null;
tenant_season_matchday_id: number;
match_friends: MatchFriends;
}

export interface Team {
id: number;
ref_id: string;
name: string;
name_short: string;
image: Image;
active: null;
}

export interface Image {
large: string;
small: string;
medium: string;
}

export interface MatchFriends {
count: number;
random_friend_name: string;
items: unknown[];
}

export interface PredictionType {
type: Type;
name: Name;
category: Category;
position: number;
primary: boolean;
max_points: number;
most_popular_predictions: MostPopularPrediction[];
}

export enum Category {
Fixture = "fixture",
Team = "team",
}

export interface MostPopularPrediction {
id: number;
value: string;
popularity: number;
percentage: number;
home_team_score: string;
away_team_score: string;
}

export enum Name {
FirstTeamToScore = "First team to score",
GamePredictionTypesFixtureScoreName = "game.prediction.types.fixture_score.name",
}

export enum Type {
FirstTeamScore = "first_team_score",
FixtureScore = "fixture_score",
}

export enum Status {
NotStarted = "not_started",
// These two are guesses and may be wrong
Started = "started",
Finished = "finished",
}

export interface Sync {
mhash: string;
s: number;
}
23 changes: 23 additions & 0 deletions store/Euro2024/typeMatchday.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Generated by https://jsonformatter.org/json-to-typescript for https://gaming.uefa.com/en/uclpredictor/api/v1/competition/3/season/current/predictor/match_days
export default interface Result {
data: Data_matchday;
}

export interface Data_matchday {
items: CurrentMatchDay[];
current_match_day: CurrentMatchDay;
}

export interface CurrentMatchDay {
id: number;
name: string;
name_short: string;
name_abbr: string;
start_at: number;
end_at: number;
is_public: boolean;
points_count_finished: boolean;
predictable: boolean;
has_played_match: boolean;
related_match_number: number;
}
115 changes: 115 additions & 0 deletions store/Euro2024/typePlayers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Generated by https://jsonformatter.org/json-to-typescript for https://gaming.uefa.com/en/eurofantasy/services/feeds/players/players_2_en_1.json
export default interface Result {
data: Data;
meta: Meta;
}

export interface Data {
value: Value;
feedTime: FeedTime;
}

export interface FeedTime {
utcTime: string;
istTime: string;
cestTime: string;
}

export interface Value {
playerList: PlayerList[];
}

export interface PlayerList {
id: string;
pDName: string;
pFName: string;
latinName: string;
tName: string;
tId: string;
teamPlayed: number;
minsPlyd: number;
mTransferIn: number;
mTransferOut: number;
rating: number;
cCode: string;
skill: number;
value: number;
isActive: number;
selPer: number;
mdId: string;
totPts: number;
gS: number;
assist: number;
cS: number;
gC: number;
yC: number;
rC: number;
oG: number;
pS: number;
pC: number;
pE: number;
saves: number;
pM: number;
bR: number;
gOB: number;
mOM: number;
mOMPts: number;
pStatus: PStatus;
curGDPts: number;
matchAtd: string;
trained: string;
isPlayed: number;
selInPer: number;
selOutPer: number;
upcomingMatchesList: MatchesList[];
currentMatchesList: MatchesList[];
avgPlayerPts: number;
avgPlayerValue: number;
lastGdPoints: number;
category1: number;
category2: number;
category3: number;
category4: number;
category5: number;
category6: number;
category7: number;
category8: number;
category9: number;
category10: number;
category11: number;
category12: number;
category13: number;
category14: number;
category15: number;
dTotPts: number;
}

export interface MatchesList {
mdId: string;
tId: string;
tSCode: string;
cCode: string;
tLoc: HomeAway;
vsTID: string;
vsTSCode: string;
vsCCode: string;
matchDate: string;
vsTLoc: HomeAway;
}

export enum HomeAway {
Away = "A",
Home = "H",
}

export enum PStatus {
Empty = "",
Nis = "NIS",
}

export interface Meta {
message: string;
retVal: number;
success: boolean;
timestamp: FeedTime;
}
Loading