Skip to content

Commit

Permalink
Fix metrics report showing incorrect data
Browse files Browse the repository at this point in the history
- Edit sql query to use union all instead of union to include duplicates.
- Fix bug where incorrect recordType inputs caused query failure
  • Loading branch information
hkhan38 committed Oct 21, 2024
1 parent f71832d commit 0f9e8dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private void syncDBHelper(Map<String, Set<String>> tableMap, SimpleJdbcInsert in
public List<Map<String,String>> getMetricsReport(Instant startDate, Instant endDate, String orderBy, String ordering, List<String> recordType, String docId, Integer noOfRecords) {
String sql = "select t.DOCUMENT, ifnull(t.DOC_TITLE, '') as \"DOC_TITLE\", ifnull(t.RECORD_TYPE, '') as \"RECORD_TYPE\", sum(t.VIEWS) as \"VIEWS\", sum(t.DOWNLOADS) as \"DOWNLOADS\" " +
"from (select DOCUMENT, DOC_TITLE, RECORD_TYPE, AMOUNT as \"DOWNLOADS\", 0 as \"VIEWS\" from downloads where %s " +
"union select DOCUMENT, DOC_TITLE, RECORD_TYPE, 0 as \"DOWNLOADS\", AMOUNT as \"VIEWS\" from views where %s) t " +
"union all select DOCUMENT, DOC_TITLE, RECORD_TYPE, 0 as \"DOWNLOADS\", AMOUNT as \"VIEWS\" from views where %s) t " +
"group by DOCUMENT,DOC_TITLE,RECORD_TYPE";

ArrayList<String> whereVal = new ArrayList<>();
Expand Down
4 changes: 2 additions & 2 deletions templates/html/metrics/metrics.ftlh
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
<label><input type="checkbox" name="recordType" value="dataset">dataset</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="recordType" value="datasetNonGeographic">dataset (non geographic)</label>
<label><input type="checkbox" name="recordType" value="nonGeographicDataset">dataset (non geographic)</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="recordType" value="modelCodeApplication">model code (application)</label>
<label><input type="checkbox" name="recordType" value="application">model code (application)</label>
</div>
</div>
</div>
Expand Down

0 comments on commit 0f9e8dc

Please sign in to comment.