public void processHostTaskData() {
    try {
      PreparedStatement pstmt = sqlConnection.prepareStatement(Queries.getSqlInsertHostTaskInfo());
      AggregationOutput aggregationOutput =
          mongoTask.getAggregatedOutput("task", Queries.getHostTaskInfoQuery());
      for (DBObject obj : aggregationOutput.results()) {
        String timeStamp = (String) obj.get("timestamp");
        String action = (String) obj.get("action");
        String target = (String) obj.get("target");
        double timeTaken = Double.parseDouble(obj.get("timeTaken").toString());

        pstmt.setTimestamp(
            1,
            new java.sql.Timestamp(
                MongoAggregationHelper.jsonDateFormat.parse(timeStamp).getTime()));
        pstmt.setString(2, target);
        pstmt.setString(3, action);
        pstmt.setDouble(4, timeTaken);
        pstmt.setInt(5, 1);
        pstmt.addBatch();
      }
      pstmt.executeBatch();
    } catch (SQLException | ParseException s) {
      s.printStackTrace();
    }
  }
Esempio n. 2
0
  private Notificacion armarNotificacion(ResultSet rs) {
    DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Notificacion n = new Notificacion();
    try {
      n.setId(rs.getInt("id"));
      n.setFecha_envio(format.parse(rs.getString("fecha_envio")));
      n.setFecha_recepcion(format.parse(rs.getString("fecha_recepcion")));
      n.setContenido(rs.getString("contenido"));
      n.setContexto(rs.getString("contexto"));
      n.setNinio(rs.getString("ninio"));
      n.setCategoria(rs.getString("categoria"));

      // agregar etiquetas
      Statement st2 = connect.createStatement();
      ResultSet rs2;
      ArrayList<String> etiquetas = new ArrayList<String>();
      rs2 =
          st2.executeQuery(
              "SELECT * FROM notificacion_etiqueta, etiquetas WHERE notificacion_id = "
                  + n.getId()
                  + " AND notificacion_etiqueta.etiqueta_id = etiquetas.id");
      while (rs2.next()) {
        etiquetas.add(rs2.getString("texto"));
      }

      n.setEtiquetas(etiquetas);

    } catch (SQLException | ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return n;
  };
  private void end_of_month_LMC() {
    // TODO Auto-generated method stub
    //	String sql ="SELECT SUM(x.rmc) FROM (SELECT a.permno,a.yrmo,(a.value1*b.value1) as rmc FROM
    // (SELECT permno,yrmo,value1 FROM caaf_marketcapitalization WHERE yrmo=201501) a INNER JOIN
    // (SELECT permno,yrmo,value1 FROM caaf_returns WHERE yrmo = 201501) b ON a.permno = b.permno) x
    // INNER JOIN  (SELECT DISTINCT(PERMNO_date) FROM capm_drawdowns_date WHERE
    // DATE(CAPM_resid_date) BETWEEN '2014-12-16' AND '2015-01-15' ORDER BY CAPM_resid_date ) y ON
    // x.permno = y.PERMNO_date";

    SessionFactory SFact = new Configuration().configure().buildSessionFactory();
    Session session = SFact.openSession();
    session.beginTransaction();

    db_connections db_con = new db_connections();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    ArrayList<String> indexDates = get_index_dates();
    ArrayList<Double> endOfMonthVales = new ArrayList<Double>();
    ArrayList<String> endOFMonthDates = new ArrayList<String>();
    ArrayList<Double> endOfMonthVales_top_ten = new ArrayList<Double>();
    ArrayList<String> endOFMonthDates_top_ten = new ArrayList<String>();

    //	ArrayList<Double> cumulative_LMC_top_ten_values = new ArrayList<Double>();
    //	ArrayList<String> cumulative_LMC_top_ten_date = new ArrayList<String>();

    for (int i = 0; i < indexDates.size() - 1; i++) {
      String d1temp = indexDates.get(i);
      Calendar c = Calendar.getInstance();
      try {
        c.setTime(dateFormat.parse(d1temp));
      } catch (ParseException e1) {
        e1.printStackTrace();
      }
      c.add(Calendar.DATE, 1);
      String d1 = dateFormat.format(c.getTime());

      String d2 = indexDates.get(i + 1);
      String[] parts = d2.split("-");
      int yrmo = Integer.valueOf(parts[0] + "" + parts[1]);

      String sql =
          "SELECT SUM(x.rmc) FROM (SELECT a.permno,a.yrmo,(a.value1*b.value1) as rmc FROM (SELECT permno,yrmo,value1 FROM caaf_marketcapitalization WHERE yrmo='"
              + yrmo
              + "') a INNER JOIN (SELECT permno,yrmo,value1 FROM caaf_returns WHERE yrmo = '"
              + yrmo
              + "') b ON a.permno = b.permno) x INNER JOIN  (SELECT DISTINCT(PERMNO_date) FROM capm_drawdowns_date WHERE DATE(CAPM_resid_date) BETWEEN '"
              + d1
              + "' AND '"
              + d2
              + "' ORDER BY CAPM_resid_date ) y ON x.permno = y.PERMNO_date";
      String sql_top_ten =
          "SELECT SUM(c.mcap*d.value1) from (SELECT a.permno,a.yrmo,a.value1 as mcap FROM (SELECT permno,yrmo,value1 FROM caaf_marketcapitalization )as a JOIN (SELECT DISTINCT(PERMNO) from	sys_top10_losess WHERE CAPM_resid_date BETWEEN '"
              + d1
              + "' AND '"
              + d2
              + "') as b ON a.permno = b.permno and a.yrmo = '"
              + yrmo
              + "') as c JOIN caaf_returns as d ON c.permno=d.permno and c.yrmo =d.yrmo";
      // String sql_top_ten="SELECT SUM(a.marketCapitalization*b.value1) FROM (SELECT
      // PERMNO,YRMO,marketCapitalization,CAPM_resid_date FROM sys_top10_losess WHERE
      // DATE(CAPM_resid_date) BETWEEN '"+d1+"' AND '"+d2+"' ORDER BY CAPM_resid) AS a INNER JOIN
      // (SELECT permno,yrmo,value1 FROM caaf_returns WHERE yrmo='"+yrmo+"') AS b ON
      // a.PERMNO=b.permno";
      // String sql_LMC ="SELECT SUM(LOSSMcap) FROM sys_top10_losess WHERE DATE(CAPM_resid_date)
      // BETWEEN '"+d1+"' AND '"+d2+"' ORDER BY CAPM_resid";
      String sqlyas =
          "SELECT SUM(x.LOSSMcap) FROM (SELECT * from sys_top10_losess_with_ratings WHERE Drawdown_rate < 9549 AND DATE(CAPM_resid_date) BETWEEN '"
              + d1
              + "' AND '"
              + d2
              + "' UNION SELECT * from sys_top10_losess_with_ratings WHERE Mcap_rate < 9549 AND DATE(CAPM_resid_date) BETWEEN '"
              + d1
              + "' AND '"
              + d2
              + "') as x";

      try {
        Date eDate = dateFormat.parse(d2);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(eDate);
        calendar.add(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.add(Calendar.DATE, -1);
        Date lastDayOfMonth = calendar.getTime();

        ResultSet rsetee = db_con.selectData(sqlyas);
        if (rsetee.next()) {
          System.out.println(
              dateFormat.format(lastDayOfMonth) + "," + rsetee.getDouble("SUM(x.LOSSMcap)"));
          // endOfMonthVales.add(rset.getDouble("SUM(x.rmc)"));
          // endOFMonthDates.add(dateFormat.format(lastDayOfMonth));
        }

        /**
         * ResultSet rset = db_con.selectData(sql); if(rset.next()){
         * System.out.println(rset.getDouble("SUM(x.rmc)")+" non
         * "+dateFormat.format(lastDayOfMonth)); endOfMonthVales.add(rset.getDouble("SUM(x.rmc)"));
         * endOFMonthDates.add(dateFormat.format(lastDayOfMonth)); }
         *
         * <p>ResultSet rset_top_ten = db_con.selectData(sql_top_ten); if(rset_top_ten.next()){
         * System.out.println(rset_top_ten.getDouble("SUM(c.mcap*d.value1)")+" top10
         * "+dateFormat.format(lastDayOfMonth));
         * endOfMonthVales_top_ten.add(rset_top_ten.getDouble("SUM(c.mcap*d.value1)"));
         * endOFMonthDates_top_ten.add(dateFormat.format(lastDayOfMonth)); }
         */

        /*
        ResultSet rset_lmc_top_ten = db_con.selectData(sql_LMC);
        if(rset_lmc_top_ten.next()){
        	System.out.println(rset_lmc_top_ten.getDouble("SUM(LOSSMcap)")+" date "+dateFormat.format(lastDayOfMonth));

        }
        */
      } catch (SQLException | ParseException e) {
        e.printStackTrace();
      }
    }
    /**
     * for (int i = 0; i < endOfMonthVales.size(); i++) { Sys_CLM_EndofMonthLMC obj = new
     * Sys_CLM_EndofMonthLMC(); obj.setLmcdate(endOFMonthDates.get(i));
     * obj.setValue(endOfMonthVales.get(i)); session.save(obj); } for (int i = 0; i <
     * endOfMonthVales_top_ten.size(); i++) { Sys_CLM_EndofMonthLMC_top_ten obj = new
     * Sys_CLM_EndofMonthLMC_top_ten(); obj.setLmcdate(endOFMonthDates_top_ten.get(i));
     * obj.setValue(endOfMonthVales_top_ten.get(i)); session.save(obj); }
     * session.getTransaction().commit();
     */
  }