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

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