View Single Post
  #20   Spotlight this post!  
Unread 09-11-2009, 02:44
Andrew Schreiber Andrew Schreiber is offline
Joining the 900 Meme Team
FRC #0079
 
Join Date: Jan 2005
Rookie Year: 2000
Location: Misplaced Michigander
Posts: 4,081
Andrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond reputeAndrew Schreiber has a reputation beyond repute
Re: FRC Event Data in XML Format

There have been some minor updates:

The request can come in any order now, as long as you specify an What and an Event and the When where applicable it will do its best to figure out what you meant.

Human format has been tweaked to be tabular.

XML option should be a little more standard. I am now using an XML generator instead of just string concatenation.

Got rid of all evals in the python code. I also cleaned up the code to use one function in the place of 4.

Also, as a small project I decided to put together some a Javascript object for getting data. I forgot how ugly Javascript's object stuff is. I have included it below.

Code:
function Event(eventCode,year){
  this.eventCode = eventCode;
  this.year = year;
}

Event.prototype.getRankings = function(){
  myEvent = this
  url = "http://frcfeed.appspot.com/"+myEvent.year+"/"+myEvent.eventCode+"/rankings/json"
  new AJAX_Request(url,function(){myEvent.Rankings = eval("("+xmlhttp.responseText+")")},myEvent)
  return myEvent
  }
  
Event.prototype.getAwards = function(){
  myEvent = this
  url = "http://frcfeed.appspot.com/"+myEvent.year+"/"+myEvent.eventCode+"/awards/json"
  new AJAX_Request(url,function(){myEvent.Awards = eval("("+xmlhttp.responseText+")")},myEvent)
  return myEvent
}

Event.prototype.getQualificationSchedule = function(){
  myEvent = this
  url = "http://frcfeed.appspot.com/"+myEvent.year+"/"+myEvent.eventCode+"/qualification/schedule/json"
  new AJAX_Request(url,function(){myEvent.Qualification_Schedule = eval("("+xmlhttp.responseText+")")},myEvent)
  return myEvent
}

Event.prototype.getEliminationSchedule = function(){
  myEvent = this
  url = "http://frcfeed.appspot.com/"+myEvent.year+"/"+myEvent.eventCode+"/elimination/schedule/json"
  new AJAX_Request(url,function(){myEvent.Elimination_Schedule = eval("("+xmlhttp.responseText+")")},myEvent)
  return myEvent
}

Event.prototype.getQualificationResults = function(){
  myEvent = this
  url = "http://frcfeed.appspot.com/"+myEvent.year+"/"+myEvent.eventCode+"/qualification/results/json"
  new AJAX_Request(url,function(){myEvent.Qualification_Results = eval("("+xmlhttp.responseText+")")},myEvent)
  return myEvent
}

Event.prototype.getEliminationResults = function(){
  myEvent = this
  url = "http://frcfeed.appspot.com/"+myEvent.year+"/"+myEvent.eventCode+"/elimination/results/json"
  new AJAX_Request(url,function(){myEvent.Elimination_Results = eval("("+xmlhttp.responseText+")")},myEvent)
  return myEvent
}


// Utility Functions
function AJAX_Request(url,handlerFunction,newEvent){
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else{
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  url = url
  xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
    handlerFunction(newEvent)
    }
  }
  xmlhttp.open("GET",url,true);
  xmlhttp.send(null);
}
Usage is incredibly simple, create an Event and then get whatever data you want. The data will be placed inside the Event object. Below is an example of getting the first team on the winning alliance.
Code:
kettering = new Event("Kettering",2009);
kettering.getAwards();
kettering.Awards["Regional Winner #1"]["Team"]
__________________




.
Reply With Quote