Exemplo n.º 1
0
function importShuttlePositions()
{
    $url = "http://shuttles.rpi.edu/vehicles/current.js";
    //mysql_query("TRUNCATE stops"); mysql_query("TRUNCATE stop_routes"); mysql_query("TRUNCATE routes"); mysql_query("TRUNCATE route_coords");
    $data = json_decode(getUrl($url));
    print_r($data);
    foreach ($data as $current_stat_item) {
        if ($current_stat_item->vehicle) {
            $shuttle_status = $current_stat_item->vehicle;
            /* update 'shuttle' table */
            if (Shuttle::get($shuttle_status->id)) {
                Shuttle::update($shuttle_status->id, $shuttle_status);
            } else {
                Shuttle::insert($shuttle_status);
            }
            if ($shuttle_status->latest_position) {
                /* update 'shuttle_coords' table */
                echo "inserting into shuttleCoords";
                echo ShuttleCoords::insert($shuttle_status->id, $shuttle_status->latest_position);
            }
        }
    }
    ShuttleCoords::deleteOlderThan(2);
    /* delete history over 2 days old */
}
function importShuttlePositions()
{
    $url = "http://shuttles.rpi.edu/vehicles/current.js";
    //mysql_query("TRUNCATE stops"); mysql_query("TRUNCATE stop_routes"); mysql_query("TRUNCATE routes"); mysql_query("TRUNCATE route_coords");
    $data = json_decode(getUrl($url));
    /*$data = json_decode('[
        {
            "vehicle": {
                "id": 7,
                "name": "Bus 90",
                "latest_position": {
                    "heading": 10,
                    "latitude": "42.73548",
                    "longitude": "-73.67086",
                    "speed": 30,
                    "public_status_msg": null,
                    "cardinal_point": "North"
                },
                "icon": {
                    "id": 1
                }
            }
        }
    ]');   */
    //print_ar($data);exit;
    foreach ($data as $current_stat_item) {
        if ($current_stat_item->vehicle) {
            $shuttle_status = $current_stat_item->vehicle;
            /* update 'shuttle' table */
            if (Shuttle::get($shuttle_status->id)) {
                Shuttle::update($shuttle_status->id, $shuttle_status);
            } else {
                Shuttle::insert($shuttle_status);
            }
            if ($shuttle_status->latest_position) {
                /* update 'shuttle_coords' table */
                ShuttleCoords::insert($shuttle_status->id, $shuttle_status->latest_position);
            }
        }
    }
    ShuttleCoords::deleteOlderThan(2);
    /* delete history over 2 days old */
}