use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints 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.executeTransaction((Realm db) -> {
RiderStageConnection res = db.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.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);
}
}
});
if (callback != null) {
callback.onSuccess();
}
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorMountainPoints in project app by TourLive.
the class Parser method updateRiderConnectionRankByOfficalGap.
private static void updateRiderConnectionRankByOfficalGap() throws InterruptedException {
Runnable runnable = new Runnable() {
public void run() {
try {
RealmList<RiderStageConnection> connections = Context.getAllRiderStageConnections();
connections.sort(new RiderStageConnectionComparatorOfficalGap());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingOfficial = new RiderRanking();
rankingOfficial.setType(RankingType.OFFICAL);
rankingOfficial.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingOfficial);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingOfficial);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
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));
}
connections.sort(new RiderStageConnectionComparatorMountainPoints());
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingMountain = new RiderRanking();
rankingMountain.setType(RankingType.MOUNTAIN);
rankingMountain.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingMountain);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingMountain);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
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));
}
connections.sort(new RiderStageConnectionComparatorVirtualGap());
int rank = 1;
for (int i = 0; i < connections.size(); i++) {
if (connections.get(i).getRiders().getCountry().equals("SUI")) {
RiderRanking rankingSwiss = new RiderRanking();
rankingSwiss.setType(RankingType.SWISS);
rankingSwiss.setRank(rank);
rank++;
synchronized (this) {
Context.addRiderRanking(rankingSwiss);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingSwiss);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
}
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingMoney = new RiderRanking();
rankingMoney.setType(RankingType.MONEY);
rankingMoney.setRank(i + 1);
synchronized (this) {
Context.addRiderRanking(rankingMoney);
}
RiderRanking realmRiderRanking = Context.getRiderRanking(rankingMoney);
Context.updateRiderStageConnectionRanking(realmRiderRanking, connections.get(i));
}
for (int i = 0; i < connections.size(); i++) {
RiderRanking rankingTimeInLead = new RiderRanking();
rankingTimeInLead.setType(RankingType.TIME_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();
}
Aggregations