Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 41 additions & 33 deletions Velo.class.php
Original file line number Diff line number Diff line change
@@ -1,89 +1,97 @@
<?php

/**
*
*
* @package packages/Bikes
* @copyright (C) 2012 by iRail vzw/asbl
* @license AGPLv3
* @author Pieter Colpaert <pieter aŧ iRail.be>
*/
class BikesVelo extends AReader
{

class BikesVelo extends AReader{

public function __construct($package, $resource, $RESTparameters) {
parent::__construct($package, $resource, $RESTparameters);
public function __construct($package, $resource, $RESTparameters)
{
parent::__construct($package, $resource, $RESTparameters);
$this->lat = null;
$this->long = null;
$this->offset = 0;
$this->rowcount = 1024;
}

public static function getParameters(){
return array( "lat" => "Latitude"
,"long" => "Longitude"
,"offset" => "Offset"
,"rowcount" => "Rowcount");
public static function getParameters()
{
return [
"lat" => "Latitude",
"long" => "Longitude",
"offset" => "Offset",
"rowcount" => "Rowcount",
];
}

public static function getRequiredParameters(){
public static function getRequiredParameters()
{
return array();
}

public function setParameter($key,$val){
if($key == "lat") {
public function setParameter($key, $val)
{
if ($key == "lat") {
$this->lat = $val;
} else if ($key == "long") {
} elseif ($key == "long") {
$this->long = $val;
} else if ($key == "offset") {
} elseif ($key == "offset") {
$this->offset = $val;
} else if ($key == "rowcount") {
} elseif ($key == "rowcount") {
$this->rowcount = $val;
}
}

public function read(){
public function read()
{
$data = TDT::HttpRequest("http://ClearChannelBikes:[email protected]/data/stations.json");
$decoded = json_decode($data->data);
//todo: convert to wished format

$result = array();
$gpoint = new gPoint();
foreach($decoded as $sourceStation) {

foreach ($decoded as $sourceStation) {
$station = new Object();

$station->name = $sourceStation->name;
$station->freebikes = $sourceStation->bikes;
$station->freespots = $sourceStation->slots;
$station->state = $sourceStation->status;
$station->latitude = $sourceStation->latitude;
$station->longitude = $sourceStation->longitude;

$gpoint->setLongLat($station->longitude, $station->latitude);
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
$station->distance = $gpoint->distanceFrom($this->long, $this->lat);
}

array_push($result, $station);
}

function compare($a, $b) {

function compare($a, $b)
{
if ($a->distance == $b->distance) {
return 0;
}
return ($a->distance < $b->distance) ? -1 : 1;
}
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
usort($result, "compare");
}

return array_slice($result, $this->offset, $this->rowcount);
}

public static function getDoc(){
public static function getDoc()
{
return "This resource contains dynamic information about the availability of bikes in Antwerp";
}
}

?>
78 changes: 43 additions & 35 deletions Villo.class.php
Original file line number Diff line number Diff line change
@@ -1,99 +1,107 @@
<?php
/**
*
*
* @package packages/Bikes
* @copyright (C) 2012 by iRail vzw/asbl
* @license AGPLv3
* @author Pieter Colpaert <pieter aŧ iRail.be>
*/

include_once('gpoint.php');

class BikesVillo extends AReader{

public function __construct($package, $resource, $RESTparameters) {
parent::__construct($package, $resource, $RESTparameters);
class BikesVillo extends AReader
{

public function __construct($package, $resource, $RESTparameters)
{
parent::__construct($package, $resource, $RESTparameters);
$this->lat = null;
$this->long = null;
$this->offset = 0;
$this->rowcount = 1024;
}

public static function getParameters(){
return array( "lat" => "Latitude"
,"long" => "Longitude"
,"offset" => "Offset"
,"rowcount" => "Rowcount");
public static function getParameters()
{
return [
"lat" => "Latitude",
"long" => "Longitude",
"offset" => "Offset",
"rowcount" => "Rowcount",
];
}

public static function getRequiredParameters(){
public static function getRequiredParameters()
{
return array();
}

public function setParameter($key,$val){
if($key == "lat") {
public function setParameter($key, $val)
{
if ($key == "lat") {
$this->lat = $val;
} else if ($key == "long") {
} elseif ($key == "long") {
$this->long = $val;
} else if ($key == "offset") {
} elseif ($key == "offset") {
$this->offset = $val;
} else if ($key == "rowcount") {
} elseif ($key == "rowcount") {
$this->rowcount = $val;
}
}

public function read(){
public function read()
{
$data = TDT::HttpRequest("http://www.mobielbrussel.irisnet.be/villo/json/");
$decoded = json_decode($data->data);
//todo: convert to wished format

$result = array();
$gpoint = new gPoint();
foreach($decoded->features as $feature) {

foreach ($decoded->features as $feature) {
$station = new Object();

$station->name = $feature->properties->NAME;
$station->freebikes = $feature->properties->FREEBK;
$station->freespots = $feature->properties->FREEBS;
$station->state = $feature->properties->STATE;

// Configure the gPoint library to use the Lambert Projection for Belgium
$gpoint->configLambertProjection(150000.013, 5400088.438, 4.367487, 90, 49.833333, 51.166666);
$x = $feature->geometry->coordinates[0];
$y = $feature->geometry->coordinates[1];

$gpoint->setLambert($x, $y);
// Convert the Lambert Coordinates to Latitude and Longitude (using the gPoint Library)
$gpoint->convertLCCtoLL();

$station->latitude = $gpoint->lat;
$station->longitude = $gpoint->long;
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
$station->distance = $gpoint->distanceFrom($this->long, $this->lat);
}

array_push($result, $station);
}

function compare($a, $b) {

function compare($a, $b)
{
if ($a->distance == $b->distance) {
return 0;
}
return ($a->distance < $b->distance) ? -1 : 1;
}
if($this->lat != null && $this->long != null) {

if ($this->lat != null && $this->long != null) {
usort($result, "compare");
}

return array_slice($result, $this->offset, $this->rowcount);
}

public static function getDoc(){
public static function getDoc()
{
return "This resource contains dynamic information about the availability of bikes in Brussels";
}
}

?>
Loading