use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepositoryInstrumentedTest method initalData.
private void initalData() {
RiderStageConnection riderStageConnection = new RiderStageConnection();
riderStageConnection.setBonusPoint(10);
riderStageConnection.setBonusTime(20);
riderStageConnection.setSprintBonusPoints(100);
riderStageConnection.setMountainBonusPoints(200);
riderStageConnection.setOfficialGap(100);
riderStageConnection.setOfficialTime(100);
riderStageConnection.setType(RiderStateType.DNC);
riderStageConnection.setVirtualGap(100);
RiderStageConnection riderStageConnectionTwo = new RiderStageConnection();
riderStageConnectionTwo.setBonusPoint(20);
riderStageConnectionTwo.setSprintBonusPoints(300);
riderStageConnectionTwo.setMountainBonusPoints(400);
riderStageConnectionTwo.setBonusTime(40);
riderStageConnectionTwo.setOfficialGap(100);
riderStageConnectionTwo.setOfficialTime(100);
riderStageConnectionTwo.setType(RiderStateType.DOCTOR);
riderStageConnectionTwo.setVirtualGap(100);
synchronized (this) {
riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
riderStageConnectionRepository.addRiderStageConnection(riderStageConnectionTwo, onSaveRiderStageConnectionCallback);
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class StageRepositoryInstrumentedTest method addStage.
@Test
public void addStage() {
RiderStageConnection riderStageConnection = new RiderStageConnection();
riderStageConnection.setBonusPoint(10);
riderStageConnection.setBonusTime(20);
riderStageConnection.setOfficialGap(100);
riderStageConnection.setOfficialTime(100);
riderStageConnection.setType(RiderStateType.DNC);
riderStageConnection.setVirtualGap(100);
synchronized (this) {
riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
riderStageConnection.setBonusPoint(100);
riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
}
RealmList<RiderStageConnection> connections = new RealmList<>();
RealmResults<RiderStageConnection> realmConnections = realm.where(RiderStageConnection.class).findAll();
connections.addAll(realmConnections);
Stage stage = new Stage();
stage.setStageId(1);
stage.setDistance(100);
stage.setStartTime(new Date());
stage.setEndTime(new Date());
stage.setFrom("bern");
stage.setTo("zuerich");
stage.setName("Etappe 1");
stage.setType(StageType.FLATSTAGE);
stage.setStageConnections(connections);
synchronized (this) {
stageRepository.addStage(stage, onSaveStageCallback);
}
Assert.assertEquals(100, realm.where(Stage.class).findAll().first().getDistance());
Assert.assertEquals("bern", realm.where(Stage.class).findAll().first().getFrom());
Assert.assertEquals("Etappe 1", realm.where(Stage.class).findAll().first().getName());
Assert.assertEquals(2, realm.where(Stage.class).findAll().first().getStageConnections().size());
Assert.assertEquals(20, realm.where(Stage.class).findAll().first().getStageConnections().first().getBonusTime());
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class JudgmentDetailFragment method updateRiderStateConnectionWithPerformance.
private void updateRiderStateConnectionWithPerformance(Rider rider, int rank) {
int r = rider.getStartNr();
new Thread(() -> {
Judgement judgement = JudgmentPresenter.getInstance().getJudgmentByObjectIdReturned(judgementID);
rewardM = RewardPresenter.getInstance().getRewardReturnedByJudgment(judgement);
RiderStageConnection riderStageConnection = new RiderStageConnection();
riderStageConnection.setId(RiderPresenter.getInstance().getRiderByStartNr(r).getRiderStages().first().getId());
if (rewardM.getType() == RewardType.TIME) {
riderStageConnection.setBonusTime(RiderStageConnectionUtilities.getPointsAtPosition(rank, rewardM));
} else if (rewardM.getType() == RewardType.POINTS) {
int points = RiderStageConnectionUtilities.getPointsAtPosition(rank, rewardM);
if (judgement.getName().toLowerCase().contains("sprint")) {
riderStageConnection.setSprintBonusPoints(points);
riderStageConnection.setBonusPoint(points);
} else if (judgement.getName().toLowerCase().contains("bergpreis")) {
riderStageConnection.setMountainBonusPoints(points);
} else {
riderStageConnection.setBonusPoint(points);
}
} else {
Log.d(JudgmentDetailFragment.class.getSimpleName(), "APP - CALCULATE - UNSUPPORTED TYPE");
}
riderStageConnection.setMoney(RiderStageConnectionUtilities.getMoneyAtPosition(rank, rewardM));
RiderStageConnectionPresenter.getInstance().updateRiderStageConnectionReward(riderStageConnection);
}).start();
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepository method updateRiderStageConnectionRanking.
@Override
public void updateRiderStageConnectionRanking(final RiderRanking riderRanking, final RiderStageConnection connection) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.executeTransaction((Realm db) -> {
RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", connection.getId()).findFirst();
res.addRiderRanking(riderRanking);
});
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepository method updateRiderState.
@Override
public void updateRiderState(final RiderStateType type, final Rider rider, OnUpdateRiderStateCallBack callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.beginTransaction();
Rider res = realm.where(Rider.class).equalTo("id", rider.getId()).findFirst();
for (RiderStageConnection sC : res.getRiderStages()) {
if (sC.getType() == type) {
sC.setType(RiderStateType.AKTIVE);
} else {
sC.setType(type);
}
}
realm.commitTransaction();
RiderStageConnection state = realm.where(RiderStageConnection.class).equalTo("riders.id", rider.getId()).findFirst();
if (callback != null)
callback.onSuccess(state);
}
Aggregations