Skip to content

Commit

Permalink
Manage tests sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricepipart committed Feb 14, 2023
1 parent 6e5dc1b commit 257ecdc
Show file tree
Hide file tree
Showing 75 changed files with 17,812 additions and 1,230 deletions.
22 changes: 22 additions & 0 deletions src/main/java/org/teknichrono/mgp/business/RiderService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.teknichrono.mgp.business;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.teknichrono.mgp.client.RidersClient;
import org.teknichrono.mgp.model.rider.RiderDetails;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

@ApplicationScoped
public class RiderService {

@Inject
@RestClient
RidersClient riderClient;


public RiderDetails getRider(Integer legacyId) {
return riderClient.getRider(legacyId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.teknichrono.mgp.model.result.Season;
import org.teknichrono.mgp.model.result.Session;
import org.teknichrono.mgp.model.result.SessionClassification;
import org.teknichrono.mgp.model.result.TestClassification;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -15,7 +16,7 @@
import java.util.List;

@RegisterRestClient(configKey = "results-api")
public interface ResultsService {
public interface ResultsClient {

@GET
@Path("/seasons")
Expand All @@ -25,19 +26,22 @@ public interface ResultsService {
@Path("/seasons")
List<Season> getSeasons();


@GET
@Path("/season/{season}/events")
List<Event> getEventsOfSeason(@PathParam("season") String season);

@GET
@Path("/season/db8dc197-c7b2-4c1b-b3a4-7dc723c087ed/events")
List<Event> getEventsTest();
@Path("/season/{season}/events")
List<Event> getTestEventsOfSeason(@PathParam("season") String season, @QueryParam("test") boolean test);

@GET
@Path("/season/{season}/events")
List<Event> getFinishedEventsOfSeason(@PathParam("season") String season, @QueryParam("finished") boolean finished);

@GET
@Path("/event/{event}")
Event getEvent(@PathParam("event") String event);

@GET
@Path("/event/{event}/categories")
List<Category> getCategoriesOfEvent(@PathParam("event") String event);
Expand All @@ -54,9 +58,15 @@ public interface ResultsService {
@Path("/session/{session}/classifications")
SessionClassification getClassification(@PathParam("session") String session);

// $seasons_url = "https://www.motogp.com/api/results-front/be/results-api/seasons?test=1";
// $events_url = "https://www.motogp.com/api/results-front/be/results-api/season/$season/events?finished=1";
// $categories_url = "https://www.motogp.com/api/results-front/be/results-api/event/$event/categories";
// $sessions_url = "https://www.motogp.com/api/results-front/be/results-api/event/$event/category/category/$category/sessions";
// $results_url = "https://www.motogp.com/api/results-front/be/results-api/session/$sesion/classifications"
@GET
@Path("/session/{session}/test-classifications")
TestClassification getTestClassification(@PathParam("session") String session);


// $seasons_url = "http://localhost:8089/api/results-front/be/results-api/seasons?test=1";
// $events_url = "http://localhost:8089/api/results-front/be/results-api/season/$season/events?finished=1";
// $categories_url = "http://localhost:8089/api/results-front/be/results-api/event/$event/categories";
// $sessions_url = "http://localhost:8089/api/results-front/be/results-api/event/$event/category/category/$category/sessions";
// $results_url = "http://localhost:8089/api/results-front/be/results-api/session/$sesion/classifications"
// $results_url = "http://localhost:8089/api/results-front/be/results-api/session/$sesion/test-classifications"
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import javax.ws.rs.PathParam;

@RegisterRestClient(configKey = "riders-api")
public interface RidersService {
public interface RidersClient {

@GET
@Path("/riders/{legacyId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.teknichrono.mgp.model.out;

import org.teknichrono.mgp.model.result.Classification;

import java.util.List;
import org.teknichrono.mgp.model.result.RiderClassification;

public interface ClassificationDetails {

void fill(Classification c, List<SessionRider> ridersDetails);
void fill(RiderClassification c);


}
8 changes: 6 additions & 2 deletions src/main/java/org/teknichrono/mgp/model/out/LapAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,12 @@ public LapAnalysis() {
}

public LapAnalysis(LapAnalysis old) {
frontTyreLapNumber = old.frontTyreLapNumber + 1;
backTyreLapNumber = old.backTyreLapNumber + 1;
if (old.frontTyreLapNumber != null) {
frontTyreLapNumber = old.frontTyreLapNumber + 1;
}
if (old.backTyreLapNumber != null) {
backTyreLapNumber = old.backTyreLapNumber + 1;
}
frontTyre = old.frontTyre;
backTyre = old.backTyre;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.opencsv.bean.CsvBindByName;
import com.opencsv.bean.CsvBindByPosition;
import org.teknichrono.mgp.model.result.Classification;
import org.teknichrono.mgp.model.rider.RiderSeason;

import java.util.List;
import org.teknichrono.mgp.model.result.RiderClassification;

public class PracticeClassificationDetails implements ClassificationDetails {

Expand Down Expand Up @@ -57,23 +54,18 @@ public class PracticeClassificationDetails implements ClassificationDetails {
@CsvBindByPosition(position = 11)
public Float topSpeed;

public static PracticeClassificationDetails from(Classification c, List<SessionRider> ridersDetails) {
public static PracticeClassificationDetails from(RiderClassification c) {
PracticeClassificationDetails toReturn = new PracticeClassificationDetails();
toReturn.fill(c, ridersDetails);
toReturn.fill(c);
return toReturn;
}

public void fill(Classification c, List<SessionRider> ridersDetails) {
public void fill(RiderClassification c) {
position = c.position;
riderName = c.rider.full_name;
for (SessionRider details : ridersDetails) {
if (c.rider.full_name.equalsIgnoreCase(details.fullName())) {
RiderSeason season = details.season;
riderNumber = season.number;
team = season.sponsored_team;
constructor = season.team.constructor.name;
}
}
riderNumber = c.rider.number;
team = c.team.name;
constructor = c.constructor.name;
gapToFirst = c.gap.first;
gapToPrevious = c.gap.prev;
totalLaps = c.total_laps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.opencsv.bean.CsvBindByName;
import com.opencsv.bean.CsvBindByPosition;
import org.teknichrono.mgp.model.result.Classification;
import org.teknichrono.mgp.model.rider.RiderSeason;

import java.util.List;
import org.teknichrono.mgp.model.result.RiderClassification;

public class RaceClassificationDetails implements ClassificationDetails {

Expand Down Expand Up @@ -54,23 +51,18 @@ public class RaceClassificationDetails implements ClassificationDetails {
public Float averageSpeed;


public static RaceClassificationDetails from(Classification c, List<SessionRider> ridersDetails) {
public static RaceClassificationDetails from(RiderClassification c) {
RaceClassificationDetails toReturn = new RaceClassificationDetails();
toReturn.fill(c, ridersDetails);
toReturn.fill(c);
return toReturn;
}

public void fill(Classification c, List<SessionRider> ridersDetails) {
public void fill(RiderClassification c) {
position = c.position;
riderName = c.rider.full_name;
for (SessionRider details : ridersDetails) {
if (c.rider.full_name.equalsIgnoreCase(details.fullName())) {
RiderSeason season = details.season;
riderNumber = season.number;
team = season.sponsored_team;
constructor = season.team.constructor.name;
}
}
riderNumber = c.rider.number;
team = c.team.name;
constructor = c.constructor.name;
gapToFirst = c.gap.first;
totalLaps = c.total_laps;
points = getPointsForPosition(c.position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.teknichrono.mgp.model.rider.RiderBiography;
import org.teknichrono.mgp.model.rider.RiderCountry;
import org.teknichrono.mgp.model.rider.RiderDetails;
import org.teknichrono.mgp.model.rider.RiderSeason;

public class SessionRider {

Expand All @@ -23,7 +22,6 @@ public class SessionRider {
public String birth_city;
public String birth_date;
public RiderAttributes physical_attributes;
public RiderSeason season;

public RiderBiography biography;
public Boolean legend;
Expand All @@ -32,7 +30,7 @@ public class SessionRider {
public Boolean published;


public void fill(Entry e, RiderDetails rider, int year) {
public void fill(Entry e, RiderDetails rider) {
this.wildcard = e.wildcard;
this.replacement = e.replacement;
this.replaced = e.replaced;
Expand All @@ -46,15 +44,10 @@ public void fill(Entry e, RiderDetails rider, int year) {
this.birth_city = rider.birth_city;
this.birth_date = rider.birth_date;
this.physical_attributes = rider.physical_attributes;
this.season = rider.getSeasonOfYear(e.constructor.name, year);
this.biography = rider.biography;
this.legend = rider.legend;
this.legacy_id = rider.legacy_id;
this.merchandise_url = rider.merchandise_url;
this.published = rider.published;
}

public String fullName() {
return name + " " + surname;
}
}
44 changes: 4 additions & 40 deletions src/main/java/org/teknichrono/mgp/model/result/Classification.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,9 @@
package org.teknichrono.mgp.model.result;

import com.opencsv.bean.CsvBindByName;
import com.opencsv.bean.CsvBindByPosition;
import java.util.List;

public class Classification {

public String id;

@CsvBindByName(column = "POSITION")
@CsvBindByPosition(position = 0)
public Integer position;

@CsvBindByName(column = "RIDER")
@CsvBindByPosition(position = 1)
public Rider rider;

@CsvBindByName(column = "TEAM")
@CsvBindByPosition(position = 2)
public Team team;

@CsvBindByName(column = "CONSTRUCTOR")
@CsvBindByPosition(position = 3)
public String constructor;

@CsvBindByName(column = "BEST_LAP")
@CsvBindByPosition(position = 3)
public Lap best_lap;

@CsvBindByName(column = "TOTAL_LAPS")
@CsvBindByPosition(position = 4)
public Integer total_laps;

@CsvBindByPosition(position = 5)
public String status;

@CsvBindByName(column = "TOP_SPEED")
@CsvBindByPosition(position = 6)
public Float top_speed;

@CsvBindByName(column = "GAP")
@CsvBindByPosition(position = 7)
public Gap gap;

}
public List<RiderClassification> classification;
public List<Record> records;
}
1 change: 1 addition & 0 deletions src/main/java/org/teknichrono/mgp/model/result/Rider.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Rider {
public String full_name;
public Country country;
public Integer legacy_id;
public Integer number;

public String toString() {
return full_name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.teknichrono.mgp.model.result;

import com.opencsv.bean.CsvBindByName;
import com.opencsv.bean.CsvBindByPosition;

public class RiderClassification {

public String id;

@CsvBindByName(column = "POSITION")
@CsvBindByPosition(position = 0)
public Integer position;

@CsvBindByName(column = "RIDER")
@CsvBindByPosition(position = 1)
public Rider rider;

@CsvBindByName(column = "TEAM")
@CsvBindByPosition(position = 2)
public Team team;

@CsvBindByName(column = "CONSTRUCTOR")
@CsvBindByPosition(position = 3)
public Constructor constructor;

@CsvBindByName(column = "BEST_LAP")
@CsvBindByPosition(position = 3)
public Lap best_lap;

@CsvBindByName(column = "TOTAL_LAPS")
@CsvBindByPosition(position = 4)
public Integer total_laps;

@CsvBindByPosition(position = 5)
public String status;

@CsvBindByName(column = "TOP_SPEED")
@CsvBindByPosition(position = 6)
public Float top_speed;

@CsvBindByName(column = "GAP")
@CsvBindByPosition(position = 7)
public Gap gap;

}
5 changes: 1 addition & 4 deletions src/main/java/org/teknichrono/mgp/model/result/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

public class Session {

public static final String FILENAME_MAX_SPEED = "maximum_speed";
public static final String FILENAME_ANALYSIS = "analysis";

public static final String RACE_TYPE = "RAC";

public String id;
Expand All @@ -15,7 +12,7 @@ public class Session {
public SessionCondition condition;
public String date;
public String status;
public Map<String, PdfFile> session_files;
public Map<SessionFileType, PdfFile> session_files;
public String circuit;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.teknichrono.mgp.model.result;

import java.util.List;
public class SessionClassification extends Classification {

public class SessionClassification {

public List<Classification> classification;
public List<Record> records;
public String file;

}
Loading

0 comments on commit 257ecdc

Please sign in to comment.