source: trunk/MagicSoft/Mars/datacenter/db/plotinclude.php@ 9488

Last change on this file since 9488 was 9466, checked in by aparavac, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.8 KB
Line 
1<?php
2
3//arrays and functions for plot.php and plotdb.php
4include("include.php");
5include("magicdefs.php");
6include("db.php");
7
8$tables=array("fSequenceFirst" => "Sequences",
9 "fRunNumber" => "RunData",
10 "fDataSetNumber" => "DataSets");
11
12$prims=array("SequenceNumber" => "fSequenceFirst",
13 "RunNumber" => "fRunNumber",
14 "DataSetNumber" => "fDataSetNumber");
15
16$joins=array("fSequenceFirst" => " LEFT JOIN Star USING(fSequenceFirst,fTelescopeNumber) "
17 ."LEFT JOIN Calibration USING(fSequenceFirst,fTelescopeNumber) ",
18 "fRunNumber" => " LEFT JOIN DataCheck USING(fRunNumber) ",
19 "fDataSetNumber" =>" LEFT JOIN Ganymed USING(fDataSetNumber) ");
20
21function GetList($host, $user, $pw, $db, $column, $tables)
22{
23 $tab_fSequenceFirst=array("Sequences", "Calibration", "Star");
24 $tab_fRunNumber=array("RunData");
25 $tab_fDataSetNumber=array("DataSets", "Ganymed");
26
27 $table=$tables[$column];
28 foreach(${"tab_".$column} as $tab)
29 {
30 $query="EXPLAIN " . $tab;
31
32 mysql_connect($host, $user, $pw);
33 mysql_select_db($db);
34
35 $result=mysql_query($query);
36
37 while ($row = mysql_fetch_row($result))
38 $list[] = $row[0];
39 }
40 return $list;
41}
42
43function CheckQuery($query)
44{
45 if (strpos($query, " WHERE ")==FALSE)
46 return " WHERE ";
47 else
48 return " AND ";
49}
50
51function GetQuery($tables, $joins, $set)
52{
53 if (empty($_GET["prim"]))
54 $_GET["prim"]="";
55 $primary=$_GET["prim"];
56 if (empty($primary))
57 return "";
58 if (empty($_GET[$primary."Col"]))
59 $_GET[$primary."Col"]="";
60 $column=$_GET[$primary."Col"];
61 $table=$tables[$primary];
62 if (empty($_GET["primstart"]))
63 $_GET["primstart"]="";
64 $primstart=$_GET["primstart"];
65 if (empty($_GET["primstop"]))
66 $_GET["primstop"]="";
67 $primstop=$_GET["primstop"];
68 if (empty($_GET["Start"]))
69 $_GET["Start"]="";
70 $start1=$_GET["Start"];
71 if (empty($_GET["Stop"]))
72 $_GET["Stop"]="";
73 $stop1=$_GET["Stop"];
74
75 if (empty($_GET["fSourceN"]))
76 $_GET["fSourceN"]="";
77 $source=$_GET["fSourceN"];
78
79 $query="SELECT " . $table . "." . $primary . ", ";
80 if ($column==$primary)
81 $query.=$table . "." . $column;
82 else
83 $query.=$column;
84
85 if ($_GET["plot"]=="val")
86 {
87 if (empty($_GET[$primary."Col2"]))
88 $_GET[$primary."Col2"]="";
89 $column2=$_GET[$primary."Col2"];
90 if (empty($_GET["Start2"]))
91 $_GET["Start2"]="";
92 $start2=$_GET["Start2"];
93 if (empty($_GET["Stop2"]))
94 $_GET["Stop2"]="";
95 $stop2=$_GET["Stop2"];
96
97 if ($column2==$primary)
98 $query.=", " . $table . "." . $column2;
99 else
100 $query.=", " . $column2;
101 }
102 $query.=" FROM " . $table;
103 $query.=$joins[$primary];
104
105 if (!empty($source))
106 $query.= " LEFT JOIN Source USING(fSourceKEY) ";
107
108 if (!empty($primstart))
109 $query.= " WHERE " . $table . "." . $primary . " > " . $primstart;
110
111 if (!empty($primstop))
112 $query.= CheckQuery($query) . $table . "." . $primary . " < " . $primstop;
113
114 if (!empty($start1))
115 $query.= CheckQuery($query) . GetTable($table, $column) . " > " . $start1;
116
117 if (!empty($stop1))
118 $query.= CheckQuery($query) . GetTable($table, $column) . " < " . $stop1;
119
120 if ($_GET["plot"]=="val")
121 {
122 if (!empty($start2))
123 $query.= CheckQuery($query) . GetTable($table, $column2) . " > " . $start2;
124
125 if (!empty($stop2))
126 $query.= CheckQuery($query) . GetTable($table, $column2) . " < " . $stop2;
127 }
128
129 if (!empty($set) && !empty($_GET[$set]))
130 $query.= CheckQuery($query) . $table . "." . $primary . " IN (" . str_replace(" ", ",", $_GET[$set]) . ") ";
131
132 if (empty($_GET[$primary."Col3"]))
133 $_GET[$primary."Col3"]="";
134 $column3=$_GET[$primary."Col3"];
135 if (empty($_GET["Start3"]))
136 $_GET["Start3"]="";
137 $start3=$_GET["Start3"];
138 if (empty($_GET["Stop3"]))
139 $_GET["Stop3"]="";
140 $stop3=$_GET["Stop3"];
141
142 if (!empty($start3))
143 $query.= CheckQuery($query) . GetTable($table, $column3) . " > " . $start3;
144
145 if (!empty($stop3))
146 $query.= CheckQuery($query) . GetTable($table, $column3) . " < " . $stop3;
147
148 if (empty($_GET[$primary."Col4"]))
149 $_GET[$primary."Col4"]="";
150 $column4=$_GET[$primary."Col4"];
151 if (empty($_GET["Start4"]))
152 $_GET["Start4"]="";
153 $start4=$_GET["Start4"];
154 if (empty($_GET["Stop4"]))
155 $_GET["Stop4"]="";
156 $stop4=$_GET["Stop4"];
157
158 if (!empty($start4))
159 $query.= CheckQuery($query) . GetTable($table, $column4) . " > " . $start4;
160
161 if (!empty($stop4))
162 $query.= CheckQuery($query) . GetTable($table, $column4) . " < " . $stop4;
163
164 if (!empty($source))
165 $query.= CheckQuery($query) . " fSourceName REGEXP \"^" . $_GET["fSourceN"] . "\" ";
166
167 return $query;
168}
169
170//functions for showplots*.php
171function gettypename($type2)
172{
173 switch ($type2)
174 {
175 case "calib":
176 $type="callisto";
177 break;
178 case "signal":
179 $type="callisto";
180 break;
181 case "star":
182 $type="star";
183 break;
184 }
185 return $type;
186}
187
188function getplotname($seq, $tabnum, $type, $type2)
189{
190 $seqlong=str_pad($seq, 8, "0", STR_PAD_LEFT);
191 $seqshort=substr($seqlong, 0, 4);
192 $plot = "http://datacenter.astro.uni-wuerzburg.de/";
193 $plot .= $type . "/" . str_pad( $seqshort, 4, "0", STR_PAD_LEFT);
194// $plot .= "/" . $seqlong . "/" . $type2 . $seqlong . "-tab" . $tabnum . ".png";
195 $plot .= "/" . $seqlong . "/" . $type2 . $tabnum . ".png";
196 return $plot;
197}
198
199function getinfofromdb($seq)
200{
201 include("db.php");
202
203 $db_id = mysql_pconnect($host, $user, $pw);
204 if ($db_id==FALSE)
205 {
206 printf("mysql_connect returned the following error: %s\n", mysql_error());
207 die("");
208 }
209 mysql_select_db($db);
210
211 $query0 = "SELECT fSequenceFirst ";
212 $query0 .= ", DATE_FORMAT(ADDDATE(fRunStart,Interval 12 hour), '%Y-%m-%d') as 'ObsNight'";
213 $query0 .= ", fSourceName ";
214 $query0 .= ", fZenithDistanceMin ";
215 $query0 .= ", fZenithDistanceMax ";
216 $query0 .= ", fMeanPedRmsInner ";
217 $query0 .= ", fRunTime/60 as 'UpTime' ";
218 $query0 .= ", if(isnull(fStar), 'N/A', if(isnull(fRateSumEvts), 'no', CONCAT('yes (',fRateSumEvts, ')'))) as 'Sum' ";
219 $query0 .= "FROM Sequences ";
220 $query0 .= "LEFT JOIN Source USING(fSourceKEY) ";
221 $query0 .= "LEFT JOIN Calibration USING(fSequenceFirst) ";
222 $query0 .= "LEFT JOIN Star USING(fSequenceFirst) ";
223 $query0 .= "LEFT JOIN SequenceProcessStatus USING(fSequenceFirst) ";
224 $query0 .= "WHERE fSequenceFirst=".$seq;
225
226// echo $query0;
227
228 $result0 = mysql_query($query0, $db_id);
229 while ($row0 = mysql_fetch_assoc($result0))
230 $info="<b>".$row0["fSourceName"]."</b> ".$row0["ObsNight"]
231 ." (".$row0["UpTime"]."min)"
232 ." Zd: ".$row0["fZenithDistanceMin"]."-".$row0["fZenithDistanceMax"]
233 ." PedRmsIn: ".$row0["fMeanPedRmsInner"]
234 ." SumTrigger: ".$row0["Sum"];
235
236 mysql_free_result($result0);
237 mysql_close($db_id);
238
239 return $info;
240}
241
242function PrintType2Pulldown($type2)
243{
244 $types=array("calib", "signal", "star");
245 printf("<select name='type2'>\n");
246 foreach($types as $t => $typename)
247 if ($type2==$typename)
248 printf("<option value='%s' selected>%s </option>\n", $type2, $type2);
249 else
250 printf("<option value='%s'>%s </option>\n", $typename, $typename);
251 print("</select>\n");
252}
253
254function PrintHomeHelp()
255{
256 printf("<td valign='top'>\n");
257 printf("<a href='http://www.astro.uni-wuerzburg.de/wiki/Database_Websites'>home</a>\n");
258 printf("<a href='http://www.astro.uni-wuerzburg.de/wiki/Database_Tutorial#showplots:_calib.2C_signal.2C_star'>help</a>\n");
259 printf("</td>\n");
260}
261
262
263?>
Note: See TracBrowser for help on using the repository browser.