Skip to content

Commit

Permalink
Fixed a couple bugs. One in advisor related to how dates are handled.…
Browse files Browse the repository at this point in the history
… So changed all date parsing to use the pattern matching and created date formats. Also added Junit tests to check each format works and a performance test case comparing 1,000,000 calls using pattern matching and a fixed date format. Second bug seemed to prevent window synchronisation from working. The key thread was being conditionally created - and I've no idea why. Removed the condition so now always created and synch from window works once again
  • Loading branch information
gh-davidr committed Jan 29, 2022
1 parent a220bea commit eaae283
Show file tree
Hide file tree
Showing 19 changed files with 492 additions and 245 deletions.
4 changes: 2 additions & 2 deletions src/main/java/analysis/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ public static Date getLastDateFromDBResults(ArrayList<DBResult> resultList)
DBResult latest = resultList.get(0);

try {
result = CommonUtils.convertDateString(latest.getM_CP_EventTime(), DBResult.getCP_EventTimeFormat());
result = CommonUtils.convertDateString(latest.getM_CP_EventTime());
} catch (ParseException e)
{
m_Logger.log(Level.SEVERE, "<getLastDateFromDBResults>" + ". Unexpected Exception converting date. " + e.getMessage());
Expand All @@ -1327,7 +1327,7 @@ public static Date getFirstDateFromDBResults(ArrayList<DBResult> resultList)
DBResult latest = resultList.get(0);

try {
result = CommonUtils.convertDateString(latest.getM_CP_EventTime(), DBResult.getCP_EventTimeFormat());
result = CommonUtils.convertDateString(latest.getM_CP_EventTime());
} catch (ParseException e)
{
m_Logger.log(Level.SEVERE, "<getFirstDateFromDBResults>" + ". Unexpected Exception converting date. " + e.getMessage());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/analysis/AnalyzerTrendResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ public boolean checkForResult(AnalyzerSingleResult analyzerSingleResult2,

try
{
dt1 = CommonUtils.convertDateString(getM_AnalyzerSingleResult1().getM_DBResult().getM_CP_EventTime(), DBResult.getCP_EventTimeFormat());
dt2 = CommonUtils.convertDateString(analyzerSingleResult2.getM_DBResult().getM_CP_EventTime(), DBResult.getCP_EventTimeFormat());

dt1 = CommonUtils.convertDateString(getM_AnalyzerSingleResult1().getM_DBResult().getM_CP_EventTime());
dt2 = CommonUtils.convertDateString(analyzerSingleResult2.getM_DBResult().getM_CP_EventTime());
//m_Logger.log(Level.FINE, "<"+this.getClass().getName()+"> checkForResult " + " Comparing dt1 " + dt1 + " with dt2 " + dt2);

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/control/ThreadDetermineSaveDifferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public ThreadDetermineSaveDifferences(DataLoadNightScoutTreatments dataLoadNig
String dateRange)
{
m_LoadRunning = false;
if (m_NightscoutLoadThread != null) m_LoadThread = new Thread(this);
m_LoadThread = new Thread(this);
m_DataLoadNightScout = dataLoadNightScout;
m_MeterArrayListDBResults = meterArrayListDBResults;
m_NightScoutArrayListDBResults = nightScoutArrayListDBResults;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/control/ThreadMongoDBAlerterEntries.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ protected void checkDBForUpdates() throws IOException, ParseException

if (result != null)
{
m_CurrentResultAt = CommonUtils.convertNSZDateString(result);
m_CurrentResultAt = CommonUtils.convertDateString(result);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/control/ThreadMongoDBAlerterTreatments.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected void checkDBForUpdates() throws IOException, ParseException
Matcher m = r.matcher(result);
if (m.find())
{
m_CurrentResultAt = CommonUtils.convertNSZDateString(m.group(1));
m_CurrentResultAt = CommonUtils.convertDateString(m.group(1));
m_CurrentResultBy = m.group(3);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/entity/DBResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public static DBResult cloneDBResult(DBResult res, String timeString)
DBResult result = new DBResult();

try {
result.m_Time = CommonUtils.convertNSZDateString(timeString);
result.m_Time = CommonUtils.convertDateString(timeString);
} catch (ParseException e) {
// TODO Auto-generated catch block
result.m_Time = new Date(0);
Expand Down Expand Up @@ -370,7 +370,7 @@ private boolean isTimeSlotLater(String mealSlotStartTime)
boolean result = false;
String mealSlotStartDate = new String(m_TreatmentDate + " " + mealSlotStartTime);
try {
Date mealSlotStart = CommonUtils.convertDateString(mealSlotStartDate, "dd-MMM-yyyy HH:mm:ss");
Date mealSlotStart = CommonUtils.convertDateString(mealSlotStartDate);
int startComp = mealSlotStart.compareTo(m_Time);

// Check if start <= time
Expand All @@ -393,7 +393,7 @@ private boolean isTimeSlotBefore(String mealSlotEndTime)
boolean result = false;
String mealSlotEndDate = new String(m_TreatmentDate + " " + mealSlotEndTime);
try {
Date mealSlotEnd = CommonUtils.convertDateString(mealSlotEndDate, "dd-MMM-yyyy HH:mm:ss");
Date mealSlotEnd = CommonUtils.convertDateString(mealSlotEndDate);

int endComp = mealSlotEnd.compareTo(m_Time);

Expand Down Expand Up @@ -421,8 +421,8 @@ private boolean isTimeSlotBetween(String mealSlotStartTime, String mealSlotEndTi

// System.out.println("David Start(" + mealSlotStartDate + ") End(" + mealSlotEndDate + ") Format(" + "dd-MMM-yyyy HH:mm:ss)");

Date mealSlotStart = CommonUtils.convertDateString(mealSlotStartDate, "dd-MMM-yyyy HH:mm:ss");
Date mealSlotEnd = CommonUtils.convertDateString(mealSlotEndDate, "dd-MMM-yyyy HH:mm:ss");
Date mealSlotStart = CommonUtils.convertDateString(mealSlotStartDate);
Date mealSlotEnd = CommonUtils.convertDateString(mealSlotEndDate);

int startComp = mealSlotStart.compareTo(m_Time);
int endComp = mealSlotEnd.compareTo(m_Time);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/entity/DBResultCellNovoRaw.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private Date createDateFromString(String date, int hour, int mins)
{
String dateTime = date + " " + String.format("%02d", hour) + ":" + String.format("%02d", mins);

result = CommonUtils.convertDateString(dateTime, format);
result = CommonUtils.convertDateString(dateTime);
}
catch (ParseException e)
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/entity/DBResultEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public DBResultEntry(String m_ID, Double m_Unfiltered, Double m_Filtered, String
this.m_Date = m_Date;
this.m_Noise = m_Noise;

m_UTCDate = CommonUtils.convertNSZDateString(m_DateString);
m_UTCDate = CommonUtils.convertDateString(m_DateString);
m_EpochMillies = m_UTCDate.getTime();
m_Hour = CommonUtils.get24Hour(m_UTCDate);

Expand Down Expand Up @@ -143,7 +143,7 @@ public DBResultEntry(DBResultEntry other, String m_DateString)
this.m_Noise = other.m_Noise;

try {
m_UTCDate = CommonUtils.convertNSZDateString(m_DateString);
m_UTCDate = CommonUtils.convertDateString(m_DateString);
m_Date = Double.valueOf(m_UTCDate.getTime());
} catch (ParseException e) {
// TODO Auto-generated catch block
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/entity/DBResultNightScout.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public DBResultNightScout(DBObject rs, boolean rawData)

// David 14 Apr 2016
String timeStr = CommonUtils.getFieldStr(rs, "Time");
Date time = CommonUtils.convertNSDateString(timeStr);
Date time = CommonUtils.convertDateString(timeStr);

m_EpochMillies = time.getTime();
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public DBResultNightScout(DBObject rs, boolean rawData)

// Nightscout times are in UTC.
// Need to convert them to local time.
Date utcTime = CommonUtils.convertNSZDateString(CommonUtils.getFieldStr(rs, "created_at"));
Date utcTime = CommonUtils.convertDateString(CommonUtils.getFieldStr(rs, "created_at"));
Date time = new Date(CommonUtils.toLocalTime(utcTime.getTime(), CommonUtils.locTZ));
m_Time = time;
m_CP_EventTime = CommonUtils.convertNSZDateString(m_Time);
Expand Down Expand Up @@ -137,7 +137,7 @@ public DBResultNightScout(Document rs, boolean rawData)

// David 14 Apr 2016
String timeStr = CommonUtils.getFieldStr(rs, "Time");
Date time = CommonUtils.convertNSDateString(timeStr);
Date time = CommonUtils.convertDateString(timeStr);

m_EpochMillies = time.getTime();
}
Expand Down Expand Up @@ -177,7 +177,7 @@ public DBResultNightScout(Document rs, boolean rawData)

// Nightscout times are in UTC.
// Need to convert them to local time.
Date utcTime = CommonUtils.convertNSZDateString(CommonUtils.getFieldStr(rs, "created_at"));
Date utcTime = CommonUtils.convertDateString(CommonUtils.getFieldStr(rs, "created_at"));
Date time = new Date(CommonUtils.toLocalTime(utcTime.getTime(), CommonUtils.locTZ));
m_Time = time;
m_CP_EventTime = CommonUtils.convertNSZDateString(m_Time);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/entity/DBResultNightScoutProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public DBResultNightScoutProfile(Document rs)

// Nightscout times are in UTC.
// Need to convert them to local time.
Date utcTime = CommonUtils.convertNSZDateString(CommonUtils.getFieldStr(rs, "created_at"));
Date utcTime = CommonUtils.convertDateString(CommonUtils.getFieldStr(rs, "created_at"));
m_CreatedAt = new Date(CommonUtils.toLocalTime(utcTime.getTime(), CommonUtils.locTZ));


Expand All @@ -74,7 +74,7 @@ public DBResultNightScoutProfile(Document rs)

// Nightscout times are in UTC.
// Need to convert them to local time.
utcTime = CommonUtils.convertNSZDateString(CommonUtils.getFieldStr(defaultDoc, "startDate"));
utcTime = CommonUtils.convertDateString(CommonUtils.getFieldStr(defaultDoc, "startDate"));
m_StartDate = new Date(CommonUtils.toLocalTime(utcTime.getTime(), CommonUtils.locTZ));
m_Unit = CommonUtils.getFieldStr(defaultDoc, "timezone");

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/entity/DBResultRoche.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public DBResultRoche(String[] recordSet)
m_Day = Integer.parseInt(recordSet[m_DayIndex]);
m_DayName = recordSet[m_DayNameIndex];
//m_Time = parseFileDate(recordSet[m_TimeIndex]);
m_Time = CommonUtils.convertDateString(recordSet[m_TimeIndex], "yyyy-MM-dd HH:mm:ss");
m_Time = CommonUtils.convertDateString(recordSet[m_TimeIndex]);
m_TimeSlot = recordSet[m_TimeSlotIndex];
m_Result = recordSet[m_ResultIndex];
m_ResultType = recordSet[m_ResultTypeIndex];
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/loader/DataLoadBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected void locateTempBasals()
// If the basal rate change was on the hour, then assume that it's a basal rate
// If the basal rate change was off the hour, then assume it's a temp basal.
Date basalTime = new Date(res.getM_EpochMillies());
int minutes = CommonUtils.getMinutesFromDate(basalTime);
int minutes = CommonUtils.getMinuteFromDate(basalTime);

if (minutes == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/loader/DataLoadDiasend.java
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ protected void locateTempBasals() {
// If the basal rate change was on the hour, then assume that it's a basal rate
// If the basal rate change was off the hour, then assume it's a temp basal.
Date basalTime = new Date(res.getM_EpochMillies());
int minutes = CommonUtils.getMinutesFromDate(basalTime);
int minutes = CommonUtils.getMinuteFromDate(basalTime);

if (minutes == 0) {
lastHourChange = res;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/loader/DataLoadLibreView.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static public Date parseFileDateTime(String date)
Date result = null;

try {
result = CommonUtils.convertDateString(date, "dd-MM-yyyy HH:mm");
result = CommonUtils.convertDateString(date);
} catch (ParseException e1) {
m_Logger.log(Level.SEVERE, "<DataLoadLibreView> " + "parseFileDate - Unexpected error parsing date: " + date);

Expand All @@ -82,7 +82,7 @@ static public LocalDateTime parseFileLocalDateTime(String date)
LocalDateTime result = null;

try {
result = CommonUtils.convertDateTimeString(date, "dd-MM-yyyy HH:mm");
result = CommonUtils.convertLocalDateTimeString(date);
} catch (ParseException e1) {
m_Logger.log(Level.SEVERE, "<DataLoadLibreView> " + "parseFileLocalDateTime - Unexpected error parsing date: " + date);

Expand Down
Loading

0 comments on commit eaae283

Please sign in to comment.