Ejemplo n.º 1
0
  public void discoverInstCodesAndTotals() {
    System.out.println("Getting Institutions");
    String sql =
        "SELECT * FROM (SELECT data_provider_id, COUNT(*) AS cnt FROM raw GROUP BY data_provider_id) T1 WHERE cnt > 1 ORDER BY cnt DESC";
    for (Object[] row : BasicSQLUtils.query(dbSrcConn, sql)) {
      CollStatInfo csi = new CollStatInfo();
      csi.setProviderId((Integer) row[0]);
      csi.setTotalNumRecords(((Long) row[1]).intValue());

      if (StringUtils.isEmpty(csi.getInstName())) {
        csi.setInstName(getProviderNameFromInstCode(csi.getProviderId()));
      }
      instHashMap.put(csi.getProviderId(), csi);
      institutions.add(csi);
    }
    System.out.println("Done Getting Institutions");
  }
Ejemplo n.º 2
0
  public void createCharts() {
    loadInstCodesAndtotals();

    // for (CollStatInfo csi : institutions)
    // {
    //    csi.setInstName(getProviderNameFromInstCode(csi.getProviderId()));
    // }

    List<CollStatSQLDefs> statTypes = getStatSQL();
    HashMap<StatType, CollStatSQLDefs> statTypeHash = new HashMap<StatType, CollStatSQLDefs>();
    for (CollStatSQLDefs cs : statTypes) {
      statTypeHash.put(cs.getType(), cs);
    }

    CollStatInfo totals = new CollStatInfo(" Totals");
    for (CollStatInfo csi : institutions) {
      for (CollStatSQLDefs csqd : statTypes) {
        StatType type = csqd.getType();
        int totVal = totals.getValue(type) + csi.getValue(type);
        totals.setValue(type, totVal);
      }
    }

    try {
      FileUtils.deleteDirectory(new File("reports/charts/"));
    } catch (IOException e) {
      e.printStackTrace();
    }

    Collections.sort(
        institutions,
        new Comparator<CollStatInfo>() {
          @Override
          public int compare(CollStatInfo o1, CollStatInfo o2) {
            return o1.getInstName().compareToIgnoreCase(o2.getInstName());
            // Integer cnt1 = o1.getTotalNumRecords();
            // Integer cnt2 = o2.getTotalNumRecords();
            // return cnt2.compareTo(cnt1);
          }
        });

    institutions.insertElementAt(totals, 0);
    CollStatInfo clsi = totals;

    // tblWriter.logHdr(titles);

    int i = 0;
    for (CollStatInfo csi : institutions) {
      if (StringUtils.isEmpty(csi.getInstName())) {
        csi.setInstName(getProviderNameFromInstCode(csi.getProviderId()));
      }

      String title = csi.getTitle() + " - " + csi.getTotalNumRecords();

      if (i == 0) {
        startLogging("reports", "charts", clsi.hashCode() + ".html", title, false);
        tblWriter.startTable();
        tblInstHash.put(tblWriter, csi);

      } else {
        tblWriter.endTable();
        startNewDocument(csi.hashCode() + ".html", title, false);
        tblInstHash.put(tblWriter, csi);
        tblWriter.startTable();
      }

      if (generateChart(csi, statTypeHash)) {
        int total = csi.getValue(StatType.eTotalNumRecords);

        tblWriter.setHasLines();
        tblWriter.print("<TR><TD>");
        tblWriter.print(String.format("<img src=\"%s\">", csi.getChartFileName()));
        tblWriter.println("<BR><BR><BR><BR></TD><TD>");
        tblWriter.startTable();
        tblWriter.logHdr("Stat", "Percent");

        int rowCnt = 0;
        int cnt = 0;
        double totalPercent = 0.0;
        for (StatType type : StatType.values()) {
          if (type == StatType.eTotalNumRecords) continue;

          CollStatSQLDefs csqd = statTypeHash.get(type);

          double dVal = (double) csi.getValue(type);
          double val = (((dVal / (double) total) * 100.0));

          if (type.ordinal() < StatType.eHasYearOnly.ordinal()) {
            tblWriter.print(String.format("<TR class=\"%s\">", (rowCnt % 2 == 0 ? "od" : "ev")));
            totalPercent += val;
            cnt++;
          } else {
            tblWriter.print(String.format("<TR>", csqd.getName()));
          }
          tblWriter.println(
              String.format(
                  "<TD>%s</TD><TD style=\"text-align:right\">%6.2f</TD></TR>",
                  csqd.getName(), val));
          rowCnt++;
        }
        totalPercent = Math.max(totalPercent, 0.0);
        double avePercent = (totalPercent / (double) cnt);
        tblWriter.println(
            String.format(
                "<TR><TD>Average</TD><TD style=\"text-align:right\">%6.2f</TD></TR>", avePercent));
        csi.setAveragePercent(avePercent);

        tblWriter.endTable();
        tblWriter.println("</TD></TR>");
      }

      i++;

      /*if (i % 25 == 0)
      {
          tblWriter.endTable();
          startNewDocument("institutions"+i+".html", "Institutions " + i, false);
          tblWriter.setHasLines();
      }*/

      // if (i == 100) break;
    }
    tblWriter.endTable();

    Vector<CollStatInfo> sortedByAvesList = new Vector<CollStatInfo>(institutions);
    Collections.sort(
        sortedByAvesList,
        new Comparator<CollStatInfo>() {
          @Override
          public int compare(CollStatInfo o1, CollStatInfo o2) {
            Double i1 = o1.getAveragePercent();
            Double i2 = o2.getAveragePercent();
            int rv = i2.compareTo(i1);
            if (rv == 0) {
              Integer cnt1 = o1.getTotalNumRecords();
              Integer cnt2 = o2.getTotalNumRecords();
              return cnt2.compareTo(cnt1);
            }
            return rv;
          }
        });

    Integer rank = 0;
    String average = "";
    startNewDocument("SortedByAverages.html", " Sorted By Averages", false);
    sortByTblWriter = tblWriter;
    tblWriter.startTable();
    tblWriter.logHdr("Rank", "Institution", "Num of Records", "Percentage");
    for (CollStatInfo csi : sortedByAvesList) {
      String aveStr = String.format("%8.2f", csi.getAveragePercent());
      Integer cnt = csi.getTotalNumRecords();
      if (!aveStr.equals(average)) {
        rank++;
        average = aveStr;
      }

      String fileName = StringUtils.replace(csi.getChartFileName(), "png", "html");
      String link = String.format("<a href=\"%s\">%s</>", fileName, csi.getTitle());
      tblWriter.log(rank.toString(), link, cnt.toString(), aveStr);
    }
    tblWriter.endTable();

    // tblWriter.println("</BODY></HTML>");
    endLogging(true);

    // saveInstitutions();
  }