hi, ich bin der webmaster von dem deutschen team des distributed computing projekts climateprediction.
für the website (www.cpdndeutschland.de.vu) habe ich ein script geschrieben das die xml-stats ausliest und formatiert in die mysql gibt.
my code:
Das script kann ganz normal ausgeführt werden und wird ohne fehler beendet. auch landen die werte richtig in der mysql, aber nur die ersten 8 von über 110.
wär sehr nett wenn sich n paar von euch mal die zeit nehmen könnten sich das script genauer anzuschaun, weil ich bin schon seit über einem tag dran, und kann den fehler nicht finden.
vielen dank schonmal
greez scorpion2k
für the website (www.cpdndeutschland.de.vu) habe ich ein script geschrieben das die xml-stats ausliest und formatiert in die mysql gibt.
my code:
PHP-Code:
<?
include("confixx.php");
//$source = "grpstatsxml-id.xml";
$source = "http://cpdn.comlab.ox.ac.uk/user/grpstatsxml.php?gid=349";
$open = fopen($source,"b");
$read = fread($open,50000);
$gentime = substr($read,strpos($read,"<GENERATED>")+11,strpos($read,"</GENERATED>")-strpos($read,"<GENERATED>")-11);
$sumend = strpos($read,"</SUMMARY>");
$read = substr($read,$sumend);
$array = explode("</USER>",$read);
for($i=1;$i<=count($array)-1;$i++)
{
$name = substr($array[$i-1],strpos($array[$i-1],"<NAME>")+6,strpos($array[$i-1],"</NAME>")-strpos($array[$i-1],"<NAME>")-6);
$name = str_replace (" ","%20",$name);
$machines = substr($array[$i-1],strpos($array[$i-1],"<ACTIVEMACHINES>")+16,strpos($array[$i-1],"</ACTIVEMACHINES>")-strpos($array[$i-1],"<ACTIVEMACHINES>")-16);
$modelyears = substr($array[$i-1],strpos($array[$i-1],"<MODELYEAR>")+11,strpos($array[$i-1],"</MODELYEAR>")-strpos($array[$i-1],"<MODELYEAR>")-11);
$cpudays = substr($array[$i-1],strpos($array[$i-1],"<CPUDAYS>")+9,strpos($array[$i-1],"</CPUDAYS>")-strpos($array[$i-1],"<CPUDAYS>")-9);
//überprüfen ob user exsistiert, ansonsten anlegen
$result = mysql_query("SELECT id FROM stats_users WHERE username = '$name'");
if(mysql_num_rows($result) == 0)
{
mysql_query("INSERT INTO stats_users (username) VALUES ('$name')");
$id = mysql_insert_id();
}
else
{
$row = mysql_fetch_array($result);
$id = $row['id'];
}
//Persönliche Stats lesen
$source2 = "http://cpdn.comlab.ox.ac.uk/user/userxml.php?name=$name";
$open2 = fopen($source2,"r");
$read2 = fread($open2,750);
$tslast = substr($read2,strpos($read2,"<TSLAST>")+8,strpos($read2,"</TSLAST>")-strpos($read2,"<TSLAST>")-8);
$last_phase = substr($read2,strpos($read2,"<PHASELAST>")+11,strpos($read2,"</PHASELAST>")-strpos($read2,"<PHASELAST>")-11);
$runs_started = substr($read2,strpos($read2,"<RUNSALLOC>")+11,strpos($read2,"</RUNSALLOC>")-strpos($read2,"<RUNSALLOC>")-11);
$shortruns = substr($read2,strpos($read2,"<RUNSSHORT>")+11,strpos($read2,"</RUNSSHORT>")-strpos($read2,"<RUNSSHORT>")-11);
$clompleteruns = substr($read2,strpos($read2,"<RUNSCOMP>")+10,strpos($read2,"</RUNSCOMP>")-strpos($read2,"<RUNSCOMP>")-10);
$last_trickle = substr($read2,strpos($read2,"<TRICKLELAST>")+13,strpos($read2,"</TRICKLELAST>")-strpos($read2,"<TRICKLELAST>")-13);
$regdate = substr($read2,strpos($read2,"<REGDATE>")+9,strpos($read2,"</REGDATE>")-strpos($read2,"<REGDATE>")-9);
$total_rank = substr($read2,strpos($read2,"<RANKING>")+9,strpos($read2,"</RANKING>")-strpos($read2,"<RANKING>")-9);
//last trickle => formatting
$last_trickle_day = substr($last_trickle,0,2);
$last_trickle_month = substr($last_trickle,3,3);
$month_array = array("01" => "Jan","02" => "Feb","03" => "Mar","04" => "Apr","05" => "May","06" => "Jun","07" => "Jul","08" => "Aug","09" => "Sep","10" => "Oct","11" => "Nov","12" => "Dec");
$last_trickle_month = array_search($last_trickle_month,$month_array);
$last_trickle_year = substr($last_trickle,7,2);
$last_trickle_hour = substr($last_trickle,10,2);
$last_trickle_minute = substr($last_trickle,13,2);
$last_trickle_second = substr($last_trickle,16,2);
// last trickle => creating timestamp
$last_trickle_timestamp = mktime($last_trickle_hour,$last_trickle_minute,$last_trickle_second,$last_trickle_month,$last_trickle_day,$last_trickle_year);
//regdate => formatting
$regdate_day = substr($regdate,0,2);
$regdate_month = substr($regdate,3,3);
$regdate_month = array_search($regdate_month,$month_array);
$regdate_year = substr($regdate,7,2);
$regdate_hour = substr($regdate,10,2);
$regdate_minute = substr($regdate,13,2);
$regdate_second = substr($regdate,16,2);
// regdate => creating timestamp
$regdate_timestamp = mktime($regdate_hour,$regdate_minute,$regdate_second,$regdate_month,$regdate_day,$regdate_year);
$total_rank = str_replace("out of","/",$total_rank);
//trennzeichen
$id2 .= "$id . ";
$name2 .= "$name . ";
$machines2 .= "$machines . ";
$modelyears2 .= "$modelyears . ";
$cpudays2 .= "$cpudays . ";
$tslast2 .= "$tslast . ";
$last_phase2 .= "$last_phase2 . ";
$runs_started2 .= "$runs_started . ";
$shortruns2 .= "$shortruns . ";
$clompleteruns2 .= "$clompleteruns . ";
$last_trickle_timestamp2 .= "$last_trickle_timestamp . ";
$regdate_timestamp2 .= "$regdate_timestamp . ";
$total_rank2 .= "$total_rank . ";
}
// " . " am Ende entfernen
$id2 = substr($id2,0,strlen($id2)-3);
$name2 = substr($name2,0,strlen($name2)-3);
$machines2 = substr($machines2,0,strlen($machines2)-3);
$modelyears2 = substr($modelyears2,0,strlen($modelyears2)-3);
$cpudays2 = substr($cpudays2,0,strlen($cpudays2)-3);
$tslast2 = substr($tslast2,0,strlen($tslast2)-3);
$last_phase2 = substr($last_phase2,0,strlen($last_phase2)-3);
$runs_started2 = substr($runs_started2,0,strlen($runs_started2)-3);
$shortruns2 = substr($shortruns2,0,strlen($shortruns2)-3);
$clompleteruns2 = substr($clompleteruns2,0,strlen($clompleteruns2)-3);
$last_trickle_timestamp2 = substr($last_trickle_timestamp2,0,strlen($last_trickle_timestamp2)-3);
$regdate_timestamp2 = substr($regdate_timestamp2,0,strlen($regdate_timestamp2)-3);
$total_rank2 = substr($total_rank2,0,strlen($total_rank2)-3);
$date = time();
mysql_query("INSERT INTO stats_user_data (generated,date,userid,computer,modelyears,cpudays,last_phase,last_ts,runs_started,shortruns,completeruns,last_trickle,regdate,total_rank) VALUES ('$gentime','$date','$id2','$machines2','$modelyears2','$cpudays2','$tslast2','$last_phase2','$runs_started2','$shortruns2','$clompleteruns2','$last_trickle_timestamp2','$regdate_timestamp2','$total_rank2')");
?>
Das script kann ganz normal ausgeführt werden und wird ohne fehler beendet. auch landen die werte richtig in der mysql, aber nur die ersten 8 von über 110.
wär sehr nett wenn sich n paar von euch mal die zeit nehmen könnten sich das script genauer anzuschaun, weil ich bin schon seit über einem tag dran, und kann den fehler nicht finden.
vielen dank schonmal
greez scorpion2k
Kommentar