This commit is contained in:
AdrianLxM 2018-03-15 19:57:00 +01:00
parent 8700f20d5f
commit f33b4d4838
2 changed files with 22 additions and 12 deletions

View file

@ -13,7 +13,9 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -1420,23 +1422,30 @@ public class ComboPlugin implements PluginBase, PumpInterface, ConstraintsInterf
@Override @Override
public PumpEnactResult loadTDDs() { public PumpEnactResult loadTDDs() {
PumpEnactResult result = new PumpEnactResult(); PumpEnactResult result = new PumpEnactResult();
result.success = readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL)); result.success = readHistory(new PumpHistoryRequest().tddHistory(PumpHistoryRequest.FULL));
if (result.success) { if (result.success) {
List<Tdd> tdds = pump.tddHistory; List<Tdd> tdds = pump.tddHistory;
if (tdds != null) { if (tdds != null) {
// TODAY (not yet finished): i == 0 HashMap<Long, TDD> map = new HashMap<>();
for (int i = 1; i < tdds.size(); i++) { for (int i = 0; i < tdds.size(); i++) {
Tdd last = tdds.get(i-1); Tdd currTdd = tdds.get(i);
Tdd curr = tdds.get(i); if(currTdd.total < 1) continue; //cases where dummy days are introduced (e.g. Battery change with date loss)
double timeDifference = last.timestamp-curr.timestamp; if(map.containsKey(currTdd.timestamp)){
//Only load coherent data //duplicate days on time changes
if(timeDifference > 25*60*60*1000 + 10*1000 || timeDifference < 23*60*60*1000 - 10*1000 ) break; TDD existing = map.get(currTdd.timestamp);
if (tdds.get(i).total != 0) { existing.total += currTdd.total;
MainApp.getDbHelper().createOrUpdateTDD(new TDD(curr.timestamp, 0d, 0d, curr.total)); } else {
map.put(currTdd.timestamp, new TDD(currTdd.timestamp, 0d, 0d, currTdd.total));
} }
} }
Collection<TDD> uniqueColl = map.values();
for (TDD currTdd: uniqueColl) {
MainApp.getDbHelper().createOrUpdateTDD(currTdd);
}
} }
} }
return result; return result;

View file

@ -173,8 +173,9 @@ public class ReadHistoryCommand extends BaseCommand {
} }
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.set(year, date.getMonth() - 1, date.getDay(), 0, 0, 0); calendar.set(year, date.getMonth() - 1, date.getDay(), 0, 0, 0);
long time = calendar.getTimeInMillis();
return new Tdd(calendar.getTimeInMillis(), dailyTotal); time = time - time%1000;
return new Tdd(time, dailyTotal);
} }
private void readTbrRecords(long requestedTime) { private void readTbrRecords(long requestedTime) {