Changeset 1729
- Timestamp:
- Oct 23, 2012, 12:31:20 PM (11 years ago)
- Location:
- extensions/net.sf.basedb.reggie/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/net.sf.basedb.reggie/trunk/resources/samplereportgenerator.jsp
r1728 r1729 179 179 if (unknownCreation == null) unknownCreation = 0; 180 180 summaryList.appendChild(getListElement(unknownSite + ' specimens registered to unknown sites.')); 181 summaryList.appendChild(getListElement(unknownCreation + ' specimens without creation date. '));181 summaryList.appendChild(getListElement(unknownCreation + ' specimens without creation date. These are included in the \'Total\' column.')); 182 182 cellElement.appendChild(summaryList); 183 183 Main.show('gorestart'); … … 310 310 headerText += latestDate.getDate(); 311 311 } 312 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+ 3)));312 headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+4))); 313 313 314 314 // Sub headers … … 333 333 334 334 335 columnHeaderRow.appendChild(getTableCellElement('Grand\ntotal', 'reportsubheader')); 335 columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader')); 336 columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader')); 336 337 337 338 // Build table … … 347 348 sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary')); 348 349 sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary')); 349 var gt = 0;350 350 for (key in sitesCombined) 351 351 { 352 // Add entry with sample sum for site for selected time period 352 353 sitesCombinedRow.appendChild(getTableCellElement(sitesCombined[key],'colsummary')); 353 if (sitesCombined[key] != '') gt += sitesCombined[key]; 354 } 355 sitesCombinedRow.appendChild(getTableCellElement(gt, 'colsummary')); 354 } 355 // Get total number of samples for site for the selected time period 356 var statistics = report.statistics; 357 var sum = statistics.sumKey; 358 // Add entry with total number of samples for site for the selected time period 359 sitesCombinedRow.appendChild(getTableCellElement(sum, 'colsummary')); 360 // Get total number of samples for all sites, regardless of creation date 361 var total = statistics.totalKey; 362 // Add entry with total number of samples for all sites, regardless of creation date 363 sitesCombinedRow.appendChild(getTableCellElement(total, 'colsummary')); 356 364 reportTable.appendChild(sitesCombinedRow); 357 365 … … 526 534 tableRow.appendChild(tableCol); 527 535 tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata')); 528 var grandTotal = 0;529 536 var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate()); 530 537 var columnCounter = 0; … … 542 549 if (siteData[keyIndex] != null) data = siteData[keyIndex]; 543 550 } 544 grandTotal += data;545 551 if ( (currentDate.getFullYear() < siteStartDate.getFullYear())) 546 552 { … … 561 567 if (siteData[keyIndex] != null) data = siteData[keyIndex]; 562 568 } 563 grandTotal += data;564 569 if ( (currentDate.getFullYear() <= siteStartDate.getFullYear()) && qIndex<startQuarter) 565 570 { … … 580 585 if (siteData[keyIndex] != null) data = siteData[keyIndex]; 581 586 } 582 grandTotal += data;583 587 if (currentDate.getFullYear() <= siteStartDate.getFullYear() && (monthIndex-1) < siteStartDate.getMonth()) 584 588 { … … 600 604 if (siteData[keyIndex] != null) data = siteData[keyIndex]; 601 605 } 602 grandTotal += data;603 606 if (currentDate.getFullYear() <= siteStartDate.getFullYear() && getISOWeekNumber(currentDate) < getISOWeekNumber(siteStartDate)) 604 607 { … … 614 617 columnCounter++; 615 618 } while (columnCounter < numCols) 616 tableRow.appendChild(getTableCellElement(grandTotal, 'rowsummary')); 619 // Add column with sample sum for site for the selected time period 620 var siteSum = 0; 621 if (siteData != null) 622 { 623 var sumSiteKey = 'sumSiteKey'; 624 if (siteData[sumSiteKey] != null) 625 { 626 siteSum = siteData[sumSiteKey]; 627 } 628 } 629 tableRow.appendChild(getTableCellElement(siteSum, 'rowsummary')); 630 // Add column with total number of samples for site, regardless of creation date 631 var siteTotal = 0; 632 if (siteData != null) 633 { 634 var totalSiteKey = 'totalSiteKey'; 635 if (siteData[totalSiteKey] != null) 636 { 637 siteTotal = siteData[totalSiteKey]; 638 } 639 } 640 tableRow.appendChild(getTableCellElement(siteTotal, 'rowsummary')); 617 641 reportTable.appendChild(tableRow); 618 642 } -
extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java
r1728 r1729 80 80 Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter); 81 81 82 if (startDate == null) 83 { 84 // Get the when the first site started 85 for (Site s : Site.getAllSites()) 86 { 87 Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", "")); 88 if (siteDate != null && (startDate == null || startDate.after(siteDate))) 89 { 90 startDate = siteDate; 91 } 92 } 93 } 94 if (endDate == null) 95 { 96 // Get the date for today 97 endDate = new Date(); 98 } 99 82 100 String viewType = null; 83 101 String viewTypeParameter = Values.getString(req.getParameter("vtype"), null); … … 86 104 viewType = viewTypeParameter; 87 105 } 106 else 107 { 108 viewType = getViewType(startDate, endDate); 109 } 88 110 89 111 //List<Restriction> restrictions = new ArrayList<Restriction>(); … … 91 113 sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true)); 92 114 Subtype.SPECIMEN.addFilter(dc, sampleQuery); 93 94 if (endDate != null)95 {96 sampleQuery.restrict(Restrictions.lteq(Hql.property("ce", "eventDate"), Expressions.parameter("endDate", endDate)));97 }98 else99 {100 endDate = new Date();101 }102 if (startDate != null)103 {104 sampleQuery.restrict(Restrictions.gteq(Hql.property("ce", "eventDate"), Expressions.parameter("startDate", startDate)));105 }106 else107 {108 // Get the when the first site started109 for (Site s : Site.getAllSites())110 {111 Date siteDate = Reggie.CONVERTER_STRING_TO_DATE.convert(s.getStartDate().replaceAll("-", ""));112 if (siteDate != null && (startDate == null || startDate.after(siteDate)))113 {114 startDate = siteDate;115 }116 }117 }118 115 sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); 119 116 sampleQuery.order(Orders.asc(Hql.property("name"))); … … 126 123 JSONObject jsonSitesCombined = new JSONObject(); 127 124 JSONObject jsonStatistics = new JSONObject(); 125 String sumSiteKey = "sumSiteKey"; 126 String sumKey = "sumKey"; 127 String totalSiteKey = "totalSiteKey"; 128 String totalKey = "totalKey"; 128 129 while (sampleIterator.hasNext()) 129 130 { … … 141 142 jsonStatistics.put(key, unknownSite); 142 143 } 143 if (creationDate != null)144 else 144 145 { 145 if (viewType == null) viewType = getViewType(startDate, endDate);146 147 146 // Get site info 148 147 JSONObject jsonSite = (JSONObject)jsonStatistics.get(site.getPrefix()); … … 153 152 } 154 153 155 // Increase the counter for current period on the site 156 String currentPeriod = getCurrentPeriod(creationDate, viewType); 157 Integer periodCounter = (Integer)jsonSite.get(currentPeriod); 158 if (periodCounter == null) periodCounter = 0; 159 Integer combinedCounter = (Integer)jsonSitesCombined.get(currentPeriod); 160 if (combinedCounter == null) combinedCounter = 0; 161 periodCounter++; 162 combinedCounter++; 163 jsonSite.put(currentPeriod, periodCounter); 164 jsonSitesCombined.put(currentPeriod, combinedCounter); 165 166 // Find out if current creation-date is the latest so far. 167 if (latestDate == null || latestDate.before(creationDate)) 168 { 169 latestDate = creationDate; 170 } 171 } 172 else 173 { 174 String noDateKey = "noDate"; 175 Integer noDateCounter = (Integer)jsonStatistics.get(noDateKey); 176 if (noDateCounter == null) noDateCounter = 0; 177 noDateCounter++; 178 jsonStatistics.put(noDateKey, noDateCounter); 154 if (creationDate != null) 155 { 156 if ((creationDate.after(startDate) || creationDate.equals(startDate)) && 157 (creationDate.before(endDate) || creationDate.equals(endDate))) 158 { 159 // Increase the counter for current period on the site 160 String currentPeriod = getCurrentPeriod(creationDate, viewType); 161 Integer periodCounter = (Integer)jsonSite.get(currentPeriod); 162 if (periodCounter == null) periodCounter = 0; 163 Integer combinedCounter = (Integer)jsonSitesCombined.get(currentPeriod); 164 if (combinedCounter == null) combinedCounter = 0; 165 periodCounter++; 166 combinedCounter++; 167 jsonSite.put(currentPeriod, periodCounter); 168 jsonSitesCombined.put(currentPeriod, combinedCounter); 169 170 // Increase the counter for samples for the site for the selected time period 171 Integer sumSiteCounter = (Integer)jsonSite.get(sumSiteKey); 172 if (sumSiteCounter == null) 173 { 174 sumSiteCounter = 0; 175 } 176 sumSiteCounter++; 177 jsonSite.put(sumSiteKey, sumSiteCounter); 178 179 // Increase the counter for samples for all sites for the selected time period 180 Integer sumCounter = (Integer) jsonStatistics.get(sumKey); 181 if (sumCounter == null) 182 { 183 sumCounter = 0; 184 } 185 sumCounter++; 186 jsonStatistics.put(sumKey, sumCounter); 187 188 // Find out if current creation-date is the latest so far. 189 if (latestDate == null || latestDate.before(creationDate)) 190 { 191 latestDate = creationDate; 192 } 193 } 194 } 195 else 196 { 197 String noDateKey = "noDate"; 198 Integer noDateCounter = (Integer)jsonStatistics.get(noDateKey); 199 if (noDateCounter == null) noDateCounter = 0; 200 noDateCounter++; 201 jsonStatistics.put(noDateKey, noDateCounter); 202 } 203 204 // Get total number of samples per site, regardless of creation date 205 // Increase the counter for total samples for the site 206 Integer totalSiteCounter = (Integer)jsonSite.get(totalSiteKey); 207 if (totalSiteCounter == null) 208 { 209 totalSiteCounter = 0; 210 } 211 totalSiteCounter++; 212 jsonSite.put(totalSiteKey, totalSiteCounter); 213 214 // Increase the counter for total samples for all sites 215 Integer totalCounter = (Integer) jsonStatistics.get(totalKey); 216 if (totalCounter == null) 217 { 218 totalCounter = 0; 219 } 220 totalCounter++; 221 jsonStatistics.put(totalKey, totalCounter); 179 222 } 180 223 } 181 182 224 jsonReport.put("statistics", jsonStatistics); 183 225 if (viewType == null) viewType = getViewType(startDate, endDate);
Note: See TracChangeset
for help on using the changeset viewer.