Rangliste und Tabelle: Spiel-Class wird jetzt genutzt
This commit is contained in:
@@ -40,19 +40,6 @@ class RitzenbergenLib {
|
||||
if(path.startsWith("/")) return "http://192.168.188.38/Jonas/ritzenbergenapi"+path;
|
||||
else return "http://192.168.188.38/Jonas/ritzenbergenapi/"+path;
|
||||
}
|
||||
static calcPoints(spiel){ //TODO class dafür erstellen
|
||||
if(spiel.tipp==null) return 0;
|
||||
if(spiel.result==spiel.tipp) return 3;
|
||||
let differenztipp=spiel.tipp[0]-spiel.tipp[1];
|
||||
let differenz=spiel.result[0]-spiel.result[1];
|
||||
if(differenztipp==differenz) return 2;
|
||||
if(
|
||||
(spiel.tipp[0]>spiel.tipp[1] && spiel.result[0]>spiel.result[1]) ||
|
||||
(spiel.tipp[0]<spiel.tipp[1] && spiel.result[0]<spiel.result[1])
|
||||
) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Paarung {
|
||||
@@ -89,11 +76,51 @@ class Tipp{
|
||||
}
|
||||
}
|
||||
|
||||
class Spiel {
|
||||
public paarung: Paarung;
|
||||
public result: [number, number]|null;
|
||||
public tipp: [number, number]|null;
|
||||
|
||||
constructor (paarung: Paarung, result: [number, number], tipp: [number, number]|null) {
|
||||
this.paarung = paarung;
|
||||
this.result = result;
|
||||
this.tipp = tipp;
|
||||
}
|
||||
public calcPoints(){
|
||||
if(this.tipp==null) return 0;
|
||||
if(this.result==this.tipp) return 3;
|
||||
let differenztipp=this.tipp[0]-this.tipp[1];
|
||||
let differenz=this.result[0]-this.result[1];
|
||||
if(differenztipp==differenz) return 2;
|
||||
if(
|
||||
(this.tipp[0]>this.tipp[1] && this.result[0]>this.result[1]) ||
|
||||
(this.tipp[0]<this.tipp[1] && this.result[0]<this.result[1])
|
||||
) return 1;
|
||||
return 0;
|
||||
}
|
||||
public static async fetchSpiele(spieltag: number, userid: number):Spiel[]{
|
||||
let params=new URLSearchParams({
|
||||
spieltag: spieltag+1,
|
||||
user: userid
|
||||
});
|
||||
return fetch(RitzenbergenLib.api("/bulitipp/spieltag-user.php?")+params.toString()).then((response)=>{
|
||||
return response.json();
|
||||
}).then((data)=>{
|
||||
return data.data;
|
||||
}).then((data)=>{
|
||||
return data.map((el)=>{
|
||||
return new Spiel(new Paarung(el.paarung.heim, el.paarung.gast, el.paarung.id),el.result, el.tipp);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
RitzenbergenLib,
|
||||
User,
|
||||
SpieltagSumme,
|
||||
Paarung,
|
||||
Ergebnis,
|
||||
Tipp
|
||||
Tipp,
|
||||
Spiel
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user