use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking in project app by TourLive.
the class Parser method updateRiderConnectionRankByVirtualGap.
public static String updateRiderConnectionRankByVirtualGap() throws InterruptedException {
Runnable runnable = new Runnable() {
public void run() {
try {
RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
connections.sort(new RiderStageConnectionComparatorVirtualGap());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingVirtual = new RiderRanking();
rankingVirtual.setType(RankingType.VIRTUAL);
rankingVirtual.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingVirtual);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingVirtual);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
} catch (Exception e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
}
}
};
Thread threadRanking = new Thread(runnable);
threadRanking.start();
threadRanking.join();
return "success";
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking in project app by TourLive.
the class Parser method updateRiderConnectionRankByPoints.
public static String updateRiderConnectionRankByPoints() throws InterruptedException {
Runnable runnable = new Runnable() {
public void run() {
try {
RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
connections.sort(new RiderStageConnectionComparatorPoints());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingPoints = new RiderRanking();
rankingPoints.setType(RankingType.POINTS);
rankingPoints.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingPoints);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingPoints);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
} catch (Exception e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
}
}
};
Thread threadRanking = new Thread(runnable);
threadRanking.start();
threadRanking.join();
return "success";
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking in project app by TourLive.
the class RiderStageConnectionRepositoryInstrumentedTest method updateRiderStageConnectionRank.
@Test
public void updateRiderStageConnectionRank() {
Date date = new Date();
RiderRanking virtRank = new RiderRanking();
virtRank.setRank(1);
virtRank.setType(RankingType.VIRTUAL);
RiderStageConnection riderStageConnection = new RiderStageConnection();
riderStageConnection.setId(new Random().nextLong());
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 rSC = realm.where(RiderStageConnection.class).equalTo("virtualGap", riderStageConnection.getVirtualGap()).findFirst();
synchronized (this) {
riderStageConnectionRepository.updateRiderStageConnectionRanking(virtRank, rSC);
}
rSC = realm.where(RiderStageConnection.class).equalTo("id", rSC.getId()).findFirst();
assertEquals(1, rSC.getRiderRanking(RankingType.VIRTUAL).getRank());
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking in project app by TourLive.
the class RiderRankingRepository method addRiderRanking.
@Override
public void addRiderRanking(RiderRanking riderRanking, OnSaveRiderRankingCallback callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.executeTransaction((Realm db) -> {
RiderRanking realmRiderRanking = db.createObject(RiderRanking.class, UUID.randomUUID().toString());
realmRiderRanking.setType(riderRanking.getType());
realmRiderRanking.setRank(riderRanking.getRank());
});
if (callback != null)
callback.onSuccess();
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderRanking in project app by TourLive.
the class Parser method updateRiderConnectionRankByDistanceInLead.
public static String updateRiderConnectionRankByDistanceInLead() throws InterruptedException {
Runnable runnable = new Runnable() {
public void run() {
try {
RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
connections.sort(new RiderStageConnectionComparatorDistanceInLead());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingTimeInLead = new RiderRanking();
rankingTimeInLead.setType(RankingType.DISTANCE_IN_LEAD);
rankingTimeInLead.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingTimeInLead);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingTimeInLead);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
} catch (Exception e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERCONNECTION - " + e.getMessage());
}
}
};
Thread threadRanking = new Thread(runnable);
threadRanking.start();
threadRanking.join();
return "success";
}
Aggregations