source: trunk/MagicSoft/Mars/datacenter/db/builddatasets.php@ 9498

Last change on this file since 9498 was 9498, checked in by Daniela Dorner, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 45.3 KB
Line 
1<?php
2
3 function PrintDataSetFile()
4 {
5 printf("AnalysisNumber: 1\n\n");
6 printf("SeqencesOn: %s \n", $_SESSION["sequon"]);
7 if ($_SESSION["sequoff"]!=" ")
8 printf("SeqencesOff: %s \n\n", $_SESSION["sequoff"]);
9 else
10 printf("\n");
11
12 printf("SourceName: %s \n", $_SESSION["realsourcename"]);
13 printf("Catalog: /magic/datacenter/setup/magic_favorites_dc.edb \n");
14 if ($_SESSION["sequoff"]==" ")
15 printf("WobbleMode: On \n\n");
16 printf("RunTime: %s \n", $_SESSION["runtime"]);
17 printf("Name: %s \n", $_SESSION["name"]);
18 printf("Comment: %s \n", $_SESSION["comment"]);
19 }
20
21 function CreateQuery($alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs)
22 {
23 $fromtable="Sequences";
24
25 $groups = 0;
26 foreach ($checkgroup as $element)
27 if ($element==-1)
28 $groups++;
29
30 $statusgroups = 0;
31 foreach ($checkstatusgroup as $element)
32 if ($element==-1)
33 $statusgroups++;
34
35 $query0 = "SELECT SQL_CALC_FOUND_ROWS ";
36
37 if ($groups>0)
38 {
39 foreach ($checkgroup as $key => $element)
40 if ($element==-1)
41 $query0 .= $key . " as '" . $alias[$key] . "' " . ", ";
42 //--------------------------------------------------
43 $query0 .= "SUM(fRunTime)/3600 as '" . $alias["SUM(fRunTime)/3600"] . "', ";
44 //--------------------------------------------------
45 $query0 .= " SUM(fNumEvents) as '" . $alias["SUM(fNumEvents)"] . "', ";
46 $query0 .= " Min(fZenithDistanceMin) as '" . $alias["Min(fZenithDistanceMin)"] . "', ";
47 $query0 .= " Max(fZenithDistanceMax) as '" . $alias["Max(fZenithDistanceMax)"] . "', ";
48 $query0 .= " COUNT(*) as '# Sequ' ";
49 }
50 else
51 {
52 if ($statusgroups>0)
53 {
54 foreach ($checkstatusgroup as $key => $element)
55 if ($element==-1)
56 $query0 .= " (if(IsNull(" . $key . "), if(isnull(fStartTime), 'not done', if(isnull(fFailedTime),if(isnull(" . $needs[$key] . "),'not done',if(date_sub(Now(),interval 12 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] . "', ";
57
58 $query0 .= " COUNT(*) as '# Sequ'";
59
60 }
61 else
62 {
63 $query0 .= " " . $fromtable . ".fSequenceFirst as '" . $alias["fSequenceFirst"] . "' ";
64 if (!empty($_SESSION["fLinks"]))
65 {
66 $query0 .= ", CONCAT('<A&ws;HREF=\"runinfo-aio.php?', 'fRunStart=On', '&amp;fZenithDistance=On', '&amp;fRunMin=', Sequences.fSequenceFirst, '&amp;fMeanTriggerRate=On', '&amp;fTest=On', '&amp;fRunTypeName=On', '&amp;fRunMax=', fSequenceLast, '&amp;fNumEvents=On', '&amp;fSourceName=On&amp;', 'fExcludedFDAKEY=1', '&amp;fSequenceFirst=On', '&amp;fRawFileAvail=On', '&amp;fCCFileAvail=On', '&amp;fCaCoFileAvail=On', '&amp;fNumResults=500\">r</A>' ";
67 //$query0 .= " as " . $alias["fSequenceFirst"];
68 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'callisto', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">cl</A>'";
69 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/callisto/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">c</A>'";
70 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), 'star', LPAD(CONCAT(Sequences.fSequenceFirst , '.html'), 13,'0') , '\">sl</A>'";
71 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/star/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/', LPAD(CONCAT(Sequences.fSequenceFirst, '/'), 9,'0'), '\">s</A>'";
72 $query0 .= ", '&nbsp;<A&ws;HREF=\"http://www.astro.uni-wuerzburg.de/datacenter/sequences/' , LEFT(LPAD(CONCAT(Sequences.fSequenceFirst, '.'), 9,'0'),4), '/sequence', LPAD(CONCAT(Sequences.fSequenceFirst , '.txt'), 12,'0') , '\">', 'f </A>' ";
73 $query0 .= ", '&nbsp;<A&ws;HREF=\"sequence.php?fSequenceNo=', Sequences.fSequenceFirst , '&amp;fAll=On\">i</A>') ";
74 $query0 .= " as 'Links'";
75 }
76
77 foreach ($_SESSION as $key => $element)
78 if ($_SESSION[$key]=="On")
79 if ($key!="fLinks" && $key!="fOff" && $key!="fOnlyOff")
80 if (!(ereg("^[0-9]*ON$", $key) || ereg("^[0-9]*Off$", $key)))
81 if (empty($checkwhere[$key]) || $checkwhere[$key]==0)
82 $query0 .= ", " . $key . " as '" . $alias[$key] . "' ";
83 }
84 }
85
86 $query0 .= " FROM " . $fromtable;
87
88 $query0 .= " LEFT JOIN SequenceProcessStatus USING(fSequenceFirst,fTelescopeNumber) ";
89 $query0 .= " LEFT JOIN Calibration USING(fSequenceFirst,fTelescopeNumber) ";
90 $query0 .= " LEFT JOIN Star USING(fSequenceFirst,fTelescopeNumber) ";
91
92 foreach ($_SESSION as $key => $element)
93 if (($_SESSION[$key]=="On" || $groups>0))// && !empty(GetJoin($fromtable,$key)))
94 $query0 .= GetJoin($fromtable,$key);
95
96 if ($_SESSION["DisplaySelected"]!="yes" || ($_SESSION["sequon"]==" " && $_SESSION["sequoff"]==" "))
97 {
98 if ($_SESSION["fTest"]!="On")
99 {
100 if ($_SESSION["fSourceName"]!="On")
101 $query0 .= " LEFT JOIN Source USING(fSourceKEY) ";
102 $query0 .= " WHERE fTest='no'";
103 }
104
105 if ($_SESSION["fOff"]=="Off")
106 {
107 if (strpos($query0, " WHERE ")==FALSE)
108 $query0 .= " WHERE ";
109 else
110 $query0 .= " AND ";
111
112 $query0 .= " NOT (fSourceName like '%Off%')";
113 }
114
115 if ($_SESSION["fOnlyOff"]=="On")
116 {
117 if (strpos($query0, " WHERE ")==FALSE)
118 $query0 .= " WHERE ";
119 else
120 $query0 .= " AND ";
121
122 $query0 .= " fSourceName like '%Off%'";
123 }
124
125 foreach ($checkwhere as $key => $element)
126 {
127 if (empty($element) || $element<=0)
128 continue;
129
130 if (strpos($query0, " WHERE ")==FALSE)
131 $query0 .= " WHERE ";
132 else
133 if ($element!=-1)
134 if (strrpos($query0, " AND ")!=strlen($query0)-5)
135 $query0 .= " AND ";
136
137 if ($element!=-1)
138 $query0 .= GetCheck($fromtable, $key) . "=" . $element;
139 }
140
141 if (strpos($query0, " WHERE ")==FALSE)
142 $query0 .= " WHERE ";
143 else
144 $query0 .= " AND ";
145
146 $query0 .= StatusQuery("fSequenceFileWritten", $needs, $timelimits);
147 $query0 .= StatusQuery("fAllFilesAvail", $needs, $timelimits);
148 $query0 .= StatusQuery("fCallisto", $needs, $timelimits);
149 $query0 .= StatusQuery("fFillCallisto", $needs, $timelimits);
150 $query0 .= StatusQuery("fStar", $needs, $timelimits);
151 $query0 .= StatusQuery("fFillStar", $needs, $timelimits);
152
153 if (!empty($_SESSION["fRunMin"]) && !empty($_SESSION["fRunMax"]))
154 $query0 .= "Sequences.fSequenceFirst BETWEEN " . $_SESSION["fRunMin"] . " AND " . $_SESSION["fRunMax"] . " ";
155 else
156 $query0 = substr($query0, 0, -4);
157
158 if ((!empty($_SESSION["fZDMin"]) || $_SESSION["fZDMin"]==0) && !empty($_SESSION["fZDMax"]))
159 $query0 .= "AND (fZenithDistanceMin >= " . $_SESSION["fZDMin"] . " AND fZenithDistanceMax <= " . $_SESSION["fZDMax"] . ") ";
160
161 if (!empty($_SESSION["fSourceN"]))
162 $query0 .= " AND fSourceName REGEXP \"^" . $_SESSION["fSourceN"] . "\" ";
163
164 if (!empty($_SESSION["fStartDate"]))
165 {
166 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
167 $query0 .= " AND ";
168
169 $startdate=substr($_SESSION["fStartDate"], 0, 10);
170 if ($startdate=="0000-00-00")
171 $query0 .=" fRunStart >= '" . $startdate . " 00:00:00' ";
172 else
173 $query0 .= " fRunStart >= ADDDATE('" . $startdate . " 13:00:00', INTERVAL -1 DAY) ";
174 }
175
176 if (!empty($_SESSION["fStopDate"]))
177 {
178 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
179 $query0 .= " AND ";
180
181 $stopdate=substr($_SESSION["fStopDate"], 0, 10);
182 $query0 .= " fRunStart < '" . $stopdate . " 13:00:00' ";
183 }
184
185 if (!empty($_SESSION["fStarStart"]))
186 {
187 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
188 $query0 .= " AND ";
189
190 $starstart=substr($_SESSION["fStarStart"], 0, 10);
191 $query0 .=" fStar >= '" . $starstart . " 00:00:00' ";
192 }
193
194 if (!empty($_SESSION["fStarStop"]))
195 {
196 if (strpos(strrev($query0), " DNA ")!=0 || !strpos(strrev($query0), " DNA "))
197 $query0 .= " AND ";
198
199 $starstop=substr($_SESSION["fStarStop"], 0, 10);
200 $query0 .= " fStar < '" . $starstop . " 23:59:59' ";
201 }
202
203 if ($groups>0)
204 {
205 $query0 .= " GROUP BY ";
206 $num = $groups;
207 foreach ($checkgroup as $key => $element)
208 if ($element==-1)
209 {
210 $query0 .= GetCheck($fromtable,$key);
211 if ($num-->1)
212 $query0 .= ", ";
213 }
214 }
215
216 if ($statusgroups>0)
217 {
218 $query0 .= " GROUP BY ";
219 $num = $statusgroups;
220 foreach ($checkstatusgroup as $key => $element)
221 if ($element==-1)
222 {
223 $query0 .= $alias[$key];
224 if ($num-->1)
225 $query0 .= ", ";
226 }
227 }
228
229 }
230 else
231 {
232 $displsequ=str_replace(" ", " ", $_SESSION["sequon"].$_SESSION["sequoff"]);
233 $displsequ=ereg_replace("^ ", "(", $displsequ);
234 $displsequ=ereg_replace(" $", ")", $displsequ);
235 $displsequ=str_replace(" ", ",", $displsequ);
236
237 $query0 .= "WHERE fSequenceFirst IN " . $displsequ;
238 }
239
240 if (!empty($_SESSION["fSortBy"]))
241 {
242 $val=substr($_SESSION["fSortBy"], 0, -1);
243 $query0 .= " ORDER BY " . GetTable($fromtable,$val) . " ";
244 if (substr($_SESSION["fSortBy"], -1)=="-")
245 $query0 .= "DESC";
246 }
247
248 if (empty($_SESSION["fSortBy"]) && $groups==0 && $statusgroups==0)
249 $query0 .= " ORDER BY Sequences.fSequenceFirst DESC ";
250
251 if (empty($_SESSION["fNumStart"]))
252 $start=0;
253 else
254 $start=$_SESSION["fNumStart"];
255
256 if (empty($_SESSION["fSendTxt"]))
257 $query0 .= " LIMIT " . $start . ", " . $_SESSION["fNumResults"];
258
259 return $query0;
260 }
261
262 function PrintForm($host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias)
263 {
264 printf("<center>\n");
265 printf("<form action='builddatasets.php' METHOD='GET'>\n");
266 printf("<input id='sh' type='hidden' name='fShowHide' value='");
267 if (!empty($_SESSION["fShowHide"]))
268 printf("%s", $_SESSION["fShowHide"]);
269 else
270 printf("1000000010");//display Ranges
271 printf("'>\n");
272 printf("<img id='allbutton' src='minus.png' alt='-' onclick='showhide(\"all\")'> <b>Menu</b>&nbsp;&nbsp;&nbsp;&nbsp;\n");
273 printf("&nbsp;&nbsp;<img id='infobutton' src='plus.png' alt='+' onClick='showhide(\"info\");showhide(\"info2\")'> SequInfo \n");
274 printf("&nbsp;&nbsp;<img id='statbutton' src='plus.png' alt='+' onClick='showhide(\"stat\");showhide(\"fail\")'> StatusInfo \n");
275 printf("&nbsp;&nbsp;<img id='calbutton' src='plus.png' alt='+' onClick='showhide(\"cal\")'> CalInfo \n");
276 printf("&nbsp;&nbsp;<img id='starbutton' src='plus.png' alt='+' onClick='showhide(\"star\")'> StarInfo \n");
277 printf("&nbsp;&nbsp;<img id='limitsbutton' src='plus.png' alt='+' onClick='showhide(\"limits\")'> Limits \n");
278 printf("&nbsp;&nbsp;<img id='rangesbutton' src='plus.png' alt='+' onClick='showhide(\"ranges\")'> Ranges \n");
279
280 printf(" <div id='all' style='display:block'>");
281
282 PrintSequInfo2Menu($host,$user,$pw,$db);
283 PrintSequInfoMenu();
284 PrintSequStatMenu();
285 PrintFailMenu();
286 PrintCalMenu();
287 PrintStarMenu();
288 PrintLimitsMenu($limitsmean, $limitsmin, $limitsmax, $alias, "");
289
290 printf(" <div id='ranges' style='display:none'>");
291 PrintZdRangeMenu($host,$user,$pw,$db);
292 PrintSequRangeMenu($host,$user,$pw,$db);
293 printf("<p>");
294 PrintSourceMenu($host,$user,$pw,$db);
295 PrintNightRangeMenu($host,$user,$pw,$db, "Sequences");
296 PrintStarRangeMenu($host,$user,$pw,$db);
297 printf("<p>");
298 printf("</div>");
299
300 printf("</div>");
301 printf(" <P>\n");
302
303 PrintNumResPullDown();
304
305 ini_set("mysql.trace_mode", "Off");
306 ini_set("display_errors", "Off");
307
308 PrintButtons("builddatasets.php");
309
310 printf("</form>\n");
311 printf("</center>\n");
312 printf("</td>\n");
313 printf("</tr>\n");
314 printf("<tr class='Block'>\n");
315 printf("<td>\n");
316 }
317
318 function InsertDataSet($values, $dataset)
319 {
320 $insquery[0]="INSERT DataSets SET fDataSetNumber=" . $dataset . ", fUserKEY=" . $_SESSION["user"];
321 $insquery[0].=", fComment='" . $_SESSION["comment"] . "', fObservationModeKEY=" . $_SESSION["obsmode"];
322 $insquery[0].=", fDataSetName='" . $_SESSION["name"] . "', fSourceKEY= " . $_SESSION["realsourcekey"];
323 $insquery[0].=", fRunStart='" . $values["Min(fRunStart)"]["on"];
324 $insquery[0].="', fRunStop='" . $values["Max(fRunStop)"]["on"];
325 $insquery[0].="', fZenithDistanceMin=" . $values["Min(fZenithDistanceMin)"]["on"];
326 $insquery[0].=", fZenithDistanceMax=" . $values["Max(fZenithDistanceMax)"]["on"];
327 $insquery[0].=", fRunTime=" . $_SESSION["runtime"];
328 $insquery[1]="INSERT DataSetProcessStatus SET fDataSetNumber=" . $dataset . ", fDataSetInserted=Now()";
329 $i=2;
330 foreach(explode(" ", trim($_SESSION["sequon"])) as $key => $sequ)
331 {
332 $insquery[$i]="INSERT DataSetSequenceMapping SET fDataSetNumber=" . $dataset;
333 $insquery[$i].=", fSequenceFirst=" . $sequ . ", fOnOff=1";
334 $i=$i+1;
335 }
336 if (!empty($off))
337 {
338 foreach(explode(" ", trim($_SESSION["sequoff"])) as $key => $sequ)
339 {
340 $insquery[$i]="INSERT DataSetSequenceMapping SET fDataSetNumber=" . $dataset;
341 $insquery[$i].=", fSequenceFirst=" . $sequ . ", fOnOff=2";
342 $i=$i+1;
343 }
344 }
345 // insert
346 if (!empty($_SESSION["insert"]) && $numerr==0)
347 {
348 printf("<br><br>\n");
349 foreach($insquery as $num => $q)
350 {
351 printf("Inserted Query #%s: %s<br>\n", $num, $q);
352 $insresult=mysql_query($q);
353 if (mysql_errno()>0)
354 printf("&nbsp; Errorno: %s <br>\n", mysql_errno());
355 if (mysql_error()!="")
356 printf("&nbsp; Errormsg: %s <br>\n", mysql_error());
357 if (mysql_info()!="")
358 printf("&nbsp; Info: %s <br>\n", mysql_info());
359 printf("&nbsp; Affected Rows: %s <br><br>\n", mysql_affected_rows());
360 mysql_free_result($insresult);
361 if (mysql_errno()>0)
362 {
363 printf("ERROR => stop inserting. <br><br>\n");
364 break;
365 }
366 }
367 // reset after insert
368 unset($_SESSION["insert"]);
369 unset($_SESSION["name"]);
370 unset($_SESSION["comment"]);
371 }
372 else
373 printf("<input type='button' value='Insert Data Set' onClick='self.location.href=\"%s&insert=yes\"'>&nbsp;&nbsp;&nbsp;\n", GetClearedURL());
374 }
375
376 function PrintPage($html, $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs)
377 {
378 $db_id = mysql_pconnect($host, $user, $pw);
379 if ($db_id==FALSE)
380 {
381 printf("mysql_connect returned the following error: %s\n", mysql_error());
382 die("");
383 }
384 mysql_select_db($db);
385
386 $query0 = CreateQuery($alias, $checkwhere, $checkgroup, $checkstatusgroup, $needs);
387
388 $result0 = mysql_query($query0, $db_id);
389 $result1 = mysql_query("SELECT FOUND_ROWS()", $db_id);
390
391 if ($result0)
392 {
393 if ($html=="1" || $html=="2")
394 {
395 PrintMagicTable($result0, $alias, $rightalign, $limitsmean, $limitsmin, $limitsmax, $result1, "yes");
396
397 if ($_SESSION["sequon"]!=" " || $_SESSION["sequoff"]!=" ")
398 {
399 printf("<div align='left'>\n");
400 printf("Remark: To store your selection you have to press 'Update Data Set'<br> \n");
401 if ($_SESSION["DisplaySelected"]!="yes" && ($_SESSION["sequon"]!=" " || $_SESSION["sequoff"]!=" "))
402 {
403 printf("Remark: To be able to remove sequence(s) from your selection you have to \n");
404 printf("'Display Selected Sequences'");
405// printf("<input type='button' value='Display Selected Sequences' onClick='self.location.href=\"%s&DisplaySelected=yes\"'>\n", GetClearedURL("yes"));
406 printf(" only.<br>\n");
407 }
408 printf("<br>\n");
409
410 printf("<u>Your Data Set:</u> <br>\n");
411
412 $on=str_replace(" ", ",", trim($_SESSION["sequon"]));
413 $off=str_replace(" ", ",", trim($_SESSION["sequoff"]));
414
415 $values=array("Sum(fRunTime)/60" => $runtime,
416 "Min(fRunTime)/60" => $runtimemin,
417 "Max(fUnsuitableInner)" => $unsuitablemax,
418 "Max(fUnreliableInner)" => $unreliablemax,
419 "Max(fIsolatedInner)" => $isolatedmax,
420 "Max(fIsolatedMaxCluster)" => $imcmax,
421 "Max(fArrTimeMeanInner)" => $arrtimemax,
422 "Min(fArrTimeMeanInner)" => $arrtimemin,
423 "Max(fArrTimeRmsInner)" => $arrtimermsmax,
424 "Avg(fMeanPedRmsInner)" => $pedrmsmean,
425 "Std(fMeanPedRmsInner)" => $pedrmsrms,
426 "Min(fMeanPedRmsInner)" => $pedrmsmin,
427 "Max(fMeanPedRmsInner)" => $pedrmsmax,
428 "Min(fPulsePosMean)" => $pulseposmin,
429 "Max(fPulsePosMean)" => $pulseposmax,
430 "Max(fPulsePosRms)" => $pulseposrmsmax,
431 "Max(fMaxHumidity)" => $hummax,
432 "Max(fInhomogeneity)" => $inhommax,
433 "Avg(fInhomogeneity)" => $inhommean,
434 "Std(fInhomogeneity)" => $inhomrms,
435 "Min(fMeanNumberIslands)" => $numislmin,
436 "Max(fMeanNumberIslands)" => $numislmax,
437 "Avg(fDataRate)" => $clratemean,
438 "Min(fDataRate)" => $clratemin,
439 "Max(fDataRate)" => $clratemax,
440 "Min(fMuonRate)" => $muonratemin,
441 "Max(fMuonRate)" => $muonratemax,
442 "Min(fMuonNumber)" => $muonnumbermin,
443 "Avg(fPSF)" => $psfmean,
444 "Std(fPSF)" => $psfrms,
445 "Min(fPSF)" => $psfmin,
446 "Max(fPSF)" => $psfmax,
447 "Min(fEffOnTime/fRunTime)" => $relontimemin,
448 "Max(fEffOnTime/fRunTime)" => $relontimemax,
449 "Min(fBrightnessMed)" => $brightmin,
450 "Max(fBrightnessMed)" => $brightmax,
451 "Min(fNumStarsMed)" => $idstarsmin,
452 "Max(fNumStarsMed)" => $idstarsmax,
453 "Min(fNumStarsCorMed)" => $corstarsmin,
454 "Max(fNumStarsCorMed)" => $corstarsmax,
455 "Min(fZenithDistanceMin)" => $zdmin,
456 "Max(fZenithDistanceMax)" => $zdmax,
457 "Min(fRunStart)" => $starttime,
458 "Max(fRunStop)" => $stoptime,
459 );
460 //get runtimes of dataset
461 function GetSequenceValues($db_id, $sequences, $txt, &$values)
462 {
463 $query="SELECT COUNT(*) ";
464 foreach($values as $name => $varname)
465 $query.=", " . $name;
466 $query.=" FROM Sequences ";
467 $query.=" LEFT JOIN Calibration USING(fSequenceFirst,fTelescopeNumber) ";
468 $query.=" LEFT JOIN Star USING(fSequenceFirst,fTelescopeNumber) ";
469 $query.=" WHERE Sequences.fSequenceFirst IN (" . $sequences . ")";
470 $result = mysql_query($query, $db_id);
471 $row = mysql_fetch_assoc($result);
472 foreach($values as $name => $varname)
473 $values[$name][$txt]=$row[$name];
474 mysql_free_result($result);
475 }
476
477 //get next dataset#
478 $query="SELECT fDataSetNumber+1 FROM DataSets ORDER BY fDataSetNumber DESC LIMIT 0,1";
479 $result = mysql_query($query, $db_id);
480 $row = mysql_fetch_assoc($result);
481 $dataset=$row["fDataSetNumber+1"];
482 if (empty($dataset))
483 $dataset=1;
484 mysql_free_result($result);
485
486 //get sourcenames
487 function GetSources($db_id, $sequences)
488 {
489 $query="SELECT fSourceName FROM Source LEFT JOIN Sequences USING(fSourceKEY) ";
490 $query.="WHERE fSequenceFirst IN (" . $sequences . ") GROUP BY fSourceName";
491 $result = mysql_query($query, $db_id);
492 while ($row = mysql_fetch_assoc($result))
493 $sources.=" " . $row["fSourceName"];
494 mysql_free_result($result);
495 return $sources;
496 }
497 $sourceson=GetSources($db_id, $on);
498 $sourcesoff=GetSources($db_id, $off);
499
500 //get sourcename for dataset
501 $son=str_replace(" ", "','", trim($sourceson));
502 $query="SELECT fRealSourceKEY, Count(*), fSourceName FROM Source where fSourceName IN ('" . $son . "') GROUP BY fRealSourceKEY";
503 $result = mysql_query($query, $db_id);
504 $row = mysql_fetch_assoc($result);
505 $numsources=$row["Count(*)"];
506 $numrealkeys=mysql_num_rows($result);
507 $_SESSION["realsourcekey"]=$row["fRealSourceKEY"];
508 $_SESSION["realsourcename"]=$row["fSourceName"];
509 mysql_free_result($result);
510 //printf("found %s sources with real sourcekey %s", $numsources, $realsourcekey);
511 //printf("found %s keys", $numrealkeys);
512
513 //check observationmode for on-sequences
514 $query="SELECT fObservationModeKEY FROM Sequences where fSequenceFirst IN (" . $on . ") GROUP BY fObservationModeKEY";
515 $result = mysql_query($query, $db_id);
516 $row = mysql_fetch_assoc($result);
517 $obskey=$row["fObservationModeKEY"];
518 $numobskeys=mysql_num_rows($result);
519 mysql_free_result($result);
520
521 //check dt for on-sequences
522 $query="SELECT fDiscriminatorThresholdTableKEY FROM Sequences where fSequenceFirst IN (" . $on . ") GROUP BY fDiscriminatorThresholdTableKEY";
523 $result = mysql_query($query, $db_id);
524 $numdtkeys=mysql_num_rows($result);
525 mysql_free_result($result);
526
527
528 //set limit
529 $runtimelimit=5;
530 $unsuitablemaxlimit=15;
531 $isolatedlimit=0;
532 $imclimit=0;
533 $pedrmsrms=0.09;
534 $scalelimit=1.3;
535 $inhomlimit=13;
536 $numstarslimit=20;
537 $numstarscorlimit=10;
538
539
540 //check values for infos, warnings and errors
541 $numerr=0;
542 if (!empty($on))
543 {
544 $color=array("INFO" => "#000000",
545 "WARN" => "#FF9900",
546 "ERROR" => "#FF0000");
547 printf("<div align='left'><font><ul>\n");
548 $vals=array("on", "off");
549 foreach($vals as $num => $val)
550 {
551 if (empty(${$val}))
552 continue;
553 //get information from the database
554 GetSequenceValues($db_id, ${$val}, $val, $values);
555
556 if ($values["Min(fNumStarsCorMed)"][$val]<$numstarscorlimit)
557 printf("<li style='color:%s'>%s: One of your %s-sequences has less than %s correlated stars (%s). </li>\n",
558 $color["WARN"], "WARN", $val, $numstarscorlimit, $values["Min(fNumStarsCorMed)"][$val]);
559 if ($values["Min(fNumStarsMed)"][$val]<$numstarslimit)
560 printf("<li style='color:%s'>%s: One of your %s-sequences has less than %s identified stars (%s). </li>\n",
561 $color["WARN"], "WARN", $val, $numstarslimit, $values["Min(fNumStarsMed)"][$val]);
562 if ($values["Min(fRunTime)/60"][$val]<$runtimelimit)
563 printf("<li style='color:%s'>%s: One of your %s-sequences is shorter than %s min (%s min). </li>\n",
564 $color["INFO"], "INFO", $val, $runtimelimit, $values["Min(fRunTime)/60"][$val]);
565 if ($values["Max(fInhomogeneity)"][$val]>$inhomlimit)
566 printf("<li style='color:%s'>%s: One of your %s-sequences has an inhomogeneity larger than %s (%s). </li>\n",
567 $color["WARN"], "WARN", $val, $inhomlimit, $values["Max(fInhomogeneity)"][$val]);
568 if ($values["Max(fUnsuitableInner)"][$val]>$unsuitablemaxlimit)
569 printf("<li style='color:%s'>%s: One of your %s-sequences has more than %s unsuitable inner pixel (%s). </li>\n",
570 $color["WARN"], "WARN", $val, $unsuitablemaxlimit, $values["Max(fUnsuitableInner)"][$val]);
571 if ($values["Max(fIsolatedInner)"][$val]>$isolatedlimit)
572 printf("<li style='color:%s'>%s: One of your %s-sequences has more than %s isolated inner pixel (%s). </li>\n",
573 $color["WARN"], "WARN", $val, $isolatedlimit, $values["Max(fIsolatedInner)"][$val]);
574 if ($values["Max(fIsolatedMaxCluster)"][$val]>$imclimit)
575 printf("<li style='color:%s'>%s: One of your %s-sequences has more than %s isolated max cluster (%s). </li>\n",
576 $color["WARN"], "WARN", $val, $imclimit, $values["Max(fIsolatedMaxCluster)"][$val]);
577 }
578 //check selected dataset for errors
579 if (!empty($on) && $values["Max(fMeanPedRmsInner)"]["on"]>$values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms)
580 printf("<li style='color:%s'>%s: One of your on-sequences has a PedRms larger than %s (%s).</li>\n",
581 $color["WARN"], "WARN", $values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms, $values["Max(fMeanPedRmsInner)"]["on"]);
582 if (!empty($off) && $values["Max(fMeanPedRmsInner)"]["off"]>$values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms)
583 printf("<li style='color:%s'>%s: One of your off-sequences has a PedRms larger than %s (%s). </li>\n",
584 $color["WARN"], "WARN", $values["Avg(fMeanPedRmsInner)"]["on"]+$pedrmsrms, $values["Max(fMeanPedRmsInner)"]["off"]);
585 if (!empty($off) && $values["Min(fMeanPedRmsInner)"]["off"]<$values["Avg(fMeanPedRmsInner)"]["on"]-$pedrmsrms)
586 printf("<li style='color:%s'>%s: One of your off-sequences has a PedRms smaller than %s (%s). </li>\n",
587 $color["WARN"], "WARN", $values["Avg(fMeanPedRmsInner)"]["on"]-$pedrmsrms, $values["Min(fMeanPedRmsInner)"]["off"]);
588 $scale=$values["Sum(fRunTime)/60"]["on"]/$values["Sum(fRunTime)/60"]["off"];
589 if ($scale > $scalelimit)
590 printf("<li style='color:%s'>%s: Your scale factor is larger than %s (%0.2f). Try to find more offdata! </li>\n",
591 $color["WARN"], "WARN", $scalelimit, $scale);
592 $doubleseq=0;
593 foreach(explode(" ", $_SESSION["sequon"]) as $n => $s)
594 {
595 if (ereg($s, $_SESSION["sequoff"]))
596 $doubleseq++;
597 }
598 if ($obskey!=$_SESSION["obsmode"])
599 {
600 printf("<li style='color:%s'>%s: You have not selected any Off sequences. </li>\n",
601 $color["ERROR"], "ERROR", $doubleseq);
602 $numerr=$numerr+1;
603 }
604 if ($doubleseq>0)
605 {
606 printf("<li style='color:%s'>%s: You have selected sequences (%s) as On AND Off. </li>\n",
607 $color["ERROR"], "ERROR", $doubleseq);
608 $numerr=$numerr+1;
609 }
610 if ($numrealkeys>1)
611 {
612 printf("<li style='color:%s'>%s: You have selected more than one (%s) on source. </li>\n",
613 $color["ERROR"], "ERROR", $numrealkeys);
614 $numerr=$numerr+1;
615 }
616 if ($numobskeys>1)
617 {
618 printf("<li style='color:%s'>%s: You have selected more than one (%s) different observation modes in your on sequences. </li>\n",
619 $color["ERROR"], "WARN", $numobskeys);
620 //$numerr=$numerr+1;
621 }
622 if ($numdtkeys>1)
623 {
624 printf("<li style='color:%s'>%s: Your selected on sequences have more than one (%s) different discriminator threshold tables. </li>\n",
625 $color["ERROR"], "WARN", $numdtkeys);
626 }
627 if (empty($_SESSION["realsourcekey"]))
628 {
629 printf("<li style='color:%s'>%s: The source you selected does not have a real sourcekey, yet. Please insert fRealSourceKEY in the DB for %s (contact: datacenter@astro.uni-wuerzburg.de). </li>\n",
630 $color["ERROR"], "ERROR", $sourceson);
631 $numerr=$numerr+1;
632 }
633 if (empty($_SESSION["name"]))
634 {
635 printf("<li style='color:%s'>%s: You have to choose a name. </li>\n",
636 $color["ERROR"], "ERROR");
637 $numerr=$numerr+1;
638 }
639 if (empty($_SESSION["comment"]))
640 {
641 printf("<li style='color:%s'>%s: You have to comment your data set. </li>\n",
642 $color["ERROR"], "ERROR");
643 $numerr=$numerr+1;
644 }
645 printf("</ul></font>\n");
646 printf("</div>");
647
648 //set runtime in session (has to be after calling GetSequenceValues())
649 $_SESSION["runtime"] = $values["Sum(fRunTime)/60"]["on"];
650 $_SESSION["zdmin"] = $values["Min(fZenithDistanceMin)"]["on"];
651 $_SESSION["zdmax"] = $values["Max(fZenithDistanceMax)"]["on"];
652 $_SESSION["meanrate"] = $values["Avg(fDataRate)"]["on"];
653 $_SESSION["psfmean"] = $values["Avg(fPSF)"]["on"];
654 $_SESSION["psfmin"] = $values["Min(fPSF)"]["on"];
655 $_SESSION["psfmax"] = $values["Max(fPSF)"]["on"];
656
657 printf("SequencesOn: %s<br>\n", $_SESSION["sequon"]);
658 if ($_SESSION["sequoff"]!=" ")
659 printf("SequencesOff: %s<br>\n", $_SESSION["sequoff"]);
660
661 //set observation mode
662 if ($_SESSION["sequoff"]==" ")
663 $obsmode="Wobble";
664 else
665 $obsmode="On";
666 //get key from db for insert query
667 $query = "SELECT fObservationModeKEY FROM ObservationMode WHERE fObservationModeName='".$obsmode."'";
668 $result = mysql_query($query);
669 $row = mysql_fetch_assoc($result);
670 $_SESSION["obsmode"] = $row["fObservationModeKEY"];
671 mysql_free_result($result);
672 printf("Observation mode: %s <br>\n", $obsmode);
673 printf("RunTime: %s min <br>\n", $_SESSION["runtime"]);
674 printf("Mean Rate after cleaning: %s Hz <br>\n", $_SESSION["meanrate"]);
675 printf("Zd: %s - %s deg <br>\n", $_SESSION["zdmin"], $_SESSION["zdmax"]);
676 printf("PSF: %s (%s - %s) mm <br>\n", $_SESSION["psfmean"], $_SESSION["psfmin"], $_SESSION["psfmax"]);
677
678 //user name
679 printf("User name: %s <br><br>\n", $_SERVER['PHP_AUTH_USER']);
680
681 // data set name and comment: to be inserted by the user
682 printf("Data set name: &nbsp;<input name='name' type='text' size='20' maxlength='20' value='%s'><br>\n", $_SESSION["name"]);
683 printf("Comment: &nbsp;<input name='comment' type='text' size='50' maxlength='255' value='%s'><br><br>\n", $_SESSION["comment"]);
684
685
686 //PrintUpdateDataSetButton() has to be called before InsertDataSet()
687 // to ensure that there are no problem with insert and $_SESSION["insert"]
688
689 //allow 'insert/get dataset' in case no error is found
690 if ($numerr!=0)
691 {
692 printf("Remark: Only data sets without errors can be inserted.<br>");
693 printf("<font color='red'>Your data set has %s error(s).</font><br><br>", $numerr);
694 PrintUpdateDataSetButton();
695 }
696 else
697 {
698 PrintUpdateDataSetButton();
699
700 if ($_SERVER['PHP_AUTH_USER']=="MAGIC")
701 printf("<br><br>\n Remark: As user MAGIC you are not allowed to insert data sets into the database. For an own account, please contact datacenter@astro.uni-wuerzburg.de <br><br>\n");
702 else
703 InsertDataSet($values, $dataset);
704
705 printf("<input type='button' value='Get Data Set File' onClick='self.location.href=\"%s&fSendTxt=2\"'>&nbsp;&nbsp;&nbsp;\n", GetClearedURL());
706 }
707
708
709 //print table with more information on dataset
710 printf("<br><br><br>\n");
711 printf("<table><tr><td colspan='2'><b>More Information on Your Data Set:<b></td></tr>");
712 printf("<tr><td>Next DataSet# in DB: </td><td>%s</td></tr>", $dataset);
713 printf("<tr><td valign='top'>SequencesOn:</td><td> %s</td></tr>", $_SESSION["sequon"]);
714 if ($_SESSION["sequoff"]!=" ")
715 {
716 printf("<tr><td valign='top'>SequencesOff:</td><td> %s</td></tr>", $_SESSION["sequoff"]);
717 printf("<tr><td>Scale factor (On/Off): </td><td>%0.2f</td></tr>", $scale);
718 }
719 printf("<tr><td>SourcenamesOn [%s]: </td><td>%s</td></tr>", str_word_count($sourceson, 0, "1234567890+"), $sourceson);
720 if ($_SESSION["sequoff"]!=" ")
721 printf("<tr><td>SourcenamesOff [%s]: </td><td>%s</td></tr>", str_word_count($sourcesoff, 0, "1234567890+"), $sourcesoff);
722 printf("</table>\n");
723
724 printf("<table border='1'>\n");
725 printf("<tr><td>Value</td><td>On</td>");
726 if (!empty($off))
727 printf("<td>Off</td></tr>\n");
728 foreach($values as $name => $varname)
729 {
730 printf("<tr><td>%s</td>\n", $name);
731 foreach($vals as $num => $val)
732 if (!empty(${$val}))
733 printf("<td>%s</td>\n", $varname[$val]);
734 printf("</tr>\n");
735 }
736 printf("</table>\n");
737 }
738 }
739 else
740 printf("<input type='submit' value='Get Data Set'><br><br>\n");
741
742 printf("</div>\n");
743 printf("</td>\n");
744 printf("</tr>\n");
745
746 printf("</form>\n");
747 }
748 else
749 PrintText($result0);
750
751 mysql_free_result($result0);
752 mysql_free_result($result1);
753 }
754 mysql_close($db_id);
755
756 PrintSubmittedQuery($query0, $html, $db, "");
757 }
758
759 include ("include.php");
760 include ("menu.php");
761 include ("db.php");
762 include ("magicdefs.php");
763
764// $debug="yes";
765 session_start();
766 if ($debug)
767 {
768 echo "GET: ";
769 print_r($_GET);
770 echo " <br>";
771
772 echo "POST: ";
773 print_r($_POST);
774 echo " <br>";
775 }
776
777 // set values given by $_GET
778 foreach ($_GET as $element => $value)
779 $_SESSION[$element]=$value;
780
781 // unset values in case of 'Reset'
782 if (empty($_GET))
783 foreach($_SESSION as $element => $value)
784 unset($_SESSION[$element]);
785
786 // set values given by $_POST
787 if (!empty($_POST))
788 foreach ($_POST as $element => $value)
789 $_SESSION[$element]=$value;
790
791
792
793 if ($debug)
794 print_r($_SESSION);
795
796 // remove sequence from selection
797 if (!empty($_POST) && $_SESSION["DisplaySelected"]=="yes" && $_SESSION["DisplaySelectedOld"]=="yes")
798 foreach ($_SESSION as $key => $element)
799 if (($_SESSION[$key]=="On") //value is set
800 && (ereg("^[0-9]*ON$", $key) || ereg("^[0-9]*Off$", $key)) // it is a sequence number
801 && (!$_POST[$key]==On)) // the sequence is not given in $_POST any more
802 unset($_SESSION[$key]);
803
804 //store old value of $_SESSION["DisplaySelected"]
805 if ($_SESSION["DisplaySelected"]=="yes")
806 {
807 unset($_SESSION["fNumStart"]);
808 $_GET["fNumStart"]=0;
809 $_SESSION["DisplaySelectedOld"]="yes";
810 }
811 else
812 $_SESSION["DisplaySelectedOld"]="no";
813
814 $_SESSION["sequon"]=" ";
815 $_SESSION["sequoff"]=" ";
816 foreach($_SESSION as $key => $val)
817 if ($val=="On")
818 {
819 if (ereg("^[0-9]*ON$", $key))
820 $_SESSION["sequon"].=str_replace("ON", " ", $key);
821 if (ereg("^[0-9]*Off$", $key))
822 $_SESSION["sequoff"].=str_replace("Off", " ", $key);
823 }
824 if ($_SESSION["sequon"]==" " && $_SESSION["sequoff"]==" ")
825 {
826 $_SESSION["DisplaySelected"]="no";
827 $_SESSION["DisplaySelectedOld"]="no";
828 }
829
830 ini_set("display_errors", "On");
831 ini_set("mysql.trace_mode", "On");
832
833 if (!isset($_SERVER['PHP_AUTH_USER']))
834 {
835 header('WWW-Authenticate: Basic realm="Build Datasets"');
836 header('HTTP/1.0 401 Unauthorized');
837 return;
838 }
839 else
840 {
841 $db_id = mysql_connect($host, $user, $pw);
842 if ($db_id==FALSE)
843 {
844 printf("mysql_connect returned the following error:<br>");
845 printf("%s<br>", mysql_error());
846 die("");
847 }
848
849 $userquery = "SELECT fUserName, fPassword, fUserKEY FROM " . $db . ".User ORDER BY fUserKEY";
850 $userresult = mysql_query($userquery);
851 if (!$userresult)
852 echo "query failed";
853 $validuser="no";
854 while ($userrow = mysql_fetch_assoc($userresult))
855 {
856// echo crypt($_SERVER['PHP_AUTH_PW']). "<br>";
857 if (crypt($_SERVER['PHP_AUTH_PW'], $userrow["fPassword"])==$userrow["fPassword"]
858 && $_SERVER['PHP_AUTH_USER']==$userrow["fUserName"])
859 {
860 $validuser="yes";
861 $_SESSION["user"]=$userrow["fUserKEY"];
862 }
863 }
864 mysql_free_result($userresult);
865 if ($validuser=="no")
866 {
867 printf("<br>Password or username incorrect<br>");
868 return;
869 }
870 }
871
872 if (!empty($_SESSION["fSendTxt"]))
873 {
874 header("Content-Type: application/octet");
875 switch($_SESSION["fSendTxt"])
876 {
877 case 1:
878 header("Content-Disposition: attachment; filename=query-result.txt");
879 PrintPage("0", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
880 break;
881 case 2:
882 header("Content-Disposition: attachment; filename=dataset_".str_replace(" ", "_", $_SESSION["name"]).".txt");
883 PrintDataSetFile();
884 echo "hallo\n";
885 }
886 unset($_SESSION["fSendTxt"]);
887 }
888 else
889 {
890 echo (file_get_contents("index-header.html"));
891
892 $environment = sizeof($_GET);
893
894 // Find out whether it is the first call to the php script
895 $first = empty($_GET["fRunMin"]) && empty($_GET["fRunMax"]);
896 InitBuildDataSets($first);
897 if (empty($_SESSION["fPrintTable"]))
898 PrintForm($host, $user, $pw, $db, $limitsmean, $limitsmin, $limitsmax, $alias);
899
900 if ($environment==0)
901 printf("No query submitted yet.<BR>");
902 else
903 {
904 if (empty($_SESSION["fPrintTable"]))
905 PrintPage("1", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
906 else
907 PrintPage("2", $host, $user, $pw, $db, $alias, $rightalign, $checkwhere, $checkgroup, $checkstatusgroup, $limitsmean, $limitsmin, $limitsmax, $needs);
908 }
909
910 echo (file_get_contents("index-footer.html"));
911 }
912
913 ini_set("display_errors", "Off");
914 ini_set("mysql.trace_mode", "Off");
915
916?>
Note: See TracBrowser for help on using the repository browser.