Skip to content

Commit

Permalink
Don't wrap around times after midnight in Details View.
Browse files Browse the repository at this point in the history
Closes #34
  • Loading branch information
mh- committed Sep 1, 2020
1 parent be8b1ce commit 71cb4c1
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public MatchesRecyclerViewAdapter(DailyMatchEntries dailyMatchEntries, Context c
this.mContext = context;
this.mValues = new ArrayList<>();
TreeMap<Integer, Pair<DiagnosisKey, MatchEntryContent.GroupedByDkMatchEntries>> treeMap = new TreeMap<>();
// Sorted TreeMap <startTimestampUTC of the first entry, Pair <DK, matchEntries> >
for (Map.Entry<DiagnosisKey, MatchEntryContent.GroupedByDkMatchEntries> entry :
dailyMatchEntries.getMap().entrySet()) {
treeMap.put(entry.getValue().getList().get(0).startTimestampUTC, new Pair<>(entry.getKey(), entry.getValue()));
Expand Down Expand Up @@ -259,12 +260,14 @@ public MatchEntryDetails() {

public static MatchEntryDetails getMatchEntryDetails(ArrayList<Matcher.MatchEntry> list,
int timeZoneOffset) {
// Get the details for one risk encounter.

// Threshold value for break detection:
final int pauseThresholdSeconds = 10;

MatchEntryDetails result = new MatchEntryDetails();
result.minTimestampLocalTZDay0 = Integer.MAX_VALUE;
result.maxTimestampLocalTZDay0 = Integer.MIN_VALUE;
int minTimestampLocalTZ = Integer.MAX_VALUE;
int maxTimestampLocalTZ = Integer.MIN_VALUE;
result.dataPoints = new ArrayList<>();
result.dotColors = new ArrayList<>();
result.dataPointsMinAttenuation = new ArrayList<>();
Expand All @@ -291,11 +294,9 @@ public static MatchEntryDetails getMatchEntryDetails(ArrayList<Matcher.MatchEntr
//Log.d(TAG, "Attenuation: "+attenuation+" dB");

int timestampLocalTZ = scanRecord.getTimestamp() + timeZoneOffset;
// reduce to "day0", to improve resolution within the float x value:
int timestampLocalTZDay0 = timestampLocalTZ % (24*3600);

// store to temporary buffers:
dataPointsInterimMap.put(timestampLocalTZDay0, attenuation);
dataPointsInterimMap.put(timestampLocalTZ, attenuation);

// if found, store max/min values
if (result.minTxPower > txPower) {
Expand All @@ -310,15 +311,20 @@ public static MatchEntryDetails getMatchEntryDetails(ArrayList<Matcher.MatchEntr
if (result.maxAttenuation < attenuation) {
result.maxAttenuation = attenuation;
}
if (result.minTimestampLocalTZDay0 > timestampLocalTZDay0) {
result.minTimestampLocalTZDay0 = timestampLocalTZDay0;
if (minTimestampLocalTZ > timestampLocalTZ) {
minTimestampLocalTZ = timestampLocalTZ;
}
if (result.maxTimestampLocalTZDay0 < timestampLocalTZDay0) {
result.maxTimestampLocalTZDay0 = timestampLocalTZDay0;
if (maxTimestampLocalTZ < timestampLocalTZ) {
maxTimestampLocalTZ = timestampLocalTZ;
}
}
}

// reduce timestamp to "day0", to improve resolution within the float x value of the graph:
int timestampMinOffset= (minTimestampLocalTZ / (24*3600)) * (24*3600);
result.minTimestampLocalTZDay0 = minTimestampLocalTZ - timestampMinOffset;
result.maxTimestampLocalTZDay0 = maxTimestampLocalTZ - timestampMinOffset;

// Second step: Process each scan record, group them, find the minimum attenuation in each group
ArrayList<Entry> dataPointsBuffer = new ArrayList<>();
ArrayList<Integer> dotColorsBuffer = new ArrayList<>();
Expand All @@ -329,7 +335,7 @@ public static MatchEntryDetails getMatchEntryDetails(ArrayList<Matcher.MatchEntr
int i = 0;
for(Map.Entry<Integer, Integer> mapEntry : dataPointsInterimMap.entrySet()) {
// iterate over sorted TreeMap
int timestampLocalTZDay0 = mapEntry.getKey();
int timestampLocalTZDay0 = mapEntry.getKey() - timestampMinOffset;
int attenuation = mapEntry.getValue();

// Second step: look for a break (>= pauseThresholdSeconds)
Expand Down

0 comments on commit 71cb4c1

Please sign in to comment.