Skip to content

Commit

Permalink
Do trim the melia statistics families before querying to reduce error…
Browse files Browse the repository at this point in the history
… proneness
  • Loading branch information
GenieTim committed Sep 14, 2021
1 parent 4d709ce commit 6f3b244
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private void doAnalysis() {
String startDateFormatted = format.format(startDate);
String endDateFormatted = format.format(endDate);
String[] families = getFamiliesTextField().getText().split("\n|,");
List familiesList = Arrays.asList(families);
List familiesList = Arrays.asList(Arrays.stream(families).map(String::trim).toArray(String[]::new));
log.debug("Doing Melia statistics with " + startDateFormatted + ", " + endDateFormatted + ", and " + String.join(", ", families));
// finally, all right, prepare & run queries
String results = "";
Expand All @@ -182,26 +182,27 @@ private void doAnalysis() {
try {

//
Query query1 = session.createQuery("SELECT count(DISTINCT i.imageId) FROM ICImage i INNER JOIN i.specimen AS s WHERE i.path < :end AND i.path > :start AND s.family in :families");
Query query1 = session.createQuery("SELECT count(DISTINCT i.imageId) FROM ICImage i LEFT JOIN i.specimen AS s WHERE i.path < :end AND i.path > :start AND s.family in (:families)");
query1.setParameter("end", endDateFormatted);
query1.setParameter("start", startDateFormatted);
query1.setParameter("families", familiesList);
query1.setParameterList("families", familiesList);
List resultsList = query1.getResultList();
String results1 = CastUtility.castToString(query1.getSingleResult());
results += "Nr. of ICImages: " + results1 + "\n";

//
Query query2 = session.createQuery("SELECT count(DISTINCT s.specimenId) FROM ICImage i INNER JOIN i.specimen AS s WHERE i.path < :end AND i.path > :start AND s.family IN :families");
Query query2 = session.createQuery("SELECT count(DISTINCT s.specimenId) FROM ICImage i LEFT JOIN i.specimen AS s WHERE i.path < :end AND i.path > :start AND s.family IN (:families)");
query2.setParameter("end", endDateFormatted);
query2.setParameter("start", startDateFormatted);
query2.setParameter("families", familiesList);
query2.setParameterList("families", familiesList);
String results2 = CastUtility.castToString(query2.getSingleResult());
results += "Corresponding to #specimen: " + results2 + "\n";

//
Query query3 = session.createQuery("SELECT count(DISTINCT s.specimenId) FROM Tracking t INNER JOIN t.specimen as s WHERE t.eventDateTime < :end AND t.eventDateTime > :start AND t.eventType = :eventType AND s.family IN :families");
Query query3 = session.createQuery("SELECT count(DISTINCT s.specimenId) FROM Tracking t LEFT JOIN t.specimen as s WHERE t.eventDateTime < :end AND t.eventDateTime > :start AND t.eventType LIKE :eventType AND s.family IN (:families)");
query3.setParameter("end", endDate);
query3.setParameter("start", startDate);
query3.setParameter("families", familiesList);
query3.setParameterList("families", familiesList);
query3.setParameter("eventType", "Text Entered");
String results3 = CastUtility.castToString(query3.getSingleResult());
results += "Text Entered in this date-range: " + results3 + "\n";
Expand Down

0 comments on commit 6f3b244

Please sign in to comment.