Changeset 1500


Ignore:
Timestamp:
Jan 13, 2012, 11:57:53 AM (10 years ago)
Author:
Martin Svensson
Message:

References #339 A bug that calculated the wrong number of quarters is fixed. Also added statistics-information about number of specimens registered to unlisted sites and number of specimens that are missing 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

    r1498 r1500  
    3030  var sitesCombined;
    3131  var numCols;
     32  var unknownSite = 0;
     33  var unknownCreation;
    3234 
    3335  var month=new Array(12);
     
    168170    setInnerHTML('reportcell', '');
    169171    cellElement.appendChild(reportTable);
     172    var summaryList = document.createElement('ul');
     173    if (unknownSite == null) unknownSite = 0;
     174    if (unknownCreation == null) unknownCreation = 0;
     175    summaryList.appendChild(getListElement(unknownSite + ' specimens registered to unknown sites.'));
     176    summaryList.appendChild(getListElement(unknownCreation + ' specimens without creation date.'));
     177    cellElement.appendChild(summaryList);
    170178    Main.show('gorestart');   
    171179  }
     
    221229    else if (viewType == 'QUARTER')
    222230    {
    223       numCols = (endDate.getFullYear()-startDate.getFullYear())*4 + Math.ceil((endDate.getMonth()-startDate.getMonth())/3)+1;
     231      //First year
     232      numCols = 4 - Math.floor(startDate.getMonth()/3);
     233      numCols += Math.floor(endDate.getMonth()/3)+1;
     234      if((endDate.getFullYear() - startDate.getFullYear()) > 1) numCols += 4 * (endDate.getFullYear() - startDate.getFullYear()-1);
    224235      headerText += 'quarters';
    225236    }
     
    438449    endDate.setMonth(ldString.substr(4,2)-1);
    439450    endDate.setDate(ldString.substr(6));
    440     var viewType = report.viewType;
    441    
    442     var sites = report.sites;
     451    var viewType = report.viewType;   
     452    var sites = report.sites;   
     453    var statistics = report.statistics;
     454    unknownCreation = statistics.noDate;
     455    unknownSite = statistics.unknownSite;
    443456    for (namePrefix in sites)
    444457    {
     
    451464      var siteStartDate = new Date(year, month-1, date);
    452465     
    453       var siteData = report[namePrefix];
     466      var siteData = statistics[namePrefix];     
    454467      var tableRow = document.createElement('tr');
    455468      var tableCol = getTableCellElement(siteName, 'rowtitle');
     
    473486          }
    474487          grandTotal += data;         
    475           if (currentDate.getFullYear() < siteStartDate.getFullYear()) data = '';
    476           else if (sitesCombined[keyIndex] == null) sitesCombined[keyIndex] = data;
     488          if ( (currentDate.getFullYear() <= siteStartDate.getFullYear()))
     489          {
     490            data = '';
     491            if (sitesCombined[keyIndex] == null) sitesCombined[keyIndex] = data;
     492          }
     493          else if (sitesCombined[keyIndex] == null || sitesCombined[keyIndex] == '') sitesCombined[keyIndex] = data;
    477494          else sitesCombined[keyIndex] += data;
    478495          currentDate.setFullYear(currentDate.getFullYear()+1);
     
    488505          }         
    489506          grandTotal += data;
    490           if ( currentDate.getFullYear() <= siteStartDate.getFullYear() && qIndex<startQuarter)
     507          if ( (currentDate.getFullYear() <= siteStartDate.getFullYear()) && qIndex<startQuarter)
    491508          {
    492509            data = '';
     
    575592   
    576593    return cellElement;
     594  }
     595 
     596  function getListElement(itemText)
     597  {
     598    var listElement = document.createElement('li');
     599    var textNode = document.createTextNode(itemText);
     600    listElement.appendChild(textNode);
     601    return listElement;
    577602  }
    578603  </script>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/SampleReportServlet.java

    r1498 r1500  
    124124        Date firstDate = null;
    125125        JSONObject jsonSitesCombined = new JSONObject();
    126         String viewType = null;   
     126        String viewType = null;
     127        JSONObject jsonStatistics = new JSONObject();
    127128        while (sampleIterator.hasNext())
    128129        {
     
    130131          BioMaterialEvent creationEvent = s.getCreationEvent();
    131132          Date creationDate = creationEvent.getEventDate();
     133          String currentSitePrefix = s.getName().substring(0,2);
     134          if (sites.get(currentSitePrefix) == null)
     135          {
     136            String key = "unknownSite";
     137            Integer unknownSite = (Integer)jsonStatistics.get(key);
     138            if (unknownSite == null) unknownSite = 0;
     139            unknownSite++;
     140            jsonStatistics.put(key, unknownSite);
     141          }
    132142          if (creationDate != null)
    133143          {
    134144            if (viewType == null) viewType = getViewType(startDate, endDate);
    135             if (creationDate != null)
    136             {           
    137               // Get site info
    138               String currentSitePrefix = s.getName().substring(0,2);
    139               JSONObject jsonSite = (JSONObject)jsonReport.get(currentSitePrefix);
    140               if (jsonSite == null)jsonSite = new JSONObject();
    141              
    142               // Increase the counter for current period on the site
    143               String currentPeriod = getCurrentPeriod(creationDate, viewType);                       
    144               Integer periodCounter = (Integer)jsonSite.get(currentPeriod);
    145               if (periodCounter == null) periodCounter = 0;
    146               Integer combinedCounter = (Integer)jsonSitesCombined.get(currentPeriod);
    147               if (combinedCounter == null) combinedCounter = 0;
    148               periodCounter++;
    149               combinedCounter++;
    150               jsonSite.put(currentPeriod, periodCounter);
    151               jsonSitesCombined.put(currentPeriod, combinedCounter);
    152              
    153               // Put current site info back into the report info.
    154               jsonReport.put(currentSitePrefix, jsonSite);
    155              
    156               // Find out if current creation-date is the latest so far.
    157               if (latestDate == null || latestDate.before(creationDate))
     145                       
     146            // Get site info           
     147            JSONObject jsonSite = (JSONObject)jsonStatistics.get(currentSitePrefix);
     148            if (jsonSite == null)jsonSite = new JSONObject();
     149           
     150            // Increase the counter for current period on the site
     151            String currentPeriod = getCurrentPeriod(creationDate, viewType);                       
     152            Integer periodCounter = (Integer)jsonSite.get(currentPeriod);
     153            if (periodCounter == null) periodCounter = 0;
     154            Integer combinedCounter = (Integer)jsonSitesCombined.get(currentPeriod);
     155            if (combinedCounter == null) combinedCounter = 0;
     156            periodCounter++;
     157            combinedCounter++;
     158            jsonSite.put(currentPeriod, periodCounter);
     159            jsonSitesCombined.put(currentPeriod, combinedCounter);
     160           
     161            // Put current site info back into the report info.
     162            jsonStatistics.put(currentSitePrefix, jsonSite);
     163           
     164            // Find out if current creation-date is the latest so far.
     165            if (latestDate == null || latestDate.before(creationDate))
     166            {
     167              latestDate = creationDate;
     168            }
     169            /* Find out if current creation-date is the oldest so far.
     170             * Update variable if creation date isn't before start date of current site.             
     171             */
     172            if (firstDate == null || firstDate.after(creationDate))
     173            {
     174              JSONObject site = (JSONObject)sites.get(currentSitePrefix);
     175              if (site!= null)
    158176              {
    159                 latestDate = creationDate;
     177                String siteStart = (String)site.get("startdate");
     178                Date siteStartDate = string2DateConverter.convert(siteStart.replaceAll("-", ""));
     179                if (!siteStartDate.after(creationDate))
     180                  firstDate = creationDate;
    160181              }
    161               /* Find out if current creation-date is the oldest so far.
    162                * Update variable if creation date isn't before start date of current site.             
    163                */
    164               if (firstDate == null || firstDate.after(creationDate))
    165               {
    166                 JSONObject site = (JSONObject)sites.get(currentSitePrefix);
    167                 if (site!= null)
    168                 {
    169                   String siteStart = (String)site.get("startdate");
    170                   Date siteStartDate = string2DateConverter.convert(siteStart.replaceAll("-", ""));
    171                   if (!siteStartDate.after(creationDate))
    172                     firstDate = creationDate;
    173                 }
    174               }         
    175             }         
     182            }           
     183          }
     184          else
     185          {
     186            String noDateKey = "noDate";
     187            Integer noDateCounter = (Integer)jsonStatistics.get(noDateKey);
     188            if (noDateCounter == null) noDateCounter = 0;
     189            noDateCounter++;
     190            jsonStatistics.put(noDateKey, noDateCounter);
    176191          }
    177192        }
    178         if (jsonReport.size() > 0)
    179         {
    180           if (viewType == null) viewType = getViewType(startDate, endDate);
    181           jsonReport.put("viewType", viewType);
    182           jsonReport.put("beginDate", date2StringConverter.convert(startDate));
    183           jsonReport.put("endDate", date2StringConverter.convert(endDate));
    184           jsonReport.put("latestDate", date2StringConverter.convert(latestDate));
    185           json.put("report", jsonReport);
    186         }
     193        jsonReport.put("statistics", jsonStatistics);       
     194        if (viewType == null) viewType = getViewType(startDate, endDate);
     195        jsonReport.put("viewType", viewType);
     196        jsonReport.put("beginDate", date2StringConverter.convert(startDate));
     197        jsonReport.put("endDate", date2StringConverter.convert(endDate));
     198        jsonReport.put("latestDate", date2StringConverter.convert(latestDate));
     199        json.put("report", jsonReport);
     200     
    187201      }
    188202    }
Note: See TracChangeset for help on using the changeset viewer.