Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect where the row CGM headers are at instead of hardcoding them #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions src/davidRichardson/DBResultEntryDiasend.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,34 @@ public DBResultEntryDiasend(HSSFRow row)
loadRawCGM(row);
}

public static void initializeCGMHeaders(HSSFRow row)
// Checks whether row contains CGM headers. Returns true if it does, and fills variables with the index
public static boolean initializeCGMHeaders(HSSFRow row)
{
if (m_CGMIndexesInitialized == false)
m_CGMTimeIndex = -1;
m_CGMBGIndex = -1;
int maxColumns = row.getPhysicalNumberOfCells();
if(maxColumns >= m_CGMFieldNames.length)
{
int maxColumns = row.getPhysicalNumberOfCells();
if (maxColumns == m_CGMFieldNames.length)
int c;
for (c=0; c<m_CGMFieldNames.length; c++) // iterate on column headers
{
int c = 0;

for (c=0; c<m_CGMFieldNames.length; c++)
String cell = row.getCell(c).getStringCellValue();
if (m_CGMFieldNames[c].contains(cell)) // match cells against expected column header strings
{
String cell = row.getCell(c).getStringCellValue();
if (m_CGMFieldNames[c].contains(cell))
// if (cell.equals(m_CGMFieldNames[c]))
switch (c)
{
switch (c)
{
case 0 : m_CGMTimeIndex = c; break;
case 1 : m_CGMBGIndex = c; break;
default : break;
}
case 0 : m_CGMTimeIndex = c; break;
case 1 : m_CGMBGIndex = c; break;
}
}
m_CGMIndexesInitialized = true;
}
}
if((m_CGMTimeIndex != -1) && (m_CGMBGIndex != -1))
{
m_Logger.log(Level.FINE, "<DBResultEntryDiasend> " + "Identified columns: CGM Time=" + (m_CGMTimeIndex+1) + ", CGM BG=" + (m_CGMBGIndex+1));
return true;
}
return false;
}

private void loadRawCGM(HSSFRow row)
Expand Down
21 changes: 9 additions & 12 deletions src/davidRichardson/DataLoadDiasend.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public class DataLoadDiasend extends DataLoadBase

final static int m_InsulinRowDataHeaders = 1;
final static int m_InsulinRowDataStart = 2;

final static int m_CGMRowDataHeaders = 2;
final static int m_CGMRowDataStart = 3;

final static String m_SettingsBasalStartString = "Basal profiles";
final static String m_SettingsIntervalString = "Interval";
Expand Down Expand Up @@ -537,6 +534,7 @@ private void loadDBResultEntriesFromCGMTab()
int tmp = 0;

// This trick ensures that we get the data properly even if it doesn't start from first few rows
// @Dune-jr 2019-11-23: not sure whether that's needed anymore
for(int i = 0; i < 10 || i < rows; i++)
{
row = sheet.getRow(i);
Expand All @@ -547,20 +545,19 @@ private void loadDBResultEntriesFromCGMTab()
}
}

boolean headersInitialized = false;
for(int r = 0; r < rows; r++)
{
row = sheet.getRow(r);

if (r+1 == m_CGMRowDataHeaders)
{
DBResultEntryDiasend.initializeCGMHeaders(row);
}
else if (r+1 >= m_CGMRowDataStart)
if(row == null)
continue;
if (!headersInitialized)
headersInitialized = DBResultEntryDiasend.initializeCGMHeaders(row);
else
{
DBResultEntryDiasend res = new DBResultEntryDiasend(row);
rawEntryResultsFromDB.add(res);
// m_Logger.log(Level.FINEST, "<"+this.getClass().getName()+">" + "Result added for " + res.toString());
m_Logger.log(Level.FINEST, "<DataLoadDiasend>" + "Result added for " + res.toString());
rawEntryResultsFromDB.add(res);
m_Logger.log(Level.FINEST, "<"+this.getClass().getName()+">" + "Result added for " + res.toString());
}
}
}
Expand Down