Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- date_default_timezone_set("Europe/London");
- $sqlh = new PDO("mysql:host=127.0.0.1;dbname=wifi", "", ""); //connect to MySQl - add values
- $devices = array();
- $date = "2015_02_23";
- $macs = $sqlh->query("SELECT mac,COUNT(seen_epoch) FROM meraki_$date group by mac having count(seen_epoch)>10 LIMIT 10;"); //get list of macs from db
- while($mac = $macs->fetch(PDO::FETCH_ASSOC)) { //loop over mac addresses
- $first_seen = "";
- $last_seen = "";
- $sql_string = "SELECT seen_time,seen_epoch,last_seen,mac FROM meraki_$date WHERE mac='" . $mac['mac'] . "' ORDER BY seen_epoch ASC;"; //get all records for each mac
- $records = $sqlh->query($sql_string);
- while($record = $records->fetch(PDO::FETCH_ASSOC)) { //loop over records
- if(date("G", $record['seen_epoch']) < 7) { //Values before 7am are assumed not to be actual visitors
- continue; //continue to next iteration of loop without taking further action
- }
- if($first_seen == "") { //if begining of a new visit - record start time
- $first_seen = $record['seen_epoch'];
- }
- if($record['last_seen'] < 3600) { // if less than 1 hour since previous entry then assume continuing visit
- $last_seen = $record['seen_epoch'];
- } else {
- $visit['arrival'] = $first_seen; //Add arrival & departure times to array
- $visit['depart'] = $last_seen;
- $visits[] = $visit; //Add visit to array of visits
- $first_seen == ""; //reset visit start time
- }
- $mac = $record['mac'];//record device mac address
- }
- $visit['arrival'] = $first_seen;
- $visit['depart'] = $last_seen;
- $visits[] = $visit;
- $first_seen == "";
- $devices[] = $visits;
- }
- print_r($devices);
- foreach($devices as $addr => $row) {
- foreach($row as $visit) {
- $arrival = date("r", $visit['arrival']);
- $departure = date("r", $visit['depart']);
- echo ("Device $addr arrived at $arrival and left at $departure<p />");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement