use of ch.hsr.sa.radiotour.dataaccess.models.Rider in project app by TourLive.
the class RiderStageConnectionRepository method updateRiderStageConnectionTime.
@Override
public void updateRiderStageConnectionTime(long timeBefore, long timeStamp, final RaceGroup res, OnUpdateRiderStageConnectionCallBack callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.beginTransaction();
if (timeBefore > 0 && !res.getRiders().isEmpty()) {
for (Rider r : res.getRiders()) {
if (!r.getRiderStages().isEmpty()) {
r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() - timeBefore);
}
}
}
if (!res.getRiders().isEmpty()) {
for (Rider r : res.getRiders()) {
if (!r.getRiderStages().isEmpty()) {
r.getRiderStages().first().setVirtualGap(r.getRiderStages().first().getVirtualGap() + timeStamp);
}
}
}
RealmResults<RiderStageConnection> connections = realm.where(RiderStageConnection.class).findAll();
List<RiderStageConnection> cons = realm.copyFromRealm(connections);
cons.sort(new RiderStageConnectionComparatorVirtualGap());
for (int i = 0; i < cons.size(); i++) {
RiderRanking riderRanking = realm.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.VIRTUAL);
if (riderRanking != null) {
riderRanking.setRank(i + 1);
}
}
realm.commitTransaction();
if (callback != null) {
callback.onSuccess();
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.Rider in project app by TourLive.
the class UIUtilitis method getCountsPerLine.
public static HashMap<Integer, Integer> getCountsPerLine(RealmList<Rider> riders) {
HashMap<Integer, Integer> number = new HashMap<>();
if (!riders.isEmpty()) {
for (Rider r : riders) {
int startnr = r.getStartNr();
int firstNumber = UIUtilitis.getFirstDigit(startnr);
int temp = 1;
if (number.containsKey(firstNumber)) {
temp = number.get(firstNumber) + 1;
}
number.put(firstNumber, temp);
}
}
number.put(30, 1);
return number;
}
use of ch.hsr.sa.radiotour.dataaccess.models.Rider in project app by TourLive.
the class JudgmentRiderConnectionInstrumentedTest method addRewardRiderConnection.
@Test
public void addRewardRiderConnection() {
addRider();
addJudgment();
RealmList<Rider> riderList = new RealmList<>();
RealmList<Judgement> judgementList = new RealmList<>();
riderList.add(RiderPresenter.getInstance().getRiderByStartNr(15));
judgementList.add(JudgmentPresenter.getInstance().getJudgmentsById(93).first());
JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
judgmentRiderConnection.setRank(1);
judgmentRiderConnection.setJudgements(judgementList);
judgmentRiderConnection.setRider(riderList);
synchronized (this) {
judgmentRiderConnectionRepository.addJudgmentRiderConnection(judgmentRiderConnection, onSaveJudgmentRiderConnectionCallback);
}
Assert.assertEquals(1, realm.where(JudgmentRiderConnection.class).findAll().first().getRank());
}
use of ch.hsr.sa.radiotour.dataaccess.models.Rider in project app by TourLive.
the class JudgmentRiderConnectionInstrumentedTest method clearAllRewardRiderConnections.
@Test
public void clearAllRewardRiderConnections() {
addRider();
addJudgment();
RealmList<Rider> riderList = new RealmList<>();
RealmList<Judgement> judgementList = new RealmList<>();
riderList.add(RiderPresenter.getInstance().getRiderByStartNr(15));
judgementList.add(JudgmentPresenter.getInstance().getJudgmentsById(93).first());
JudgmentRiderConnection judgmentRiderConnection = new JudgmentRiderConnection();
judgmentRiderConnection.setRank(1);
judgmentRiderConnection.setJudgements(judgementList);
judgmentRiderConnection.setRider(riderList);
synchronized (this) {
judgmentRiderConnectionRepository.addJudgmentRiderConnection(judgmentRiderConnection, onSaveJudgmentRiderConnectionCallback);
}
synchronized (this) {
judgmentRiderConnectionRepository.clearAllJudgmentRiderConnections();
}
Assert.assertEquals(0, realm.where(JudgmentRiderConnection.class).findAll().size());
}
use of ch.hsr.sa.radiotour.dataaccess.models.Rider in project app by TourLive.
the class JudgmentRiderConnectionInstrumentedTest method addRider.
private void addRider() {
Rider rider = new Rider();
rider.setCountry("swiss");
rider.setName("testrider");
rider.setStartNr(15);
rider.setTeamName("Swiss");
rider.setTeamShortName("CH");
synchronized (this) {
riderRepository.addRider(rider, onSaveRiderCallback);
}
}
Aggregations