PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/ems/web/overview.php

https://bitbucket.org/xwd/moses-csp
PHP | 384 lines | 343 code | 34 blank | 7 comment | 100 complexity | 47f88a31bb78c4099602dff18d6b6470 MD5 | raw file
  1. <?php
  2. date_default_timezone_set('Europe/London');
  3. function setup() {
  4. $setup = file("setup");
  5. head("All Experimental Setups");
  6. print "<table border=1 cellpadding=1 cellspacing=0>\n";
  7. print "<TR><TD>ID</TD><TD>User</TD><TD>Task</TD><TD>Directory</TD></TR>\n";
  8. $rev = array_reverse($setup);
  9. while (list($i,$line) = each($rev)) {
  10. $dir = explode(";",$line);
  11. print "<TR><TD><A HREF=\"?setup=$dir[0]\">$dir[0]</A></TD><TD>$dir[1]</TD><TD>$dir[2]</TD><TD>$dir[3]</TD></TR>\n";
  12. }
  13. print "</TABLE>\n";
  14. print "<P>To add experiment, edit setup in web directory";
  15. }
  16. function overview() {
  17. global $evalset;
  18. global $experiment,$comment;
  19. global $task,$user,$setup;
  20. global $dir;
  21. global $has_analysis;
  22. $has_analysis = array();
  23. head("Task: $task ($user)");
  24. print "<a href=\"http://www.statmt.org/wiki/?n=Experiment.$setup\">Wiki Notes</a>";
  25. print " &nbsp; &nbsp; | &nbsp; &nbsp; <a href=\"/\">Overview of experiments</a> &nbsp; &nbsp; | &nbsp; &nbsp; <code>$dir</code><p>";
  26. reset($experiment);
  27. print "<form action=\"\" method=get>\n";
  28. output_state_for_form();
  29. // count how many analyses there are for each test set
  30. while (list($id,$info) = each($experiment)) {
  31. reset($evalset);
  32. while (list($set,$dummy) = each($evalset)) {
  33. $analysis = "$dir/evaluation/$set.analysis.$id";
  34. $report_info = "$dir/steps/$id/REPORTING_report.$id.INFO";
  35. // does the analysis file exist?
  36. if (file_exists($analysis)) {
  37. if (!array_key_exists($set,$has_analysis)) {
  38. $has_analysis[$set] = 0;
  39. }
  40. $has_analysis[$set]++;
  41. }
  42. }
  43. }
  44. reset($experiment);
  45. print "<table border=1 cellpadding=1 cellspacing=0>
  46. <tr><td><input type=submit name=diff value=\"compare\"></td>
  47. <td align=center>ID</td>
  48. <td align=center>start</td>
  49. <td align=center>end</td>\n";
  50. reset($evalset);
  51. while (list($set,$dummy) = each($evalset)) {
  52. if (array_key_exists($set,$has_analysis)) {
  53. print "<td align=center colspan=2>";
  54. if ($has_analysis[$set]>=2) {
  55. print " <input type=submit name=\"analysis_diff_home\" value=\"$set\">";
  56. }
  57. else {
  58. print $set;
  59. }
  60. print "</td>";
  61. }
  62. else {
  63. print "<td align=center>$set</td>";
  64. }
  65. }
  66. print "</tr>\n";
  67. while (list($id,$info) = each($experiment)) {
  68. $state = return_state_for_link();
  69. print "<tr id=\"row-$id\" onMouseOver=\"highlightLine($id);\" onMouseOut=\"highlightBest();\"><td><input type=checkbox name=run[] value=$id><a href=\"?$state&show=config.$id\">cfg</a>|<a href=\"?$state&show=parameter.$id\">par</a>|<a href=\"?$state&show=graph.$id.png\">img</a></td><td><span id=run-$setup-$id><a href='javascript:createCommentBox(\"$setup-$id\");'>[$setup-$id]</a>";
  70. if (array_key_exists("$setup-$id",$comment)) {
  71. print " ".$comment["$setup-$id"]->name;
  72. }
  73. print "</span></td><td align=center>".mytime($info->start,0)."</td><td align=center>";
  74. if (mytime($info->end,1) == "running") {
  75. print "<font size=-2>".$info->last_step;
  76. if ($info->last_step == "TUNING<BR>tune") {
  77. print "<BR>".tune_status($id);
  78. }
  79. }
  80. else if (property_exists($info,"result")) {
  81. print mytime($info->end,1);
  82. print "<br><font size=-2>";
  83. print dev_score("$dir/tuning/moses.ini.$id");
  84. }
  85. else {
  86. print "<font color=red>crashed";
  87. }
  88. print "</td>";
  89. output_score($id,$info);
  90. print "</tr>\n";
  91. }
  92. print "</table>";
  93. print "<script language=\"javascript\" type=\"text/javascript\">\n";
  94. print "var currentComment = new Array();\n";
  95. reset($experiment);
  96. while (list($id,$info) = each($experiment)) {
  97. if (array_key_exists("$setup-$id",$comment)) {
  98. print "currentComment[\"$setup-$id\"] = \"".$comment["$setup-$id"]->name."\";\n";
  99. }
  100. }
  101. reset($experiment);
  102. $best = array();
  103. print "var score = [];\n";
  104. while (list($id,$info) = each($experiment)) {
  105. reset($evalset);
  106. print "score[$id] = [];\n";
  107. while (list($set,$dummy) = each($evalset)) {
  108. if (property_exists($info,"result") &&
  109. array_key_exists($set,$info->result)) {
  110. list($score) = sscanf($info->result[$set],"%f%s");
  111. if ($score > 0) {
  112. print "score[$id][\"$set\"] = $score;\n";
  113. if (!array_key_exists($set,$best) || $score > $best[$set]) {
  114. $best[$set] = $score;
  115. }
  116. }
  117. }
  118. else { $score = ""; }
  119. }
  120. }
  121. print "var best_score = [];\n";
  122. reset($evalset);
  123. while (list($set,$dummy) = each($evalset)) {
  124. print "best_score[\"$set\"] = ".$best[$set].";\n";
  125. }
  126. ?>
  127. // Get the HTTP Object
  128. function getHTTPObject(){
  129. if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
  130. else if (window.XMLHttpRequest) return new XMLHttpRequest();
  131. else {
  132. alert("Your browser does not support AJAX.");
  133. return null;
  134. }
  135. }
  136. function createCommentBox( runID ) {
  137. document.getElementById("run-" + runID).innerHTML = "<form onsubmit=\"return false;\"><input id=\"comment-" + runID + "\" name=\"comment-" + runID + "\" size=30><br><input type=submit onClick=\"addComment('" + runID + "');\" value=\"Add Comment\"></form>";
  138. if (currentComment[runID]) {
  139. document.getElementById("comment-" + runID).value = currentComment[runID];
  140. }
  141. document.getElementById("comment-" + runID).focus();
  142. }
  143. var httpObject = null;
  144. function addComment( runID ) {
  145. httpObject = null;
  146. httpObject = getHTTPObject();
  147. if (httpObject != null) {
  148. httpObject.onreadystatechange = setComment;
  149. httpObject.open("GET", "comment.php?run="+encodeURIComponent(runID)+"&text="
  150. +encodeURIComponent(document.getElementById('comment-'+runID).value), true);
  151. httpObject.send(null);
  152. currentComment[runID] = document.getElementById('comment-'+runID).value;
  153. document.getElementById("run-" + runID).innerHTML = "<a href='javascript:createCommentBox(\"" + runID + "\");'>[" + runID + "]</a> " + document.getElementById('comment-'+runID).value;
  154. }
  155. return true;
  156. }
  157. function setComment() {
  158. if(httpObject.readyState == 4){
  159. //alert("c:" +httpObject + httpObject.status + " " + httpObject.responseText);
  160. httpObject = null;
  161. }
  162. }
  163. function highlightBest() {
  164. lowlightAll();
  165. for (set in best_score) {
  166. for (run in score) {
  167. var column = "score-"+run+"-"+set;
  168. if ($(column)) {
  169. if (score[run][set] == best_score[set]) {
  170. $(column).setStyle({ backgroundColor: '#a0ffa0'});
  171. }
  172. else if (score[run][set]+1 >= best_score[set]) {
  173. $(column).setStyle({ backgroundColor: '#e0ffe0'});
  174. }
  175. }
  176. }
  177. }
  178. }
  179. function highlightLine( id ) {
  180. lowlightAll();
  181. var row = "row-"+id;
  182. $(row).setStyle({ backgroundColor: '#f0f0f0'});
  183. for (set in score[id]) {
  184. for (run in score) {
  185. var column = "score-"+run+"-"+set;
  186. if ($(column)) {
  187. if (run == id) {
  188. $(column).setStyle({ backgroundColor: '#ffffff'});
  189. }
  190. else {
  191. if (score[run][set] < score[id][set]-1) {
  192. $(column).setStyle({ backgroundColor: '#ffa0a0'});
  193. }
  194. else if (score[run][set] < score[id][set]) {
  195. $(column).setStyle({ backgroundColor: '#ffe0e0'});
  196. }
  197. else if (score[run][set] > score[id][set]+1) {
  198. $(column).setStyle({ backgroundColor: '#a0ffa0'});
  199. }
  200. else if (score[run][set] > score[id][set]) {
  201. $(column).setStyle({ backgroundColor: '#e0ffe0'});
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. function lowlightAll() {
  209. for (run in score) {
  210. var row = "row-"+run
  211. if ($(row)) {
  212. $(row).setStyle({ backgroundColor: 'transparent' });
  213. }
  214. for (set in best_score) {
  215. var column = "score-"+run+"-"+set;
  216. if ($(column)) {
  217. $(column).setStyle({ backgroundColor: 'transparent' });
  218. }
  219. }
  220. }
  221. }
  222. function highlightScore() {
  223. }
  224. highlightBest();
  225. //-->
  226. </script>
  227. <?php
  228. }
  229. function mytime($timestamp,$running) {
  230. if ($running && $timestamp + 300 > time()) {
  231. return "running";
  232. }
  233. if ($timestamp + 12*3600 > time()) {
  234. return strftime("%T",$timestamp);
  235. }
  236. if ($timestamp + 5*24*3600 > time()) {
  237. return strftime("%a %H:%M",$timestamp);
  238. }
  239. return strftime("%d %b",$timestamp);
  240. }
  241. function output_score($id,$info) {
  242. global $evalset;
  243. global $has_analysis;
  244. global $setup;
  245. global $dir;
  246. reset($evalset);
  247. $state = return_state_for_link();
  248. while (list($set,$dummy) = each($evalset)) {
  249. if (property_exists($info,"result") &&
  250. array_key_exists($set,$info->result)) {
  251. $score = $info->result[$set];
  252. }
  253. else { $score = ""; }
  254. print "<td align=center id=\"score-$id-$set\">";
  255. // print "<table><tr><td>";
  256. $each_score = explode(" ; ",$score);
  257. for($i=0;$i<count($each_score);$i++) {
  258. if (preg_match('/([\d\(\)\.\s]+) (\S*)/',$each_score[$i],$match)) {
  259. //if ($i>0) { print "&nbsp;"; }
  260. $opened_a_tag = 0;
  261. if ($set != "avg") {
  262. if (file_exists("$dir/evaluation/$set.cleaned.$id")) {
  263. print "<a href=\"?$state&show=evaluation/$set.cleaned.$id\">";
  264. $opened_a_tag = 1;
  265. }
  266. else if (file_exists("$dir/evaluation/$set.output.$id")) {
  267. print "<a href=\"?$state&show=evaluation/$set.output.$id\">";
  268. $opened_a_tag = 1;
  269. }
  270. }
  271. if ($set == "avg" && count($each_score)>1) { print $match[2].": "; }
  272. print "<div title=". $match[2] ." class=". $match[2] .">".$match[1]."</div>";
  273. if ($opened_a_tag) { print "</a>"; }
  274. }
  275. else {
  276. print "-";
  277. }
  278. }
  279. print "</td>";
  280. if ($has_analysis && array_key_exists($set,$has_analysis)) {
  281. print "<td align=center>";
  282. global $dir;
  283. $analysis = get_analysis_version($dir,$set,$id);
  284. if ($analysis["basic"]) {
  285. print "<a href=\"?analysis=show&setup=$setup&set=$set&id=$id\">&#x24B6;</a> <input type=checkbox name=analysis-$id-$set value=1>";
  286. }
  287. print "</td>";
  288. }
  289. }
  290. }
  291. function tune_status($id) {
  292. global $dir;
  293. $max_iteration = 0;
  294. if (! file_exists($dir."/tuning/tmp.".$id)) { return ""; }
  295. $d = dir($dir."/tuning/tmp.".$id);
  296. while (false !== ($entry = $d->read())) {
  297. if (preg_match('/run(\d+).moses.ini/',$entry,$match)
  298. && $match[1] > $max_iteration) {
  299. $max_iteration = $match[1];
  300. }
  301. }
  302. if ($max_iteration <= 1) { return $max_iteration; }
  303. return dev_score("$dir/tuning/tmp.$id/run$max_iteration.moses.ini");
  304. }
  305. function dev_score($moses_ini) {
  306. if (! file_exists($moses_ini)) { return ""; }
  307. $moses_ini = file($moses_ini);
  308. $last_iter = -1;
  309. $info = "";
  310. while (list($id,$line) = each($moses_ini)) {
  311. if (preg_match('/# BLEU ([\d\. \-\>]+)/',$line,$match)) {
  312. $info = $match[1];
  313. }
  314. if (preg_match('/# We were before running iteration (\d+)/',$line,$match)) {
  315. $last_iter = $match[1];
  316. }
  317. }
  318. if ($last_iter>=0) { $info = "$last_iter: $info"; };
  319. return $info;
  320. }
  321. function output_state_for_form() {
  322. global $setup;
  323. print "<input type=hidden name=setup value=\"$setup\">\n";
  324. }
  325. function return_state_for_link() {
  326. global $setup;
  327. return "setup=$setup";
  328. }
  329. function show() {
  330. global $dir;
  331. $extra = "";
  332. if (preg_match("/\.(\d+)/",$_GET["show"],$match)) {
  333. $run = $match[1];
  334. if (file_exists($dir."/steps/new") || file_exists($dir."/steps/$run")) {
  335. $extra = "$run/";
  336. }
  337. }
  338. $fullname = $dir."/steps/".$extra.$_GET["show"];
  339. if (preg_match("/\//",$_GET["show"])) {
  340. $fullname = $dir."/".$_GET["show"];
  341. }
  342. if (preg_match("/graph/",$fullname)) {
  343. header("Content-type: image/png");
  344. }
  345. else {
  346. header("Content-type: text/plain");
  347. }
  348. readfile($fullname);
  349. exit;
  350. }