Changeset 9599 for trunk/MagicSoft/Mars/datacenter/db/mcinfo.php
- Timestamp:
- 06/28/10 17:47:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/db/mcinfo.php
r9548 r9599 1 1 <?php 2 2 { 3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $ needs, $timelimits)4 { 5 $fromtable=" MCCorsikaRunData";3 function CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits) 4 { 5 $fromtable="CeresInfo"; 6 6 7 7 $groups = 0; … … 42 42 foreach ($checkstatusgroup as $key => $element) 43 43 if ($element==-1) 44 $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval " . $timelimits[$key] . " hour) < fStartTime,'running','crashed')),if(isnull(" . $needs[$key] . "),'not done','failed'))) ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', "; 45 // $query0 .= " (if(IsNull(" . $key . "), 'not done' ,if(" . $key . "='1970-01-01 00:00:00','dont do','done'))) as '" . $alias[$key] . "', "; 46 47 // $query0 .= " count(*) as '# Runs'"; 48 // $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' "; 49 44 $query0 .= " IF( ISNULL(" . $key . "Status.fStartTime) " 45 ." AND ISNULL(" . $key . "Status.fStopTime) " 46 ." AND ISNULL(" . $key . "Status.fReturnCode), 'not done', " 47 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) " 48 ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) > " . $key . "Status.fStartTime " 49 ." AND ISNULL(" . $key . "Status.fStopTime) " 50 ." AND ISNULL(" . $key . "Status.fReturnCode), 'crashed', " 51 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) " 52 ." AND DATE_SUB(Now(),INTERVAL " . $timelimits[$key] . " HOUR) < " . $key . "Status.fStartTime " 53 ." AND ISNULL(" . $key . "Status.fStopTime) " 54 ." AND ISNULL(" . $key . "Status.fReturnCode), 'running', " 55 ." IF (NOT ISNULL(" . $key . "Status.fStartTime) " 56 ." AND NOT ISNULL(" . $key . "Status.fStopTime) " 57 ." AND ISNULL(" . $key . "Status.fReturnCode), 'done', 'bla' " 58 ." )))) AS '". $key . "', "; 50 59 } 51 $query0 .= " COUNT(*) as '# Runs' ";60 $query0 .= " COUNT(*) as '# Files' "; 52 61 $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' "; 53 62 } 54 63 else 55 64 { 56 $query0 .= " MCCorsikaRunData.fCorsikaRunNumber as 'Run' "; 57 // $query0 .= " Concat(RunData.fTelescopeNumber,':', RunData.fRunNumber,':', RunData.fFileNumber) as 'Run' "; 58 // $query0 .= " Concat('M', RunData.fTelescopeNumber,':', LPAD(RunData.fRunNumber,8, ' '),'/', LPAD(RunData.fFileNumber, 3, ' ')) as 'Tel:Run/File' "; 65 $query0 .= " CONCAT(LPAD(" . $fromtable . ".fRunNumber,8, ' '),'.', "; 66 $query0 .= " RIGHT(LPAD(" . $fromtable . ".fFileNumber, 6, 0), 3)) as 'Run.File' "; 59 67 60 68 if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"])) … … 65 73 66 74 foreach ($_GET as $key => $element) 67 if ($key!="fLinks" && $_GET[$key]=="On" && $key!="fTest") 68 if (empty($checkwhere[$key]) || $checkwhere[$key]==0) 69 $query0 .= ", " . $key . " as '" . $alias[$key] . "' "; 70 } 71 72 $query0 .= " FROM MCCorsikaRunData "; 73 74 $query0 .= " LEFT JOIN MCRunProcessStatus ON MCCorsikaRunData.fCorsikaRunNumber=MCRunProcessStatus.fMCRunNumber "; 75 if ($_GET[$key]=="On" && $key!="fTest" && $key!="fLinks") 76 if (!ereg("^f", $key)) 77 { 78 79 $query0 .= ", IF (ISNULL(" . $key . "Status.fStartTime) AND "; 80 $query0 .= " ISNULL(" . $key . "Status.fStopTime) AND "; 81 $query0 .= " ISNULL(" . $key . "Status.fReturnCode), 'not done', "; 82 $query0 .= " IF (NOT ISNULL(" . $key . "Status.fReturnCode), "; 83 $query0 .= " CONCAT('failed (', " . $key . "Status.fReturnCode, ')'), "; 84 $query0 .= " CONCAT('done (', " . $key . "Status.fStopTime, ')'))) "; 85 86 //$query0 .= ", CONCAT( 'halo', " . $key . "Status.fStartTime)"; 87 $query0 .= " AS '" . $alias[$key] . "' "; 88 //echo "ereg: " . $key . "<br>"; 89 } 90 else 91 if (empty($checkwhere[$key]) || $checkwhere[$key]==0) 92 $query0 .= ", " . $key . " as '" . $alias[$key] . "' "; 93 } 94 95 $query0 .= " FROM " . $fromtable; 96 97 $query0 .= " LEFT JOIN CorsikaInfo USING(fRunNumber,fFileNumber) "; 75 98 76 99 foreach ($_GET as $key => $element) 77 100 if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key])) 78 101 $query0 .= GetJoin($fromtable,$key); 79 80 /*81 if ($_GET["fTest"]!="On")82 {83 if ($_GET["fSourceName"]!="On")84 $query0 .= " LEFT JOIN Source USING(fSourceKEY) ";85 $query0 .= " WHERE fTest='no'";86 }87 */88 102 89 103 foreach ($checkwhere as $key => $element) … … 108 122 $query0 .= " AND "; 109 123 110 $query0 .= StatusQuery("fCorsikaInputCreated", $needs, $timelimits); 111 $query0 .= StatusQuery("fCorsikaFileAvail", $needs, $timelimits); 124 $query0 .= StatusQuery("Corsika", $timelimits); 125 $query0 .= StatusQuery("Ceres", $timelimits); 126 $query0 .= StatusQuery("SequenceFile", $timelimits); 127 $query0 .= StatusQuery("Callisto", $timelimits); 128 $query0 .= StatusQuery("Star", $timelimits); 112 129 113 130 if ((!empty($_GET["fRunMin"]) || $_GET["fRunMin"]=="0") && !empty($_GET["fRunMax"])) 114 $query0 .= "MCCorsikaRunData.fCorsikaRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " "; 115 116 // if ((!empty($_GET["fZDMin"]) || $_GET["fZDMin"]==0) && !empty($_GET["fZDMax"])) 117 // $query0 .= "AND fZenithDistance BETWEEN " . $_GET["fZDMin"] . " AND " . $_GET["fZDMax"] . " "; 118 119 /* 120 if (!empty($_GET["fDate"])) 121 $query0 .= " AND fRunStart REGEXP \"^" . $_GET["fDate"] . "\" "; 122 */ 123 124 /* 125 if (!empty($_GET["fSourceN"])) 126 $query0 .= " AND fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" "; 127 128 if (!empty($_GET["fStartDate"])) 129 { 130 if (strpos(strrev($query0), " DNA ")!=0) 131 $query0 .= " AND "; 132 133 $startdate=substr($_GET["fStartDate"], 0, 10); 134 if ($startdate=="0000-00-00") 135 $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' "; 136 else 137 $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) "; 138 } 139 140 if (!empty($_GET["fStopDate"])) 141 { 142 if (strpos(strrev($query0), " DNA ")!=0) 143 $query0 .= " AND "; 144 145 $stopdate=substr($_GET["fStopDate"], 0, 10); 146 $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' "; 147 } 148 149 if (!empty($_GET["fSequenceNo"]) || $_GET["fSequenceNo"]=="0") 150 { 151 if (strpos(strrev($query0), " DNA ")!=0) 152 $query0 .= " AND "; 153 154 $query0 .= " fSequenceFirst = '" . $_GET["fSequenceNo"] . "' "; 155 } 156 */ 131 $query0 .= " " . $fromtable . ".fRunNumber BETWEEN " . $_GET["fRunMin"] . " AND " . $_GET["fRunMax"] . " "; 132 157 133 158 134 //remove WHERE or AND in the end of the query … … 175 151 if ($statusgroups>0) 176 152 { 177 // $query0 .= " GROUP BY ";178 153 if (strpos($query0, " GROUP BY ")==FALSE) 179 154 $query0 .= " GROUP BY "; … … 198 173 } 199 174 else 200 $query0 .=" ORDER BY MCCorsikaRunData.fCorsikaRunNumber ASC";175 $query0 .=" ORDER BY " . $fromtable . ".fRunNumber ASC"; 201 176 202 177 if (empty($_GET["fNumStart"])) … … 265 240 } 266 241 267 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $ needs, $timelimits)242 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits) 268 243 { 269 244 $db_id = mysql_connect($host, $user, $pw); … … 276 251 mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4 277 252 278 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $ needs, $timelimits);253 $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits); 279 254 280 255 $result0 = mysql_query($query0, $db_id); … … 310 285 header("Content-Disposition: attachment; filename=query-result.txt"); 311 286 312 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $ needs, $timelimits);287 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits); 313 288 } 314 289 else 315 290 { 316 291 if (empty($_GET["fPrintTable"])) 317 echo (file_get_contents("index-header .html"));292 echo (file_get_contents("index-header-fact.html")); 318 293 319 294 $environment = sizeof($_GET); … … 328 303 { 329 304 if (empty($_GET["fPrintTable"])) 330 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $ needs, $timelimits);305 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits); 331 306 else 332 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $ needs, $timelimits);307 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits); 333 308 } 334 309
Note:
See TracChangeset
for help on using the changeset viewer.