use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepository method updateRiderStageConnection.
@Override
public void updateRiderStageConnection(final RiderStageConnection newRiderStageConnection, final RiderStageConnection oldRiderStageConnection, OnUpdateRiderStageConnectionCallBack callback) {
Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
realm.executeTransaction((Realm db) -> {
RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", oldRiderStageConnection.getId()).findFirst();
res.setBonusPoint(newRiderStageConnection.getBonusPoint());
res.setSprintBonusPoints(newRiderStageConnection.getSprintBonusPoints());
res.setMountainBonusPoints(newRiderStageConnection.getMountainBonusPoints());
res.setBonusTime(newRiderStageConnection.getBonusTime());
res.setVirtualGap(newRiderStageConnection.getVirtualGap());
res.setOfficialGap(newRiderStageConnection.getOfficialGap());
res.setOfficialTime(newRiderStageConnection.getOfficialTime());
res.setType(newRiderStageConnection.getType());
res.setMoney(newRiderStageConnection.getMoney());
});
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection 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.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepositoryInstrumentedTest method updateRiderStageConnection.
@Test
public void updateRiderStageConnection() {
initalData();
String id;
RiderStageConnection res = realm.where(RiderStageConnection.class).findAll().first();
id = res.getId();
RiderStageConnection newStageConnection = new RiderStageConnection();
newStageConnection.setType(RiderStateType.AKTIVE);
newStageConnection.setBonusPoint(100);
newStageConnection.setBonusTime(2020);
newStageConnection.setMountainBonusPoints(4000);
newStageConnection.setSprintBonusPoints(5000);
newStageConnection.setVirtualGap(res.getVirtualGap());
newStageConnection.setOfficialTime(res.getOfficialTime());
newStageConnection.setOfficialGap(res.getOfficialGap());
synchronized (this) {
riderStageConnectionRepository.updateRiderStageConnection(newStageConnection, res, onUpdateRiderStageConnectionCallBack);
}
RiderStageConnection endRes = realm.where(RiderStageConnection.class).equalTo("id", id).findAll().first();
assertEquals(100, endRes.getOfficialGap());
assertEquals(100, endRes.getVirtualGap());
assertEquals(100, endRes.getOfficialTime());
assertEquals(100, endRes.getBonusPoint());
assertEquals(2020, endRes.getBonusTime());
assertEquals(4000, endRes.getMountainBonusPoints());
assertEquals(5000, endRes.getSprintBonusPoints());
assertEquals(RiderStateType.AKTIVE, endRes.getType());
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class RiderStageConnectionRepositoryInstrumentedTest method addRiderStageConnection.
@Test
public void addRiderStageConnection() {
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);
synchronized (this) {
riderStageConnectionRepository.addRiderStageConnection(riderStageConnection, onSaveRiderStageConnectionCallback);
}
RealmResults<RiderStageConnection> res = realm.where(RiderStageConnection.class).findAll();
assertEquals(1, res.size());
assertEquals(100, res.get(0).getOfficialGap());
assertEquals(100, res.get(0).getVirtualGap());
assertEquals(100, res.get(0).getOfficialTime());
assertEquals(10, res.get(0).getBonusPoint());
assertEquals(20, res.get(0).getBonusTime());
assertEquals(100, res.get(0).getSprintBonusPoints());
assertEquals(200, res.get(0).getMountainBonusPoints());
assertEquals(RiderStateType.DNC, res.get(0).getType());
}
use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection in project app by TourLive.
the class Parser method parseRidersAndPersist.
public static void parseRidersAndPersist(JSONArray riders) throws InterruptedException {
final JSONArray ridersJson = riders;
Runnable runnable = new Runnable() {
public void run() {
for (int i = 0; i < ridersJson.length(); i++) {
try {
JSONObject jsonRider = ridersJson.getJSONObject(i);
Rider rider = new Rider();
rider.setStartNr(jsonRider.getInt(startNr));
rider.setCountry(jsonRider.getString(country));
rider.setName(jsonRider.getString(name));
rider.setTeamName(jsonRider.getString(team));
rider.setTeamShortName(jsonRider.getString(teamShort));
rider.setRiderID(jsonRider.getInt(riderID));
synchronized (this) {
Context.addRider(rider);
}
RiderStageConnection riderStageConnection = new RiderStageConnection();
riderStageConnection.setBonusPoint(0);
riderStageConnection.setBonusTime(0);
riderStageConnection.setOfficialGap(jsonRider.getLong("timeRueckLong"));
riderStageConnection.setOfficialTime(jsonRider.getLong("timeOffLong"));
riderStageConnection.setVirtualGap(jsonRider.getLong("timeVirtLong"));
String state = jsonRider.getString("active");
if (state.equals("true")) {
riderStageConnection.setType(RiderStateType.AKTIVE);
} else {
riderStageConnection.setType(RiderStateType.DNC);
}
RiderStageConnection riderStageConnectionOne;
synchronized (this) {
riderStageConnectionOne = Context.addRiderStageConnection(riderStageConnection);
}
RealmList<RiderStageConnection> riderStageConnections = new RealmList<>();
riderStageConnections.add(riderStageConnectionOne);
Context.updateRiderStageConnection(rider, riderStageConnections);
} catch (JSONException e) {
Log.d(Parser.class.getSimpleName(), "APP - PARSER - RIDERS - " + e.getMessage());
}
}
}
};
Thread threadRiders = new Thread(runnable);
threadRiders.start();
threadRiders.join();
Thread threadGroup = createDefaultGroup();
threadGroup.start();
threadGroup.join();
updateRiderConnectionRankByOfficalGap();
}
Aggregations