Merge branch 'issue-37' of krzysiej/paper-pi into master
This commit was merged in pull request #51.
This commit is contained in:
@@ -46,10 +46,8 @@ class Keyboard extends Controller
|
|||||||
case 'last':
|
case 'last':
|
||||||
$main = new Main();
|
$main = new Main();
|
||||||
$main->noteLast();
|
$main->noteLast();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case $keyboardAction[1] > 0:
|
case $keyboardAction[1] > 0:
|
||||||
echo 'test';
|
|
||||||
$main = new Main();
|
$main = new Main();
|
||||||
$main->printNote((int)$keyboardAction[1]);
|
$main->printNote((int)$keyboardAction[1]);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class Main extends Controller
|
|||||||
|
|
||||||
|
|
||||||
$image = $image->greyscale()
|
$image = $image->greyscale()
|
||||||
->resize(300, null, function ($constraint) {
|
->resize(370, null, function ($constraint) {
|
||||||
$constraint->aspectRatio();
|
$constraint->aspectRatio();
|
||||||
$constraint->upsize();
|
$constraint->upsize();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -79,23 +79,12 @@ class HtmlToPos
|
|||||||
|
|
||||||
public function traficar($posText)
|
public function traficar($posText)
|
||||||
{
|
{
|
||||||
$data = $posText;
|
|
||||||
if (strstr($posText, '[traficar]')) {
|
if (strstr($posText, '[traficar]')) {
|
||||||
$data = [];
|
|
||||||
$traficar = new Traficar();
|
$traficar = new Traficar();
|
||||||
$nearest = $traficar->nearestCar();
|
$nearest = $traficar->nearestCarText();
|
||||||
|
$posText = str_replace('[traficar]', $nearest, $posText);
|
||||||
$data['text'] = "Najbliższy traficar:\n" .
|
|
||||||
'Model: ' . $nearest['car']['model'] . "\n" .
|
|
||||||
'Numer boczny: ' . $nearest['car']['orderNumber'] . "\n" .
|
|
||||||
'Rejestracja: ' . $nearest['car']['regNumber'] . "\n" .
|
|
||||||
'Lokalizacja: ' . $nearest['car']['location'] . "\n" .
|
|
||||||
'Odległość: ' . $nearest['distance'] . "km\n";
|
|
||||||
// $data['image'] = $nearest['imageName'];
|
|
||||||
// $data['image'] = 'https://staticmapmaker.com/img/cartodb_placeholder.png';
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return $data;
|
return $posText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,6 @@ class Paper
|
|||||||
$this->printer->text($convertedData['text']);
|
$this->printer->text($convertedData['text']);
|
||||||
} else {
|
} else {
|
||||||
$this->printer->text($htmlToPos->convert($text));
|
$this->printer->text($htmlToPos->convert($text));
|
||||||
|
|
||||||
}
|
}
|
||||||
$this->printer->feed(3);
|
$this->printer->feed(3);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,9 @@ class Traficar
|
|||||||
{
|
{
|
||||||
|
|
||||||
private $homeCoords = ['lat' => 54.417475, 'lng' => 18.481913];
|
private $homeCoords = ['lat' => 54.417475, 'lng' => 18.481913];
|
||||||
private $staticMapsKey = 'AIzaSyBPb9wXT2BcK8EH_3FFWVc2MLuDprj7YXw';
|
|
||||||
|
//dystans w kilometrach w którym auta brane są pod uwagę
|
||||||
|
const CLOSEST_DISTANCE = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $lat1
|
* @param $lat1
|
||||||
@@ -34,7 +36,29 @@ class Traficar
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function nearestCar()
|
/**
|
||||||
|
* pobiera informacje o najbliższym trafficarze względem punktu podanego jako domowy i zwraca Sformatowane
|
||||||
|
* informacje na jego temat lub jesli nie ma auta to podaje informację że nie ma dostępnego.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function nearestCarText()
|
||||||
|
{
|
||||||
|
$info = $this->nearestCarInfo();
|
||||||
|
$formatedInfo = 'Brak aut w promieniu ' . self::CLOSEST_DISTANCE . 'km od domu.';
|
||||||
|
if ($info['car'] != []) {
|
||||||
|
$formatedInfo = "Najbliższy traficar:\n" .
|
||||||
|
'Model: ' . $info['car']['model'] . "\n" .
|
||||||
|
'Numer boczny: ' . $info['car']['orderNumber'] . "\n" .
|
||||||
|
'Rejestracja: ' . $info['car']['regNumber'] . "\n" .
|
||||||
|
'Lokalizacja: ' . $info['car']['location'] . "\n" .
|
||||||
|
'Odległość: ' . $info['distance'] . "km\n";
|
||||||
|
}
|
||||||
|
return $formatedInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function nearestCarInfo()
|
||||||
{
|
{
|
||||||
$trafcarData = json_decode(file_get_contents('https://api.traficar.pl/eaw-rest-api/car?shapeId=5'), 1);
|
$trafcarData = json_decode(file_get_contents('https://api.traficar.pl/eaw-rest-api/car?shapeId=5'), 1);
|
||||||
$closestCar = [];
|
$closestCar = [];
|
||||||
@@ -42,19 +66,11 @@ class Traficar
|
|||||||
foreach ($trafcarData['cars'] as $car) {
|
foreach ($trafcarData['cars'] as $car) {
|
||||||
|
|
||||||
$distance = $this->distance($this->homeCoords['lat'], $this->homeCoords['lng'], $car['latitude'], $car['longitude']);
|
$distance = $this->distance($this->homeCoords['lat'], $this->homeCoords['lng'], $car['latitude'], $car['longitude']);
|
||||||
if ($distance < $closestDistance) {
|
if ($distance < self::CLOSEST_DISTANCE && $distance < $closestDistance) {
|
||||||
$closestDistance = $distance;
|
$closestDistance = $distance;
|
||||||
$closestCar = $car;
|
$closestCar = $car;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// $imgNoKey = "https://maps.googleapis.com/maps/api/staticmap?center=" . $latHome . "," . $lngHome . "&size=300x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0x000000%7C" . $closestCar['latitude'] . "," . $closestCar['longitude'];
|
|
||||||
// $img = "https://maps.googleapis.com/maps/api/staticmap?center=" . $this->homeCoords['lat'] . "," . $this->homeCoords['lng'] . "&size=300x300&maptype=roadmap&format=png&visual_refresh=true&markers=size:mid%7Ccolor:0x000000%7C" . $closestCar['latitude'] . "," . $closestCar['longitude'] . '&key=' . $this->staticMapsKey;
|
|
||||||
// $tmpFile = storage_path() . '/traficar_map.png';
|
|
||||||
// file_put_contents($tmpFile, file_get_contents($img));
|
|
||||||
|
|
||||||
|
|
||||||
return ['car' => $closestCar, 'distance' => round($closestDistance, 2),];
|
return ['car' => $closestCar, 'distance' => round($closestDistance, 2),];
|
||||||
// 'imageName' => $tmpFile];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user