Ignore:
Timestamp:
06/28/10 17:47:01 (14 years ago)
Author:
Daniela Dorner
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/datacenter/db/mcinfo.php

    r9548 r9599  
    11<?php
    22{
    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";
    66
    77        $groups = 0;
     
    4242                foreach ($checkstatusgroup as $key => $element)
    4343                    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 . "', ";
    5059            }
    51             $query0 .= " COUNT(*) as '# Runs' ";
     60            $query0 .= " COUNT(*) as '# Files' ";
    5261            $query0 .= ", SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "' ";
    5362        }
    5463        else
    5564        {
    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' ";
    5967
    6068            if (empty($_GET["fSendTxt"]) && !empty($_GET["fLinks"]))
     
    6573
    6674            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) ";
    7598
    7699        foreach ($_GET as $key => $element)
    77100            if (($_GET[$key]=="On" || $groups>0))// && !empty($joins[$key]))
    78101                $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         */
    88102
    89103        foreach ($checkwhere as $key => $element)
     
    108122            $query0 .= " AND ";
    109123
    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);
    112129
    113130        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
    157133
    158134        //remove WHERE or AND in the end of the query
     
    175151        if ($statusgroups>0)
    176152        {
    177 //            $query0 .= " GROUP BY ";
    178153            if (strpos($query0, " GROUP BY ")==FALSE)
    179154                $query0 .= " GROUP BY ";
     
    198173        }
    199174        else
    200             $query0 .=" ORDER BY MCCorsikaRunData.fCorsikaRunNumber ASC";
     175            $query0 .=" ORDER BY " . $fromtable . ".fRunNumber ASC";
    201176
    202177        if (empty($_GET["fNumStart"]))
     
    265240    }
    266241
    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)
    268243    {
    269244        $db_id = mysql_connect($host, $user, $pw);
     
    276251        mysql_query("SET BIG_TABLES=1"); // necessary for mySQL <= 4
    277252
    278         $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs, $timelimits);
     253        $query0 = CreateQuery($_GET, $alias, $checkwhere, $checkgroup, $checkstatusgroup, $timelimits);
    279254
    280255        $result0 = mysql_query($query0, $db_id);
     
    310285        header("Content-Disposition: attachment; filename=query-result.txt");
    311286
    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);
    313288    }
    314289    else
    315290    {
    316291        if (empty($_GET["fPrintTable"]))
    317             echo (file_get_contents("index-header.html"));
     292            echo (file_get_contents("index-header-fact.html"));
    318293
    319294        $environment = sizeof($_GET);
     
    328303        {
    329304            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);
    331306            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);
    333308        }
    334309
Note: See TracChangeset for help on using the changeset viewer.