Changeset 1729


Ignore:
Timestamp:
Oct 23, 2012, 12:31:20 PM (11 years ago)
Author:
olle
Message:

Fixes #420. The sample count report is updated to rename column "Grand total" to "Sum", and add a new column "Total" to the right of the latter with data regardless od creation date.

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  
    179179    if (unknownCreation == null) unknownCreation = 0;
    180180    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.'));
    182182    cellElement.appendChild(summaryList);
    183183    Main.show('gorestart');   
     
    310310      headerText += latestDate.getDate();
    311311    }   
    312     headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+3)));
     312    headerRow.appendChild(getTableCellElement(headerText, 'reportheader', (numCols+4)));
    313313   
    314314    // Sub headers
     
    333333   
    334334   
    335     columnHeaderRow.appendChild(getTableCellElement('Grand\ntotal', 'reportsubheader'));
     335    columnHeaderRow.appendChild(getTableCellElement('Sum', 'reportsubheader'));
     336    columnHeaderRow.appendChild(getTableCellElement('Total', 'reportsubheader'));
    336337
    337338    // Build table     
     
    347348    sitesCombinedRow.appendChild(getTableCellElement('Sites combined', 'colsummary'));
    348349    sitesCombinedRow.appendChild(getTableCellElement('', 'colsummary'));
    349     var gt = 0;
    350350    for (key in sitesCombined)
    351351    {
     352      // Add entry with sample sum for site for selected time period
    352353      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'));
    356364    reportTable.appendChild(sitesCombinedRow); 
    357365
     
    526534      tableRow.appendChild(tableCol);
    527535      tableRow.appendChild(getTableCellElement(year+'-'+(month)+'-'+date, 'reportdata'));
    528       var grandTotal = 0;
    529536      var currentDate = new Date(periodStartDate.getFullYear(), periodStartDate.getMonth(), periodStartDate.getDate());     
    530537      var columnCounter = 0;
     
    542549            if (siteData[keyIndex] != null) data = siteData[keyIndex];
    543550          }
    544           grandTotal += data;         
    545551          if ( (currentDate.getFullYear() < siteStartDate.getFullYear()))
    546552          {
     
    561567            if (siteData[keyIndex] != null) data = siteData[keyIndex];           
    562568          }         
    563           grandTotal += data;
    564569          if ( (currentDate.getFullYear() <= siteStartDate.getFullYear()) && qIndex<startQuarter)
    565570          {
     
    580585            if (siteData[keyIndex] != null) data = siteData[keyIndex];
    581586          }
    582           grandTotal += data;         
    583587          if (currentDate.getFullYear() <= siteStartDate.getFullYear() && (monthIndex-1) < siteStartDate.getMonth())
    584588          {
     
    600604            if (siteData[keyIndex] != null) data = siteData[keyIndex];
    601605          }
    602           grandTotal += data;         
    603606          if (currentDate.getFullYear() <= siteStartDate.getFullYear() && getISOWeekNumber(currentDate) < getISOWeekNumber(siteStartDate))
    604607          {
     
    614617        columnCounter++;       
    615618      } 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'));
    617641      reportTable.appendChild(tableRow);
    618642    }
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1728 r1729  
    8080        Date endDate = Reggie.CONVERTER_STRING_TO_DATE.convert(endDateParameter);
    8181       
     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
    82100        String viewType = null;
    83101        String viewTypeParameter = Values.getString(req.getParameter("vtype"), null);
     
    86104          viewType = viewTypeParameter;
    87105        }
     106        else
     107        {
     108          viewType = getViewType(startDate, endDate);
     109        }
    88110
    89111        //List<Restriction> restrictions = new ArrayList<Restriction>();
     
    91113        sampleQuery.joinPermanent(Hql.innerJoin(null, "creationEvent", "ce", true));
    92114        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         else
    99         {
    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         else
    107         {
    108           // Get the when the first site started
    109           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         }
    118115        sampleQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    119116        sampleQuery.order(Orders.asc(Hql.property("name")));
     
    126123        JSONObject jsonSitesCombined = new JSONObject();
    127124        JSONObject jsonStatistics = new JSONObject();
     125        String sumSiteKey = "sumSiteKey";
     126        String sumKey = "sumKey";
     127        String totalSiteKey = "totalSiteKey";
     128        String totalKey = "totalKey";
    128129        while (sampleIterator.hasNext())
    129130        {
     
    141142            jsonStatistics.put(key, unknownSite);
    142143          }
    143           if (creationDate != null)
     144          else
    144145          {
    145             if (viewType == null) viewType = getViewType(startDate, endDate);
    146                        
    147146            // Get site info           
    148147            JSONObject jsonSite = (JSONObject)jsonStatistics.get(site.getPrefix());
     
    153152            }
    154153           
    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);
    179222          }
    180223        }
    181 
    182224        jsonReport.put("statistics", jsonStatistics);       
    183225        if (viewType == null) viewType = getViewType(startDate, endDate);
Note: See TracChangeset for help on using the changeset viewer.