source: trunk/www/dch/shifteval.php@ 19598

Last change on this file since 19598 was 18882, checked in by Daniela Dorner, 8 years ago
adapted to stricter server
File size: 10.2 KB
Line 
1<html>
2<head>
3 <meta name="Author" content="Daniela Dorner" />
4 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
5 <title>FACT Project</title>
6 <link rel="StyleSheet" type="text/css" href="../style.css" />
7</head>
8<?php
9
10 //echo (file_get_contents("../shifteval/header.html"));
11
12 if (!empty($_GET["startdate"]))
13 $startdate=$_GET["startdate"];
14 else
15 $startdate="20111001";
16 if (!empty($_GET["stopdate"]))
17 $stopdate=$_GET["stopdate"];
18 else
19 $stopdate=date("Ymd");
20 $starttimestamp = new DateTime($startdate);
21 date_add($starttimestamp, date_interval_create_from_date_string("12 hours"));
22 $stoptimestamp = new DateTime($stopdate);
23 date_add($stoptimestamp, date_interval_create_from_date_string("12 hours"));
24
25 echo "<body>\n";
26 echo "<form action='shifteval.php' METHOD='GET'>\n";
27 echo "<b>Shift Evaluation</b> from ";
28 printf("<input name='startdate' type='text' size='10' maxlength='10' value='%s'> to\n", $startdate);
29 printf("<input name='stopdate' type='text' size='10' maxlength='10' value='%s'>\n", $stopdate);
30 echo "<input type='submit' value='Show'> \n";
31
32 include ("db.php");
33 $db_id = mysql_connect($host, $user, $pw);
34
35 //some parameters for the evaluation
36 //arrays on institute base
37 $instituteshifthours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
38 $institutedebughours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
39 $instituteexperthours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
40 $institutetotalhours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
41 $institutes2= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
42 $institutenames=array();
43 //arrays on userbase
44 $users=array();
45 $shifthours=array();
46 $debughours=array();
47 $experthours=array();
48 $totalhours=array();
49 $affiliation=array();
50 //$shifthourstotal=0;
51 //$debughourstotal=0;
52 //$experthourstotal=0;
53 $hourstotal=0;
54 $counter=0;
55
56 //get username-id connection
57 $queryusers="SELECT username, uid FROM logbook.users ORDER BY username";
58 $resultusers = mysql_query($queryusers);
59 while ($rowusers = mysql_fetch_row($resultusers))
60 $users[$rowusers[0]]=$rowusers[1];
61 mysql_free_result($resultusers);
62
63 //get institutename-id connection
64 $queryinstitutes="SELECT instituteid, institutename FROM memberlist.institutes ";
65 $resultinstitutes = mysql_query($queryinstitutes);
66 while ($rowinstitutes = mysql_fetch_row($resultinstitutes))
67 $institutenames[$rowinstitutes[0]]=$rowinstitutes[1];
68 mysql_free_result($resultinstitutes);
69
70 //loop over the nights in the given time range
71 while ($starttimestamp<=$stoptimestamp)
72 {
73 //get affiliation of users
74 $queryaffiliation="SELECT userid, instituteid FROM memberlist.members ";
75 $queryaffiliation.=" WHERE (start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
76 $queryaffiliation.=" AND stop > '".$starttimestamp->format('Y-m-d H:i:s')."')";
77 $queryaffiliation.=" OR (ISNULL(start) AND ISNULL(stop))";
78 $resultaffiliation = mysql_query($queryaffiliation);
79 while ($rowaffiliation = mysql_fetch_row($resultaffiliation))
80 $affiliation[$rowaffiliation[0]]=$rowaffiliation[1];
81 mysql_free_result($resultaffiliation);
82
83 // get share according to member list
84 $queryshare="SELECT instituteid, COUNT(*) FROM memberlist.members ";
85 $queryshare.=" WHERE start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
86 $queryshare.=" AND stop > '".$starttimestamp->format('Y-m-d H:i:s')."'";
87 $queryshare.=" GROUP BY instituteid";
88 $resultshare = mysql_query($queryshare);
89 $sumpeople=0;
90 $institutes= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
91 while ($rowshare = mysql_fetch_row($resultshare))
92 {
93 $institutes[$rowshare[0]]+=$rowshare[1];
94 $sumpeople+=$rowshare[1];
95 }
96 foreach ($institutes as $key=>$value)
97 $institutes2[$key]+=$value/$sumpeople;
98
99 // get total hours of night
100 $queryhours="SELECT Time_to_Sec(Timediff(fStopObservation, fStartObservation))/60./60.+1";
101 $queryhours.=" FROM factdata.ObservationTimes WHERE fNight=".$starttimestamp->format('Ymd');
102 $resulthours = mysql_query($queryhours);
103 $rowhours = mysql_fetch_row($resulthours);
104 $numhours=$rowhours[0];
105 mysql_free_result($resulthours);
106
107 $queryusers="SELECT uid FROM calendar.Data LEFT JOIN logbook.users ON calendar.Data.u=logbook.users.username ";
108 $queryusers.="WHERE CONCAT(y,LPAD(m+1,2,0),LPAD(d,2,0))=".$starttimestamp->format('Ymd');
109 $queryusers.=" AND u NOT IN ('ETHZ','ISDC','UNIWUE','TUDO','moon')";
110 // get shifthours per user and institute
111 $queryshifters=$queryusers." AND x=0";
112 $resultshifters = mysql_query($queryshifters);
113 while ($rowshifters = mysql_fetch_row($resultshifters))
114 {
115 if(!isset($shifthours[$rowshifters[0]]))
116 $shifthours[$rowshifters[0]]=0;
117 if(!isset($totalhours[$rowshifters[0]]))
118 $totalhours[$rowshifters[0]]=0;
119 if (!isset($affiliation[$rowshifters[0]]))
120 {
121 $affiliation[$rowshifters[0]] = $rowshifters[0];
122 $institutes2[$rowshifters[0]] = 0;
123 $institutenames[$rowshifters[0]] = $rowshifters[0];
124 $institutetotalhours[$rowshifters[0]] = 0;
125 $instituteshifthours[$rowshifters[0]] = 0;
126 }
127
128 $shifthours[$rowshifters[0]]+=$numhours/mysql_num_rows($resultshifters);
129 $totalhours[$rowshifters[0]]+=$numhours/mysql_num_rows($resultshifters);
130 $instituteshifthours[$affiliation[$rowshifters[0]]]+=$numhours/mysql_num_rows($resultshifters);
131 $institutetotalhours[$affiliation[$rowshifters[0]]]+=$numhours/mysql_num_rows($resultshifters);
132 $hourstotal+=$numhours/mysql_num_rows($resultshifters);
133 }
134 mysql_free_result($resultshifters);
135 //get debugging times per user and institute
136 $querydebug=$queryusers." AND x=1";
137 $resultdebug = mysql_query($querydebug);
138 while ($rowdebug = mysql_fetch_row($resultdebug))
139 {
140 if(!isset($debughours[$rowdebug[0]]))
141 $debughours[$rowdebug[0]]=0;
142 if(!isset($totalhours[$rowdebug[0]]))
143 $totalhours[$rowdebug[0]]=0;
144
145 $debughours[$rowdebug[0]]+=$numhours*0.5;
146 $totalhours[$rowdebug[0]]+=$numhours*0.5;
147 $institutedebughours[$affiliation[$rowdebug[0]]]+=$numhours*0.5;
148 $institutetotalhours[$affiliation[$rowdebug[0]]]+=$numhours*0.5;
149 $hourstotal+=$numhours*0.5;
150 }
151 mysql_free_result($resultdebug);
152
153 //get experts
154 //total 1 year: 4000 hours ~10.9h/night -> 46 hours/shift slot
155 //1 shift slot 46 hours
156 // 4000/46 = 87
157 // -> 87 shift slots
158 // expert 6 slots
159 // 87/6 -> 14.5
160 // => expert counts 1/13 of normal time
161 $devide=14.5;
162 $queryexperts="SELECT userid FROM memberlist.experts ";
163 $queryexperts.=" WHERE start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
164 //$queryexperts.=" AND stop > '".$stoptimestamp->format('Y-m-d H:i:s')."'";
165 $queryexperts.=" AND stop > '".$starttimestamp->format('Y-m-d H:i:s')."'";
166 $resultexperts = mysql_query($queryexperts);
167 while ($rowexperts = mysql_fetch_row($resultexperts))
168 {
169 if (!isset($experthours[$rowexperts[0]]))
170 $experthours[$rowexperts[0]]=0;
171
172 $experthours[$rowexperts[0]]+=$numhours/mysql_num_rows($resultexperts)/$devide;
173 $totalhours[$rowexperts[0]]+=$numhours/mysql_num_rows($resultexperts)/$devide;
174 $instituteexperthours[$affiliation[$rowexperts[0]]]+=$numhours/mysql_num_rows($resultexperts)/$devide;
175 $institutetotalhours[$affiliation[$rowexperts[0]]]+=$numhours/mysql_num_rows($resultexperts)/$devide;
176 $hourstotal+=$numhours/mysql_num_rows($resultexperts)/$devide;
177 }
178 mysql_free_result($resultexperts);
179
180 date_add($starttimestamp, date_interval_create_from_date_string("1 days"));
181 $counter++;
182 }
183 foreach ($institutes2 as $key=>$value)
184 $institutes2[$key]=$value/$counter;
185 mysql_free_result($resultshare);
186
187 mysql_close($db_id);
188
189 echo "<br>\n<br>\n";
190 echo "<b>Total number of hours:</b> ".$hourstotal." h.";
191 echo "<table>\n";
192 echo "<tr><td align='center'><b>institute</b></td><td align='center'>hours (shift/debug/expert)</td><td>share required:done->fulfilled</td></tr>\n";
193 foreach ($institutenames as $id=>$name)
194 {
195 //if (!$institutetotalhours[$id])
196 // continue;
197
198 if ($institutes2[$id]==0)
199 continue;
200
201 echo "<tr><td>";
202 echo $name;//."(".$id.")";
203 echo "</td><td align='right'>";
204 printf("%7.2f (%7.2f/%7.2f/%7.2f)",$institutetotalhours[$id],$instituteshifthours[$id],$institutedebughours[$id],$instituteexperthours[$id]);
205 echo "</td><td align='right'>";
206 printf("%7.2f%%: %7.2f%% -> %5.2f%%",$institutes2[$id]*100, $institutetotalhours[$id]/$hourstotal*100, ($institutetotalhours[$id]/$hourstotal)/$institutes2[$id]*100);
207 echo "</td></tr>\n";
208 }
209 echo "</table><br>\n";
210
211 echo "<table>\n";
212 echo "<tr><td align='center'><b>user</b></td><td align='center'>hours(shift/debug/expert)</td></tr>\n";
213 foreach ($users as $name=>$id)
214 {
215 if (!isset($totalhours[$id]) || !$totalhours[$id])
216 continue;
217
218 if(!isset($totalhours[$id]))
219 $totalhours[$id]=0;
220 if(!isset($debughours[$id]))
221 $debughours[$id]=0;
222 if(!isset($experthours[$id]))
223 $experthours[$id]=0;
224
225 echo "<tr><td>";
226 echo $name;//." (".$id.")";
227 echo "</td><td align='right'>";
228 printf("%5.2f (%5.2f/%5.2f/%5.2f)",$totalhours[$id],$shifthours[$id],$debughours[$id],$experthours[$id]);
229 echo "</td></tr>\n";
230 }
231 echo "</table>\n<br>\n";
232 echo "Remark: Debugging times before 2013/02 are not taken into account, i.e. first 16 months of debugging is missing in the automatic evaluation system.";
233 echo "<br>\n<br>\n";
234
235 echo "</form>\n";
236 echo "</body>\n";
237 echo "</html>\n";
238
239?>
Note: See TracBrowser for help on using the repository browser.