-1

I found a java application on google code that I downloaded and it has worked great, but I have found an instance where it breaks. I'm new to Java and am trying to reconcile it myself, but I've quickly found myself out of my league. Here is a link to the google project, https://code.google.com/p/yahoo-fan-football-stats/.

The application allows you to download the stats of the players for each team in your fantasy football league. From what I've gathered the application scrubs the yahoo html, builds an array of the stats and then outputs the entire league's data to a csv file.

One part of the application pulls the performance of players which consists of their fantasy points, projected points, and percentage that the player is started. This is seen in line 158 of the code from here, https://code.google.com/p/yahoo-fan-football-stats/source/browse/trunk/src/fantfootball/stats/YahooPlayerStatsDownloader.java. It does this by looking for "pps has-stat-note" in the yahoo html and pulls out the values. It takes all the stats from across all teams into an array.

The issue is that when a player on a team is on a bye week the "pps has-stat-note" dose not exist in the html. This then causes the array size to be different from team to team which in turns causes the application to fail.

private void getPerformance(Document doc, List<PlayerStat> stats) {
    List<Node> players = getNodesFromClass(doc, "pps has-stat-note","a");
    for (int i = 0; i < stats.size(); i++) {
        Node player = players.get(i);
        String points = player.getTextContent();
        String projected = player.getParentNode().getParentNode().getNextSibling().getTextContent();
        String percentage = player.getParentNode().getParentNode().getNextSibling().getNextSibling().getTextContent();

        double converted = Double.parseDouble(percentage.replace("%", ""))/100;

        PlayerStat stat = stats.get(i);
        stat.setPoints(Double.parseDouble(points));
        stat.setProjectedPoints(Double.parseDouble(projected));
        stat.setPerctStart(converted);
       // LOGGER.debug(stat);
    }
}


private List<Node> getNodesFromClass(Document doc, String className, String nodeType) {
    try{
    List<Node> values = new ArrayList<Node>();
    XPath xpath = XPathFactory.newInstance().newXPath();
    String path = "//"+ nodeType + "[contains(@class,'"+className+ "')]";
    NodeList nl = (NodeList) xpath.evaluate(path, doc, XPathConstants.NODESET);

    if(nl == null || nl.getLength() < 1){
        LOGGER.warn("FOUND ZERO NODES FOR " + className);
        return values;
    }

    for (int i = 0; i<nl.getLength(); i++){
        Node n = nl.item(i);
        values.add(n);
    }

    return values;

    }catch(Exception e){
        throw new IllegalStateException(e);
    }

}

}

Is there a way to insert null values into the array if the array for one team isn't the same size as those before it or for me to specify the size of the array? ie. each team has 15 players and if a player is on a bye week then only 14 players are recognized so insert another player with null values.

If so, any tips on how to implement this would be greatly appreciated.

Thanks.

1 Answers1

0
// Um sure but this is just a quik guess by me,

var arr1 = ["P", "P", "P", "P", "P", "P", "P" ]

var arr2 = ["P", "P", "P", "P" ]

fillArr(arr1, arr2);

  function fillArr(i, j){
  if(i.length == j.length) return;
  var b = i.length < j.length ? j : i;
  var s = i.length < j.length ? i : j;

  var l = b.length - s.length;
  var o = s.length;


  for(var k = 0;k < l;++k) s[o + k] = null;

}

user3152069
  • 408
  • 3
  • 9