Index: /trunk/www/dch/shifteval.php
===================================================================
--- /trunk/www/dch/shifteval.php	(revision 19741)
+++ /trunk/www/dch/shifteval.php	(revision 19742)
@@ -38,4 +38,6 @@
     $institutedebughours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
     $instituteexperthours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
+    $instituteshexperthours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
+    $instituteflareexperthours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
     $institutetotalhours= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
     $institutes2= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
@@ -52,4 +54,6 @@
     //$experthourstotal=0;
     $hourstotal=0;
+    $hourstotal2=0;
+    $hourstotal3=0;
     $counter=0;
 
@@ -104,4 +108,5 @@
         $numhours=$rowhours[0];
         mysql_free_result($resulthours);
+        $hourstotal2+=$numhours;
 
         $queryusers="SELECT uid FROM calendar.Data LEFT JOIN logbook.users ON calendar.Data.u=logbook.users.username ";
@@ -111,4 +116,6 @@
         $queryshifters=$queryusers." AND x=0";
         $resultshifters  = mysql_query($queryshifters);
+        if (mysql_num_rows($resultshifters)>0)
+            $hourstotal3+=$numhours;
         while ($rowshifters = mysql_fetch_row($resultshifters))
         {
@@ -152,15 +159,19 @@
 
         //get experts
-        //total 1 year: 4000 hours ~10.9h/night -> 46 hours/shift slot
-        //1 shift slot 46 hours
-        // 4000/46 = 87
-        // -> 87 shift slots
-        // expert 6 slots
-        // 87/6 -> 14.5
-        // => expert counts 1/13 of normal time
-        $devide=14.5;
+        // old shift scheme:
+        //   per period: 3 blocks with 2 shifters -> 6 slots
+        //   expert: 2 months = 1 slot
+        // new shift scheme:
+        //   per period: 4 blocks with 1 shifters -> 4 slots
+        //   expert: 1 months = 1 slot
+        //   + SH expert
+        // + add flare expert starting from 2014/03
+        if ($starttimestamp->format('Ymd')<20171201)
+            $devide=12.0;
+        else
+            $devide=6.0;
         $queryexperts="SELECT userid FROM memberlist.experts ";
-        $queryexperts.=" WHERE start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
-        //$queryexperts.=" AND stop > '".$stoptimestamp->format('Y-m-d H:i:s')."'";
+        $queryexperts.=" WHERE expert=1 ";
+        $queryexperts.=" AND start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
         $queryexperts.=" AND stop > '".$starttimestamp->format('Y-m-d H:i:s')."'";
         $resultexperts  = mysql_query($queryexperts);
@@ -177,4 +188,48 @@
         }
         mysql_free_result($resultexperts);
+        // sh experts
+        if ($starttimestamp->format('Ymd')>20171201)
+        {
+            $devide=6.0;
+            $queryshexperts="SELECT userid FROM memberlist.experts ";
+            $queryshexperts.=" WHERE sh=1 ";
+            $queryshexperts.=" AND start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
+            $queryshexperts.=" AND stop > '".$starttimestamp->format('Y-m-d H:i:s')."'";
+            $resultshexperts  = mysql_query($queryshexperts);
+            while ($rowshexperts = mysql_fetch_row($resultshexperts))
+            {
+                if (!isset($shexperthours[$rowshexperts[0]]))
+                    $shexperthours[$rowshexperts[0]]=0;
+
+                $shexperthours[$rowshexperts[0]]+=$numhours/mysql_num_rows($resultshexperts)/$devide;
+                $totalhours[$rowexperts[0]]+=$numhours/mysql_num_rows($resultshexperts)/$devide;
+                $instituteshexperthours[$affiliation[$rowshexperts[0]]]+=$numhours/mysql_num_rows($resultshexperts)/$devide;
+                $institutetotalhours[$affiliation[$rowshexperts[0]]]+=$numhours/mysql_num_rows($resultshexperts)/$devide;
+                $hourstotal+=$numhours/mysql_num_rows($resultshexperts)/$devide;
+            }
+            mysql_free_result($resultshexperts);
+        }
+        // flare experts
+        if ($starttimestamp->format('Ymd')>20140318)
+        {
+            $devide=6.0;
+            $queryflareexperts="SELECT userid FROM memberlist.experts ";
+            $queryflareexperts.=" WHERE flare=1 ";
+            $queryflareexperts.=" AND start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
+            $queryflareexperts.=" AND stop > '".$starttimestamp->format('Y-m-d H:i:s')."'";
+            $resultflareexperts  = mysql_query($queryflareexperts);
+            while ($rowflareexperts = mysql_fetch_row($resultflareexperts))
+            {
+                if (!isset($flareexperthours[$rowflareexperts[0]]))
+                    $flareexperthours[$rowflareexperts[0]]=0;
+
+                $flareexperthours[$rowflareexperts[0]]+=$numhours/mysql_num_rows($resultflareexperts)/$devide;
+                $totalhours[$rowexperts[0]]+=$numhours/mysql_num_rows($resultflareexperts)/$devide;
+                $instituteflareexperthours[$affiliation[$rowflareexperts[0]]]+=$numhours/mysql_num_rows($resultflareexperts)/$devide;
+                $institutetotalhours[$affiliation[$rowflareexperts[0]]]+=$numhours/mysql_num_rows($resultflareexperts)/$devide;
+                $hourstotal+=$numhours/mysql_num_rows($resultflareexperts)/$devide;
+            }
+            mysql_free_result($resultflareexperts);
+        }
 
         date_add($starttimestamp, date_interval_create_from_date_string("1 days"));
@@ -188,7 +243,11 @@
 
     echo "<br>\n<br>\n";
-    echo "<b>Total number of hours:</b> ".$hourstotal." h.";
+    //echo "<b>Total number of hours:</b> ".$hourstotal2." h (all nights).<br>\n";
+    //echo "<b>Total number of hours:</b> ".$hourstotal3." h (all data taking nights).<br>\n";
+    //echo "<b>Total number of hours:</b> ".$hourstotal." h (all data taking nights incl expert hours).\n";
+    echo "<b>Total number of hours (all duties):</b> ".$hourstotal." h.<br>\n";
+    echo "<b>Total number of hours (shift duties):</b> ".$hourstotal3." h.\n";
     echo "<table>\n";
-    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";
+    echo "<tr><td align='center'><b>institute</b></td><td align='center'>hours (shift/debug/expert/flare/sh)</td><td>share required:done->fulfilled</td></tr>\n";
     foreach ($institutenames as $id=>$name)
     {
@@ -202,5 +261,5 @@
         echo $name;//."(".$id.")";
         echo "</td><td align='right'>";
-        printf("%7.2f (%7.2f/%7.2f/%7.2f)",$institutetotalhours[$id],$instituteshifthours[$id],$institutedebughours[$id],$instituteexperthours[$id]);
+        printf("%7.2f (%7.2f/%7.2f/%7.2f/%7.2f/%7.2f)",$institutetotalhours[$id],$instituteshifthours[$id],$institutedebughours[$id],$instituteexperthours[$id],$instituteflareexperthours[$id],$instituteshexperthours[$id]);
         echo "</td><td align='right'>";
         printf("%7.2f%%: %7.2f%% -> %5.2f%%",$institutes2[$id]*100, $institutetotalhours[$id]/$hourstotal*100, ($institutetotalhours[$id]/$hourstotal)/$institutes2[$id]*100);
@@ -210,5 +269,5 @@
 
     echo "<table>\n";
-    echo "<tr><td align='center'><b>user</b></td><td align='center'>hours(shift/debug/expert)</td></tr>\n";
+    echo "<tr><td align='center'><b>user</b></td><td align='center'>hours(shift/debug/expert/flare/sh)</td></tr>\n";
     foreach ($users as $name=>$id)
     {
@@ -226,5 +285,5 @@
         echo $name;//." (".$id.")";
         echo "</td><td align='right'>";
-        printf("%5.2f (%5.2f/%5.2f/%5.2f)",$totalhours[$id],$shifthours[$id],$debughours[$id],$experthours[$id]);
+        printf("%5.2f (%5.2f/%5.2f/%5.2f/%5.2f/%5.2f)",$totalhours[$id],$shifthours[$id],$debughours[$id],$experthours[$id],$flareexperthours[$id],$shexperthours[$id]);
         echo "</td></tr>\n";
     }
