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

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