Changeset 17599 for trunk/www/dch


Ignore:
Timestamp:
03/04/14 00:47:09 (11 years ago)
Author:
Daniela Dorner
Message:
added evaluation of shift duties (so far not taking into account institute changes of members)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/dch/shifteval.php

    r17531 r17599  
    1818    else
    1919    {
    20         $stopdate="20130209";
     20        //$stopdate="20130209";
    2121        $stopdate=date("Ymd");
    2222    }
     23    $starttimestamp = new DateTime($startdate);
     24    date_add($starttimestamp, date_interval_create_from_date_string("12 hours"));
     25    $stoptimestamp = new DateTime($stopdate);
     26    date_add($stoptimestamp, date_interval_create_from_date_string("12 hours"));
    2327
    2428    echo "<body>\n";
     
    3337    $db_id = mysql_connect($host, $user, $pw);
    3438
     39    //some parameters for the evaluation
     40    $institutesum= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
     41    $users=array();
     42    $affiliation=array();
     43    $shifthours=array();
     44    $shifthourstotal=0;
     45
     46    //get affiliation of users
     47    $queryaffiliation="SELECT userid, Min(instituteid) FROM memberlist.members GROUP BY userid";
     48    $resultaffiliation  = mysql_query($queryaffiliation);
     49    while ($rowaffiliation = mysql_fetch_row($resultaffiliation))
     50        $affiliation[$rowaffiliation[0]]=$rowaffiliation[1];
     51    mysql_free_result($resultaffiliation);
     52
     53    //get username-id connection
     54    $queryusers="SELECT username, uid FROM logbook.users ";
     55    $resultusers  = mysql_query($queryusers);
     56    while ($rowusers = mysql_fetch_row($resultusers))
     57        $users[$rowusers[0]]=$rowusers[1];
     58    mysql_free_result($resultusers);
     59
     60    //calculate shift hours
    3561    $querynames="SELECT count(*), u FROM calendar.Data ";
    3662    $querynames.=" WHERE u NOT IN ('ETHZ', 'ISDC', 'UNIDO', 'UNIWUE') ";
     
    6086            }
    6187        }
    62         echo "<tr>\n<td>".$rownames[1]."</td>\n<td>".$sum."</td>\n</tr>";
     88        if ($sum>0)
     89        {
     90            echo "<tr>\n<td>".$rownames[1]."</td>\n<td>".$sum."</td>\n</tr>";
     91            $shifthours[$users[$rownames[1]]]+=$sum;
     92        }
    6393    mysql_free_result($resultnights);
    6494    }
     
    99129        }
    100130        echo "<tr>\n<td>".$rownames[1]."</td>\n<td>".$sum."</td>\n</tr>";
     131        $shifthours[$users[$rownames[1]]]+=$sum;
    101132        mysql_free_result($resultnights);
    102133    }
     
    150181        $sumexpert+=$rowexpert[1]/$devide;
    151182    }
     183    $shifthours[2]+=$sumdani;
     184    $shifthours[3]+=$sumthomas;
     185    $shifthours[7]+=$sumjens;
     186    $shifthours[11]+=$sumdom;
    152187
    153188    //echo $sumexpert;
     
    164199    echo "</table>\n";
    165200
     201
     202    //calculating the shares of the institutes according to the member list
     203    $counter=0;
     204    $institutes2= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
     205    print_r($institutes);
     206
     207    while ($starttimestamp<$stoptimestamp)
     208    {
     209        $queryshare="SELECT instituteid, COUNT(*) FROM memberlist.members ";
     210        $queryshare.=" WHERE start < '".$starttimestamp->format('Y-m-d H:i:s')."'";
     211        $queryshare.=" AND stop > '".$stoptimestamp->format('Y-m-d H:i:s')."'";
     212        $queryshare.=" GROUP BY instituteid";
     213        //echo $queryshare." ";
     214        //echo $starttimestamp->format('Y-m-d H:i:s');
     215        $resultshare  = mysql_query($queryshare);
     216        $sumpeople=0;
     217        $institutes= array ("1" => 0, "2" => 0, "3" => 0, "4" => 0, "5" => 0 );
     218        while ($rowshare = mysql_fetch_row($resultshare))
     219        {
     220            $institutes[$rowshare[0]]+=$rowshare[1];///mysql_num_rows($resultshare);
     221            $sumpeople+=$rowshare[1];
     222            //echo $rowshare[0]."..".$rowshare[1]." ";
     223        }
     224        foreach ($institutes as $key=>$value)
     225            $institutes2[$key]+=$value/$sumpeople;
     226        //print_r($institutes2);
     227        date_add($starttimestamp, date_interval_create_from_date_string("1 days"));
     228        $counter++;
     229    }
     230    //$institutes = array_map( function($val,$factor) { return $val / $factor; }, $institutes, array_fill(0, count($institutes), $counter));
     231    foreach ($institutes2 as $key=>$value)
     232        $institutes2[$key]=$value/$counter;
     233    //print_r($institutes2);
     234    mysql_free_result($resultshare);
     235    //print_r($affiliation);
     236    //print_r($users);
     237    //print_r($shifthours);
     238
     239    foreach ($shifthours as $user=>$hours)
     240    {
     241        $shifthourstotal+=$hours;
     242        $institutesum[$affiliation[$user]]+=$hours;
     243    }
     244    foreach ($institutesum as $key=>$value)
     245        $institutesum[$key]=$value/$shifthourstotal;
     246    //print_r($institutesum);
     247    echo "<br>\n First Evaluation:<br>\n Institute: duty - done<br>\n";
     248    foreach ($institutes2 as $key=>$value)
     249        echo $key.": ".$value." - ".$institutesum[$key]."=> ".$institutesum[$key]*100/$value."% <br>";
     250    echo "remark: does not yet take into account institute changes, i.e. only valid from 1.9.2012<br>";
     251
     252
     253
    166254    mysql_close($db_id);
    167255
Note: See TracChangeset for help on using the changeset viewer.