コード例 #1
0
ファイル: format.class.php プロジェクト: Nvenom/Cellwiz
 public static function TIME_AGO($T, $R)
 {
     if (STRPOS($T, ':') !== FALSE) {
         $T = STRTOTIME($T);
     }
     $C = TIME();
     $D = $C - $T;
     $P = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
     $L = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
     for ($V = SIZEOF($L) - 1; $V >= 0 && ($N = $D / $L[$V]) <= 1; $V--) {
     }
     if ($V < 0) {
         $V = 0;
     }
     $_T = $C - $D % $L[$V];
     $N = FLOOR($N);
     if ($N != 1) {
         $P[$V] .= 's';
     }
     $X = SPRINTF("%d %s ", $N, $P[$V]);
     if ($R == 1 && $V >= 1 && $C - $_T > 0) {
         $X .= self::TIME_AGO($_T);
     }
     return $X;
 }
コード例 #2
0
 /**
  * Makes sure we have the requested number of bits in the working buffer
  * 
  * @access private
  * @param int $cnt	The number of bits needed
  */
 function fetch($cnt)
 {
     if ($this->pos < $this->ofs * 8 || $this->pos + $cnt > $this->ofs * 8 + strlen($this->bits)) {
         $this->bits = '';
         $this->ofs = FLOOR($this->pos / 8);
         for ($i = $this->ofs; $i <= $this->ofs + CEIL($cnt / 8); $i++) {
             $this->bits .= str_pad(decbin(ord($this->data[$i])), 8, '0', STR_PAD_LEFT);
         }
     }
 }
コード例 #3
0
 /**
  * Makes sure we have the requested number of bits in the working buffer
  * 
  * @access private
  * @param int $cnt  The number of bits needed
  */
 private function fetch($cnt)
 {
     // Either we already have the needed bits in the buffer or we rebuild it
     if ($this->pos < $this->ofs * 8 || $this->pos + $cnt > $this->ofs * 8 + strlen($this->bits)) {
         $this->bits = '';
         $this->ofs = FLOOR($this->pos / 8);
         for ($i = $this->ofs; $i <= $this->ofs + CEIL($cnt / 8); $i++) {
             $this->bits .= str_pad(decbin(ord($this->data[$i])), 8, '0', STR_PAD_LEFT);
         }
     }
 }
コード例 #4
0
ファイル: journal.php プロジェクト: yasirgit/alchemy
 function getTimeDiff($dtime, $atime)
 {
     $dtime = substr($dtime, 0, 5);
     $atime = substr($atime, 0, 5);
     $nextDay = $dtime > $atime ? 1 : 0;
     $dep = EXPLODE(':', $dtime);
     $arr = EXPLODE(':', $atime);
     $diff = ABS(MKTIME($dep[0], $dep[1], 0, DATE('n'), DATE('j'), DATE('y')) - MKTIME($arr[0], $arr[1], 0, DATE('n'), DATE('j') + $nextDay, DATE('y')));
     $hours = FLOOR($diff / (60 * 60));
     $mins = FLOOR(($diff - $hours * 60 * 60) / 60);
     $secs = FLOOR($diff - ($hours * 60 * 60 + $mins * 60));
     if (STRLEN($hours) < 2) {
         $hours = "0" . $hours;
     }
     if (STRLEN($mins) < 2) {
         $mins = "0" . $mins;
     }
     if (STRLEN($secs) < 2) {
         $secs = "0" . $secs;
     }
     return $hours . ':' . $mins . ':' . $secs;
 }
コード例 #5
0
ファイル: fatloss_model.php プロジェクト: yasirgit/alchemy
 function getHourDiff($firstHour, $secondHour)
 {
     $dtime = substr($firstHour, 0, 5);
     $atime = substr($secondHour, 0, 5);
     $nextDay = $dtime > $atime ? 1 : 0;
     $dep = EXPLODE(':', $dtime);
     $arr = EXPLODE(':', $atime);
     $diff = ABS(MKTIME($dep[0], $dep[1], 0, DATE('n'), DATE('j'), DATE('y')) - MKTIME($arr[0], $arr[1], 0, DATE('n'), DATE('j') + $nextDay, DATE('y')));
     $hours = FLOOR($diff / (60 * 60));
     $mins = FLOOR(($diff - $hours * 60 * 60) / 60);
     $secs = FLOOR($diff - ($hours * 60 * 60 + $mins * 60));
     if (STRLEN($hours) < 2) {
         $hours = "0" . $hours;
     }
     if (STRLEN($mins) < 2) {
         $mins = "0" . $mins;
     }
     if (STRLEN($secs) < 2) {
         $secs = "0" . $secs;
     }
     $temp = floatval($mins / 60);
     $temp += $hours;
     return $temp;
 }
コード例 #6
0
ファイル: index.php プロジェクト: laiello/yt-cache
 public function sysinfo($show)
 {
     $output = "";
     switch ($show) {
         case "disks":
             $output .= $this->page_manager->text_title("Disk statistics");
             $rows = array();
             foreach (file('/proc/diskstats') as $info) {
                 if (strstr($info, " sd")) {
                     $row = explode(" ", $info);
                     $ndx = array_search("", $row);
                     while ($ndx !== false) {
                         unset($row[$ndx]);
                         $ndx = array_search("", $row);
                     }
                     $row = array_slice($row, 2);
                     $row2 = array();
                     foreach ($row as $row1) {
                         if ((int) $row1 > 0) {
                             $row2[] = number_readable($row1, "decimals");
                         } else {
                             $row2[] = $row1;
                         }
                     }
                     $rows[] = $row2;
                 }
             }
             $header = array("device", "reads issued", "reads merged", "sectors read", "milliseconds spent reading", "writes completed", "writes merged", "sectors written", "milliseconds spent writing", "I/Os currently in progress", "milliseconds spent doing I/Os", "weighted # of milliseconds spent doing I/Os");
             $output .= $this->page_manager->table($header, $rows);
             $output .= $this->page_manager->text_title("Disk partitions");
             foreach (file('/proc/partitions') as $info) {
                 if (strstr($info, " sd")) {
                     $info = explode(" ", $info);
                     $filtered = array();
                     foreach ($info as $inf) {
                         if ($inf != "") {
                             $filtered[] = $inf;
                         }
                     }
                     $final[] = $filtered;
                 }
             }
             $header = array("major", "minor", "# blocks", "partition");
             $output .= $this->page_manager->table($header, $final);
             $output .= $this->page_manager->text_title("Disk space");
             exec("df -h | grep '/dev/sd'", $dfinfo);
             $final = array();
             foreach ($dfinfo as $info) {
                 $info = explode(" ", $info);
                 $filtered = array();
                 foreach ($info as $inf) {
                     if ($inf != "") {
                         $filtered[] = $inf;
                     }
                 }
                 $final[] = $filtered;
             }
             $header = array("device", "space", "used", "free", "percent used", "mount");
             $output .= $this->page_manager->table($header, $final);
             $output .= $this->page_manager->text_title("Disk Info");
             foreach (file('/proc/scsi/scsi') as $info) {
                 $output .= $info . HTML_EOL;
             }
             break;
         case "version":
             foreach (file('/proc/version') as $info) {
                 $output .= $info;
             }
             break;
         case "system":
             $output .= $this->page_manager->text_title("CPU");
             foreach (file('/proc/cpuinfo') as $info) {
                 $var = strtok($info, ':');
                 $val = strtok('');
                 if (strstr($var, "model name") || strstr($var, "cpu MHz") || strstr($var, "cache size") || strstr($var, "bogomips")) {
                     $output .= $info . HTML_EOL;
                 }
             }
             $output .= $this->page_manager->text_title("Loads");
             foreach (file('/proc/loadavg') as $ri) {
                 $loadavg = $ri;
             }
             $loadavg = explode(" ", $loadavg);
             $output .= "Average 1 minute: <strong>{$loadavg[0]}</strong>" . HTML_EOL;
             $output .= "Average 5 minute: <strong>{$loadavg[1]}</strong>" . HTML_EOL;
             $output .= "Average 15 minute: <strong>{$loadavg[2]}</strong>" . HTML_EOL;
             $output .= "Running process/Total process: <strong>{$loadavg[3]}</strong>" . HTML_EOL;
             $output .= "Last running process: <strong>{$loadavg[4]}</strong>" . HTML_EOL;
             foreach (file('/proc/uptime') as $ri) {
                 $uptime = $ri;
             }
             $uptime = explode(" ", $uptime);
             $uptime1 = (int) $uptime[0];
             $uptime2 = (int) $uptime[1];
             $online['days'] = FLOOR($uptime1 / (24 * 60 * 60));
             $online['hours'] = FLOOR(($uptime1 - $online['days'] * (24 * 60 * 60)) / (60 * 60));
             $online['minutes'] = FLOOR(($uptime1 - ($online['days'] * (24 * 60 * 60) + $online['hours'] * (60 * 60))) / 60);
             $output .= "Server online: <strong>{$online['days']}</strong> days <strong>{$online['hours']}</strong> hours <strong>{$online['minutes']}</strong> minutes" . HTML_EOL;
             $online['days'] = FLOOR($uptime2 / (24 * 60 * 60));
             $online['hours'] = FLOOR(($uptime2 - $online['days'] * (24 * 60 * 60)) / (60 * 60));
             $online['minutes'] = FLOOR(($uptime2 - ($online['days'] * (24 * 60 * 60) + $online['hours'] * (60 * 60))) / 60);
             $output .= "Server idle time: <strong>{$online['days']}</strong> days <strong>{$online['hours']}</strong> hours <strong>{$online['minutes']}</strong> minutes" . HTML_EOL;
             $output .= $this->page_manager->text_title("Filesystem");
             foreach (file('/proc/sys/fs/file-nr') as $ri) {
                 $filenr = $ri;
             }
             $filenr = explode(chr(9), $filenr);
             $output .= "Allocated file handles: {$filenr[0]}" . HTML_EOL;
             $output .= "Free file handles: {$filenr[1]}" . HTML_EOL;
             $output .= "Maximum file handles: {$filenr[2]}" . HTML_EOL;
             break;
         case "memory":
             $output .= $this->page_manager->text_title("Memory");
             foreach (file('/proc/meminfo') as $ri) {
                 $data_array[] = array_merge(explode(": ", $ri), array("", "", "", "", ""));
                 //$output.=$ri.HTML_EOL;
             }
             $output .= $this->page_manager->table(array(), $data_array);
             //$perc_usage=100 - round(($m['MemFree'] + $m['Buffers'] + $m['Cached']) / $m['MemTotal'] * 100);
             break;
         case "network":
             $output .= $this->page_manager->text_title("Interfaces");
             foreach (file('/proc/net/dev') as $info) {
                 $row = explode(" ", $info);
                 $ndx = array_search("", $row);
                 while ($ndx !== false) {
                     unset($row[$ndx]);
                     $ndx = array_search("", $row);
                 }
                 $rows1[] = $row;
             }
             sleep(1);
             foreach (file('/proc/net/dev') as $info) {
                 $row = explode(" ", $info);
                 $ndx = array_search("", $row);
                 while ($ndx !== false) {
                     unset($row[$ndx]);
                     $ndx = array_search("", $row);
                 }
                 $rows2[] = $row;
             }
             // remove info
             unset($rows1[0]);
             unset($rows1[1]);
             unset($rows1[2]);
             unset($rows2[0]);
             unset($rows2[1]);
             unset($rows2[2]);
             $header = array("device", "recv bytes", "recv packets", "recv errs", "recv drop", "recv fifo", "recv frame", "recv compressed", "recv multicast", "transmit bytes", "transmit packets", "transmit errs", "transmit drop", "transmit fifo", "transmit colls", "transmit carrier", "transmit compressed");
             $output .= $this->page_manager->table($header, $rows2);
             $output .= $this->page_manager->text_title("Transfer");
             $devcount = 3;
             while ($rows1[$devcount][2]) {
                 $dev1[$devcount - 3] = $rows1[$devcount][2];
                 $rx_bytes1[$devcount - 3] = $rows1[$devcount][3];
                 $rx_packets1[$devcount - 3] = $rows1[$devcount][4];
                 $tx_bytes1[$devcount - 3] = $rows1[$devcount][38];
                 $tx_packets1[$devcount - 3] = $rows1[$devcount][39];
                 $devcount++;
             }
             $devcount = 3;
             while ($rows2[$devcount][2]) {
                 $dev2[$devcount - 3] = $rows2[$devcount][2];
                 $rx_bytes2[$devcount - 3] = $rows2[$devcount][3];
                 $rx_packets2[$devcount - 3] = $rows2[$devcount][4];
                 $tx_bytes2[$devcount - 3] = $rows2[$devcount][38];
                 $tx_packets2[$devcount - 3] = $rows2[$devcount][39];
                 $devcount++;
             }
             for ($dev = 0; $dev <= $devcount - 4; $dev++) {
                 $rx_bytes[$dev] = number_readable($rx_bytes2[$dev] - $rx_bytes1[$dev]);
                 $rx_packets[$dev] = $rx_packets2[$dev] - $rx_packets1[$dev];
                 $tx_bytes[$dev] = number_readable($tx_bytes2[$dev] - $tx_bytes1[$dev]);
                 $tx_packets[$dev] = $tx_packets2[$dev] - $tx_packets1[$dev];
                 $data[] = array($dev1[$dev], $rx_bytes[$dev], $rx_packets[$dev], $tx_bytes[$dev], $tx_packets[$dev]);
             }
             $header = array("device", "rx per sec", "rx packets per sec", "tx per sec", "tx packets per sec");
             $output .= $this->page_manager->table($header, $data);
             //var_dump($dev1);die;
             break;
         default:
     }
     return $output;
 }
コード例 #7
0
ファイル: journal_Snack.php プロジェクト: yasirgit/alchemy
                if ($flagtime < $glb_time) {
                    $this->config->set_item('flagtime', $globalwaketime);
                }
            }
        }
        ///////////////////////////////
        if (isset($dtime)) {
            ///////////////////////////////////////////////////////
            $atime = substr($time->time, 0, 5);
            $nextDay = $dtime > $atime ? 1 : 0;
            $dep = EXPLODE(':', $dtime);
            $arr = EXPLODE(':', $atime);
            $diff = ABS(MKTIME($dep[0], $dep[1], 0, DATE('n'), DATE('j'), DATE('y')) - MKTIME($arr[0], $arr[1], 0, DATE('n'), DATE('j') + $nextDay, DATE('y')));
            $hours = FLOOR($diff / (60 * 60));
            $mins = FLOOR(($diff - $hours * 60 * 60) / 60);
            $secs = FLOOR($diff - ($hours * 60 * 60 + $mins * 60));
            if (STRLEN($hours) < 2) {
                $hours = "0" . $hours;
            }
            if (STRLEN($mins) < 2) {
                $mins = "0" . $mins;
            }
            $hours += $mins / 60;
            ///////////////////////////////////////////
            if ($flagw == 1 && $hours > 3 || $flagw == 0 && $hours >= 0.5) {
                $timedata['currenttime'] = $time->time;
                $timedata['flagw'] = $flagw;
                $timedata['type'] = "Snack";
                ?>
					<?php 
                $this->load->view('users/eating_journal/journal_error', $timedata);
コード例 #8
0
function DiffBetweenDates( $start, $end )
{
$month 	= date( "m", strtotime( $start ) );
$day 		= date( "d", strtotime( $start ) );
$year 	= date( "Y", strtotime( $start ) );
$month2 	= date( "m", strtotime( $end ) );
$day2 	= date( "d", strtotime( $end ) );
$year2 	= date( "Y", strtotime( $end ) );

$first_date = MKTIME( 12, 0, 0, $month, $day, $year);
$second_date = MKTIME( 12, 0, 0,$month2, $day2, $year2);
 
$offset = $second_date - $first_date;
  
return FLOOR( $offset/60/60/24 );
}
コード例 #9
0
header("Content-type: application/json; charset=utf-8");
$con = new mysqli("localhost", "root", "trinity1346", "kichwa2");
if ($con->connect_errno) {
    die("Connection failed:" . $con->connect_error);
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
//DEFINING VARIABLES
$nuevo_grados = array();
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
//mayor porejemplo
$scale_name = $request->nombre;
$scale_grades = $request->grados;
//$scale_origin=$request->origin;
//$scale_id=FLOOR(RAND() * 4001);
$scale_id = FLOOR(RAND() * 4001);
//var_dump($scale_name);
//var_dump($scale_id);
//first to find the scale
$insert_scale_name_query = "INSERT INTO numeros(numero_id,numero_name) VALUES('{$scale_id}','{$scale_name}')";
if ($con->query($insert_scale_name_query) === TRUE) {
    echo "inserted id:" . $scale_id . " scale_name: " . $scale_name . "\n";
} else {
    echo "Error: " . $insert_scale_name_query . "<br>" . $con->error . "\n";
}
foreach ($scale_grades as $index => $value) {
    if ((int) $value >= (int) 10) {
        $nuevo_grados[$index] = "C0" . $value;
    } else {
        $nuevo_grados[$index] = "C00" . $value;
    }
コード例 #10
0
ファイル: ReportsController.php プロジェクト: julkar9/gss
 private function _timeDiff($firstTime, $lastTime)
 {
     // convert to unix timestamps
     $firstTime = strtotime($firstTime);
     $lastTime = strtotime($lastTime);
     // perform subtraction to get the difference (in seconds) between times
     $diff = $lastTime - $firstTime;
     $hours = FLOOR($diff / (60 * 60));
     $mins = FLOOR(($diff - $hours * 60 * 60) / 60);
     $secs = FLOOR($diff - ($hours * 60 * 60 + $mins * 60));
     if (STRLEN($hours) < 2) {
         $hours = "0" . $hours;
     }
     if (STRLEN($mins) < 2) {
         $mins = "0" . $mins;
     }
     if (STRLEN($secs) < 2) {
         $secs = "0" . $secs;
     }
     // return $diff;
     return $hours . ' hr ' . $mins . ' min ' . $secs . ' sec ';
     // return the difference
     // return $timeDiff;
 }