コード例 #1
0
  private WebPage parseDocFirstModel(URL url, Document doc) throws Exception {
    // 2 : horses
    Elements horsesUrl = doc.select("table.tablesorter.tableauLine tbody tr td:eq(1) a[href]");
    Elements horsesCotes = doc.select("table.tablesorter.tableauLine tbody tr td:eq(11)");
    Elements horsesJockey = doc.select("table.tablesorter.tableauLine tbody tr td:eq(7) a[href]");
    Elements horsesTrainers = doc.select("table.tablesorter.tableauLine tbody tr td:eq(8) a[href]");
    fl = new FinishList();
    Elements horsesPredictions = doc.select("table.tablesorter.tableauLine tbody tr");
    Elements jockeyWeights = doc.select("table.tablesorter.tableauLine tbody tr");
    Elements horsesCordes = doc.select("table.tablesorter.tableauLine tbody tr");
    Elements horsesOeilleres = doc.select("table.tablesorter.tableauLine tbody tr");

    WpDetailsTurfoModelOne wp = new WpDetailsTurfoModelOne(url, null, null);

    for (int i = 0; i < horsesPredictions.size(); i++) {
      String name = horsesPredictions.get(i).select("td:eq(1) a").text().trim().toString();
      Float weight = null;

      try {
        weight =
            Float.parseFloat(
                jockeyWeights
                    .get(i)
                    .select("td:eq(4)")
                    .text()
                    .trim()
                    .toString()
                    .replaceAll(",", "."));
      } catch (Exception e) {
        logger.error(e);
      }

      Integer corde = null;
      try {
        corde = Integer.parseInt(horsesCordes.get(i).select("td:eq(5)").text().trim().toString());
      } catch (Exception e) {
        logger.error(e);
      }
      String oeilleres = horsesOeilleres.get(i).select("td:eq(10)").text().trim().toString();

      logger.debug("... name : " + name);
      logger.debug("... weight : " + weight);
      logger.debug("... corde : " + corde);
      logger.debug("... oeilleres : " + oeilleres);
      if (withHorseDetail) {
        try {
          int rang = (i + 1);
          Float cote = null;

          try {
            cote = Float.parseFloat(horsesCotes.get(i).text());
            logger.debug(cote);
          } catch (Exception e) {
            cote = null;
          }

          // logger.debug("horse text name : " + horsesUrl.get(i).text());
          String horseURL =
              new URL(url, horsesUrl.get(i).attr("href").trim().toString()).toString();
          String horseJockey = horsesJockey.get(i).text();
          String horseTrainer = horsesTrainers.get(i).text();

          logger.debug("___________________________");
          logger.debug("... new finish");
          logger.debug("... rank : " + rang);
          logger.debug("... cote : " + cote);
          logger.debug("... horse found : " + horseURL);
          logger.debug("... jockey found : " + horseJockey);

          WebPage horseWebPage = this.horseParser.parse(new URL(horseURL));
          // look in detailed statistics to get values corresponding to
          // the horseName

          Finish finish = new Finish(-1, cote, horseJockey, horseTrainer, horseWebPage);
          finish.setPoids(weight);
          finish.setCorde(corde);
          finish.setOeilleres(oeilleres);
          fl.getFinishes().add(finish);
        } catch (Exception e) {
          logger.error(e);
        }
        ((WpDetailsTurfo) wp).setFinishList(fl);
      }
      wp.addPronostic(name, weight, corde, oeilleres);
    }

    logger.debug("... set prediction");
    try {
      wp.setPrediction(getPrediction(doc));
    } catch (Exception e) {
      logger.error("... no prediction found");
      logger.error(e);
    }

    logger.debug("... return");
    // logger.debug(wp.serialize());
    return wp;
  }
コード例 #2
0
  private WebPage parseDocSecondModel(URL url, Document doc) throws Exception {
    // TODO Auto-generated metho	//2 : horses
    Elements horsesUrl = doc.select("table.tablesorter.tableauLine tbody tr td:eq(1) a[href]");
    Elements horsesCotes = doc.select("table.tablesorter.tableauLine tbody tr td:eq(11)");
    Elements horsesJockey = doc.select("table.tablesorter.tableauLine tbody tr td:eq(7) a[href]");
    Elements horsesTrainers = doc.select("table.tablesorter.tableauLine tbody tr td:eq(8) a[href]");
    fl = new FinishList();
    Elements horsesDistance = doc.select("table.tablesorter.tableauLine tbody tr");
    Elements horsesRecord = doc.select("table.tablesorter.tableauLine tbody tr");
    WpDetailsTurfoModelTwo wp = new WpDetailsTurfoModelTwo(url, null, null);

    for (int i = 0; i < horsesDistance.size(); i++) {
      String name = horsesDistance.get(i).select("td:eq(1) a").text().trim().toString();
      Integer distance =
          Integer.parseInt(horsesDistance.get(i).select("td:eq(4)").text().trim().toString());

      String time = horsesRecord.get(i).select("td:eq(9)").text().trim().toString();
      String timePatternParsing = "([0-9]+)'([0-9]+)\"([0-9]+)";
      Pattern patternTime = Pattern.compile(timePatternParsing);
      java.util.regex.Matcher matcherTime = patternTime.matcher(time);

      Period period = null;

      if (matcherTime.find()) {
        period =
            new Period(
                0,
                Integer.parseInt(matcherTime.group(1)),
                Integer.parseInt(matcherTime.group(2)),
                (Integer.parseInt(matcherTime.group(3)) * 100));
      } else {
        logger.warn("... time is at a weird format");
      }

      logger.debug("... name :" + name);
      logger.debug("... period :" + period.toStandardDuration().getMillis());
      logger.debug("... distance :" + distance);
      if (withHorseDetail) {
        try {
          int rang = (i + 1);
          Float cote = null;

          try {
            cote = Float.parseFloat(horsesCotes.get(i).text());
            logger.debug(cote);
          } catch (Exception e) {
            cote = null;
          }

          // logger.debug("horse text name : " + horsesUrl.get(i).text());
          String horseURL =
              new URL(url, horsesUrl.get(i).attr("href").trim().toString()).toString();
          String horseJockey = horsesJockey.get(i).text();
          String horseTrainer = horsesTrainers.get(i).text();

          logger.debug("___________________________");
          logger.debug("... new finish");
          logger.debug("... rank : " + rang);
          logger.debug("... cote : " + cote);
          logger.debug("... horse found : " + horseURL);
          logger.debug("... jockey found : " + horseJockey);

          WebPage horseWebPage = this.horseParser.parse(new URL(horseURL));
          // look in detailed statistics to get values corresponding to
          // the horseName

          Finish finish = new Finish(-1, cote, horseJockey, horseTrainer, horseWebPage);
          finish.setPeriod(period);
          finish.setDistance(distance);
          fl.getFinishes().add(finish);
        } catch (Exception e) {
          logger.error(e);
        }
        ((WpDetailsTurfo) wp).setFinishList(fl);
      }
      wp.addPronostic(name, period, distance);
    }

    logger.debug("... set prediction");
    try {
      wp.setPrediction(getPrediction(doc));
    } catch (Exception e) {
      logger.error("... no prediction found");
      logger.error(e);
    }

    return wp;
  }