use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorPoints 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.RiderStageConnectionComparatorPoints in project app by TourLive.
the class RiderStageConnectionRepository method updateRiderStageConnectionReward.
@Override
public void updateRiderStageConnectionReward(final RiderStageConnection riderStageConnection, OnUpdateRiderStageConnectionCallBack callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.beginTransaction();
RiderStageConnection res = realm.where(RiderStageConnection.class).equalTo("id", riderStageConnection.getId()).findFirst();
res.appendBonusPoint(riderStageConnection.getBonusPoint());
res.appendBonusTime(riderStageConnection.getBonusTime());
res.appendMoney(riderStageConnection.getMoney());
res.appendMountainBonusPoints(riderStageConnection.getMountainBonusPoints());
res.appendSprintBonusPoints(riderStageConnection.getSprintBonusPoints());
realm.commitTransaction();
// Neu Berechnung der Rankings für die API, wird auf der API ebenfalls ausgeführt.
realm.executeTransaction((Realm db) -> {
RealmResults<RiderStageConnection> connections = db.where(RiderStageConnection.class).findAll();
List<RiderStageConnection> cons = realm.copyFromRealm(connections);
cons.sort(new RiderStageConnectionComparatorPoints());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.POINTS).setRank(i + 1);
}
if (riderStageConnection.getMountainBonusPoints() != 0) {
cons.sort(new RiderStageConnectionComparatorMountainPoints());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.MOUNTAIN).setRank(i + 1);
}
}
if (riderStageConnection.getMoney() != 0) {
cons.sort(new RiderStageConnectionComparatorMoney());
for (int i = 0; i < cons.size(); i++) {
db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.MONEY).setRank(i + 1);
}
}
});
PostHandler.makeMessage("UpdateRiderStageConnection", realm.copyFromRealm(res));
if (callback != null) {
callback.onSuccess();
}
}
Aggregations