Package org.worldbank.transport.tamt.shared

Examples of org.worldbank.transport.tamt.shared.TrafficFlowReport


   
    tagDetails = regionDao.getStudyRegion(tagDetails);
    String tagName = tagDetails.getName();
    String studyRegionName = tagDetails.getRegion().getName();
   
    TrafficFlowReport weekday;
    TrafficFlowReport saturday;
    TrafficFlowReport sundayHoliday;
   
    String output = "";
   
    try {
      weekday = dao.getTrafficFlowReport(tagDetails, TrafficCountRecord.DAYTYPE_WEEKDAY);
      saturday = dao.getTrafficFlowReport(tagDetails, TrafficCountRecord.DAYTYPE_SATURDAY);
      sundayHoliday = dao.getTrafficFlowReport(tagDetails, TrafficCountRecord.DAYTYPE_SUNDAY_HOLIDAY);
     
      // get the date the report was created
      SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd/HH:mm:ss");
      Date created = weekday.getCreated();
      logger.debug("Date created:" + created);
      String ts = format.format(created);
      logger.debug("Formatted:" + ts);
      String csvFileName = "traffic-flow-report-" + ts;
     
      StringBuffer sb = new StringBuffer();
      sb.append("REPORTDATE,REGION,TAG,DAYTYPE,HOUR,W2,W3,PC,TX,LDV,LDC,HDC,MDB,HDB\n");
      ArrayList<ArrayList> weekdayValues = weekday.getDayTypeValues();
      for (Iterator iterator = weekdayValues.iterator(); iterator
          .hasNext();) {
        ArrayList row = (ArrayList) iterator.next();
       
        // add date report was created
        sb.append(ts + ",");
       
        // add region name (need to lookup)
        sb.append(studyRegionName + ",");
       
        // add tag name (need to lookup)
        sb.append(tagName + ",");
       
        // add day type
        sb.append(TrafficCountRecord.DAYTYPE_WEEKDAY + ",");
       
        for (Iterator iter = row.iterator(); iter.hasNext();) {
          String item = (String) iter.next();
          sb.append(item);
          sb.append(",");
        }
        sb.append("\n");
       
       
      }
     
      // saturday
      ArrayList<ArrayList> saturdayValues = saturday.getDayTypeValues();
      for (Iterator iterator = saturdayValues.iterator(); iterator
          .hasNext();) {
        ArrayList row = (ArrayList) iterator.next();
       
        // add date report was created
        sb.append(ts + ",");
       
        // add region name (need to lookup)
        sb.append(studyRegionName + ",");
       
        // add tag name (need to lookup)
        sb.append(tagName + ",");
       
        // add day type
        sb.append(TrafficCountRecord.DAYTYPE_SATURDAY + ",");
       
        for (Iterator iter = row.iterator(); iter.hasNext();) {
          String item = (String) iter.next();
          sb.append(item);
          sb.append(",");
        }
        sb.append("\n");
      }
     
      // sunday
      ArrayList<ArrayList> sundayHolidayValues = sundayHoliday.getDayTypeValues();
      for (Iterator iterator = sundayHolidayValues.iterator(); iterator
          .hasNext();) {
        ArrayList row = (ArrayList) iterator.next();
       
        // add date report was created
View Full Code Here


    return seqVal;
  }

  public TrafficFlowReport getTrafficFlowReport(TagDetails tagDetails, String dayType) throws Exception {
   
    TrafficFlowReport report = null;
    String tagId = tagDetails.getId();
   
    try {
      Connection connection = getConnection();
      Statement s = connection.createStatement();
      String sql = "SELECT  " +
          "created, " +
          "date_part('hour', hour_bin) as hour_bin, " +
          "w2, " +
          "w3, " +
          "pc, " +
          "tx, " +
          "ldv, " +
          "ldc, " +
          "hdc, " +
          "mdb, " +
          "hdb " +
          "FROM trafficflowreport " +
          "WHERE tagid = '"+tagId+"' " +
          "AND daytype = '"+dayType+"' " +
          "ORDER BY hour_bin";
      logger.debug("getTrafficFlowReport sql=" + sql);
      ResultSet r = s.executeQuery(sql);
     
      report = new TrafficFlowReport();
      report.setTagId(tagId);
      report.setDayType(dayType);
     
      ArrayList<ArrayList> dayTypeValues = new ArrayList<ArrayList>();
     
      while( r.next() ) {
       
        ArrayList<String> values = new ArrayList<String>();
        report.setCreated(r.getTimestamp(1)); // set multiple times, oh well.
       
        values.add(r.getString(2)); // hour_bin
       
        values.add(formatter.format(r.getDouble(3)));
        values.add(formatter.format(r.getDouble(4)));
        values.add(formatter.format(r.getDouble(5)));
        values.add(formatter.format(r.getDouble(6)));
        values.add(formatter.format(r.getDouble(7)));
        values.add(formatter.format(r.getDouble(8)));
        values.add(formatter.format(r.getDouble(9)));
        values.add(formatter.format(r.getDouble(10)));
        values.add(formatter.format(r.getDouble(11)));
     
        dayTypeValues.add(values);
      }
     
      report.setDayTypeValues(dayTypeValues);
     
      connection.close(); // returns connection to the pool

    }
      catch (SQLException e) {
View Full Code Here

TOP

Related Classes of org.worldbank.transport.tamt.shared.TrafficFlowReport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.