Skip to content

Commit

Permalink
Merge pull request #10 from davidmsibley/GCMON-296
Browse files Browse the repository at this point in the history
Gcmon 296
  • Loading branch information
mhines-usgs committed Apr 13, 2015
2 parents 11627e0 + 77215b5 commit 8f3ae04
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,20 @@ protected void addNextRow() throws SQLException {

while(0 >= result.size() && in.next() && !in.isAfterLast()) {
TableRow now = TableRow.buildTableRow(in);
queuedRows.add(now);
if (null == sampleSet) {
sampleSet = queuedRows.peek().getValue(sampleSetColumn);
}

if (null != sampleSet &&
(queuedRows.size() > 1 && !sampleSet.equals(queuedRows.peekLast().getValue(sampleSetColumn)))) {
TableRow averagedRow = flushNextSampleSet();
if (null != averagedRow) {
result.add(averagedRow);
if (null != now.getValue(sampleSetColumn)) { // skip over null samplesets
queuedRows.add(now);
if (null == sampleSet) {
sampleSet = queuedRows.peek().getValue(sampleSetColumn);
}

if (null != sampleSet &&
(queuedRows.size() > 1 && !sampleSet.equals(queuedRows.peekLast().getValue(sampleSetColumn)))) {
TableRow averagedRow = flushNextSampleSet();
if (null != averagedRow) {
result.add(averagedRow);
}
sampleSet = null;
}
sampleSet = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ public void testBugReportTable() throws SQLException {
assertTrue(checkEqualRows(expected, actual));
}

@Test
public void testGCMON296Table() throws SQLException {
//Test created due to bug report in GCMON-296
ResultSet expected = new IteratorWrappingResultSet(expectedGCMON296Dataset.iterator());
ResultSet in = new IteratorWrappingResultSet(incomingGCMON296Dataset.iterator());

ResultSet actual = new BedSedAverageResultSet(in, expectedGCMON296ColGroup, timeColumn, sampleSetColumn, valueColumn, sampleMassColumn, errorColumn, conf95Column);

assertTrue(checkEqualRows(expected, actual));
}

@BeforeClass
public static void setUpClass() throws Exception {
timeColumn = new SimpleColumn("time");
Expand Down Expand Up @@ -205,6 +216,43 @@ public static void setUpClass() throws Exception {
new String[] {"" + dtf.parseDateTime("2012-11-19T16:21:00-07:00").getMillis(),"35","0.683","530.10","0.366","0.714"},
new String[] {"" + dtf.parseDateTime("2012-11-20T13:43:30-07:00").getMillis(),"37","0.302","1122.87","0.053","0.103"}
});

incomingGCMON296ColGroup = new ColumnGrouping(timeColumn, Arrays.asList(new Column[] {
timeColumn,
new SimpleColumn("site"),
valueColumn,
sampleMassColumn,
sampleSetColumn
}));
incomingGCMON296Dataset = ResultSetUtils.createTableRows(incomingGCMON296ColGroup, new String[][] {
new String[] {"" + dtf.parseDateTime("2010-11-08T15:05:00-07:00").getMillis(), "08375295", "0.302", "1681.59", "1"},
new String[] {"" + dtf.parseDateTime("2010-11-08T15:10:00-07:00").getMillis(), "08375295", "0.33", "1387.68", "1"},
new String[] {"" + dtf.parseDateTime("2010-11-08T15:15:00-07:00").getMillis(), "08375295", "0.424", "1291.62", "1"},
new String[] {"" + dtf.parseDateTime("2010-11-08T15:20:00-07:00").getMillis(), "08375295", "0.119", "488.06", null},
new String[] {"" + dtf.parseDateTime("2012-01-17T16:25:00-07:00").getMillis(), "08375295", "0.112", "425.96", null},
new String[] {"" + dtf.parseDateTime("2012-01-17T16:30:00-07:00").getMillis(), "08375295", "0.161", "334.93", "2"},
new String[] {"" + dtf.parseDateTime("2012-01-17T16:35:00-07:00").getMillis(), "08375295", "0.18", "327.35", "2"},
new String[] {"" + dtf.parseDateTime("2012-01-17T16:40:00-07:00").getMillis(), "08375295", "0.235", "216.68", "2"},
new String[] {"" + dtf.parseDateTime("2012-10-09T14:00:00-07:00").getMillis(), "08375295", "0.28", "274.21", "3"},
new String[] {"" + dtf.parseDateTime("2012-10-09T14:05:00-07:00").getMillis(), "08375295", "0.31", "130.98", "3"},
new String[] {"" + dtf.parseDateTime("2012-10-09T14:10:00-07:00").getMillis(), "08375295", "0.318", "173.91", "3"}
});

expectedGCMON296ColGroup = new ColumnGrouping(timeColumn, Arrays.asList(new Column[] {
timeColumn,
sampleSetColumn,
valueColumn,
sampleMassColumn,
errorColumn,
conf95Column
}));
expectedGCMON296Dataset = ResultSetUtils.createTableRows(expectedGCMON296ColGroup, new String[][] {
new String[] {"" + dtf.parseDateTime("2010-11-08T15:10:00-07:00").getMillis(),"1","0.352","1453.63","0.0369","0.0720"},
// new String[] {"" + dtf.parseDateTime("2010-11-08T15:20:00-07:00").getMillis(),null,"0.119","488.06",null,null},
// new String[] {"" + dtf.parseDateTime("2012-01-17T16:25:00-07:00").getMillis(),null,"0.112","425.96",null,null},
new String[] {"" + dtf.parseDateTime("2012-01-17T16:35:00-07:00").getMillis(),"2","0.192","292.99","0.0221","0.0431"},
new String[] {"" + dtf.parseDateTime("2012-10-09T14:05:00-07:00").getMillis(),"3","0.306","193.03","0.0093","0.0181"},
});
}

@Before
Expand Down Expand Up @@ -243,4 +291,9 @@ public void tearDown() throws Exception {
protected static Iterable<TableRow> incomingBugReportDataset = null;
protected static ColumnGrouping expectedBugReportColGroup = null;
protected static Iterable<TableRow> expectedBugReportDataset = null;

protected static ColumnGrouping incomingGCMON296ColGroup = null;
protected static Iterable<TableRow> incomingGCMON296Dataset = null;
protected static ColumnGrouping expectedGCMON296ColGroup = null;
protected static Iterable<TableRow> expectedGCMON296Dataset = null;
}

0 comments on commit 8f3ae04

Please sign in to comment.