Seeds with bugs

master
Goncalo Bras 2017-04-13 09:55:40 +01:00
parent 08feb31d54
commit df1c491a97
12 changed files with 327 additions and 72 deletions

View File

@ -26,7 +26,7 @@ class LandingController extends BaseController
private $apiKey = 'AIzaSyDsZDCiU1k6mSuywRRL88xxXY-81RMEU7s';
private $allStations = array();
private $fiveClosestStations = array();
private $districts = ['Aveiro', 'Beja', 'Braga', 'Bragança', 'Castelo Branco', 'Coimbra', 'Évora', 'Faro', 'Guarda', 'Leiria', 'Lisboa', 'Portalegre', 'Porto', 'Santarém', 'Setúbal', 'Viana do Castelo', 'Vila Real', 'Viseu'];
/**
* Show a list of all of the application's districts.
*
@ -58,6 +58,7 @@ class LandingController extends BaseController
#$this->searchStations($coordinates["latitude"], $coordinates["longitude"]);
}
$this->fetchStationData();
return View('landing_page', ['districts' => $districts]);
@ -114,10 +115,14 @@ class LandingController extends BaseController
$newArray = explode(",", $string);
print_r($newArray);*/
$lines = explode("\n", $stationsInCSV[$i]);
#print_r($stationsInCSV[0]);
$lines = explode(";", $stationsInCSV[$i]);
#$lines = explode("\n", $stationsInCSV[$i]);
$array = array();
foreach ($lines as $line) {
#$data = array_map("str_getcsv", preg_split('/\r\n+|\n+/', $line));
#print_r($data);
$array = str_getcsv($line, ",", "\n");
#print_r( $array);
@ -130,23 +135,78 @@ class LandingController extends BaseController
}
/*foreach($this->allStations as $key=>$value){
echo $key;
}*/
#print_r($this->allStations);
}
}
private function searchStations($latitudeOrigin, $longitudeOrigin, $radius=5)
{
//para todos os postos calcular se a distancia é igual ou menor ao raio
//se for guardar verificar se é menor que a que esta no array
//se for menor que a que esta no array guardar
foreach ($this->allStations as $value) {
/*$tempStationsArray = $this->allStations;
foreach ($tempStationsArray as $key => $value) {
$tempStationsArray[$key]["distance"] = $this->calculateDistance($latitudeOrigin, $longitudeOrigin, $value["latitude"], $value["longitude"]);
}*/
/*foreach ($this->allStations as $key => $value) {
#echo $value['latitude'].$value['longitude'];
$latitudeDestination = $value['latitude'];
$longitudeDestination = $value['longitude'];
//$this->allStations[$key]["distance"] = $this->calculateDistance($latitudeOrigin, $longitudeOrigin, $latitudeDestination, $longitudeDestination);
/*if ($stationDistance <= $radius) {
echo "menor que o raio";
if (count($this->fiveClosestStations)<5) {
echo "menor que 5";
array_push($this->fiveClosestStations, $value);
//var_dump($this->fiveClosestStations);
} else {
echo "maior que zero";
foreach ($this->fiveClosestStations as $val) {
//var_dump($val);
if ($this->calculateDistance($latitudeOrigin, $longitudeOrigin, $val['latitude'], $val['longitude'])<=$val){
//array_splice($this->fiveClosestStations, $key, $key, $value);
}
//$distance = $this->calculateDistance($latitudeOrigin, $longitudeOrigin, $val['latitude'], $val['longitude']);
}
}
}else {
echo "maior que o raio";
}*/
#echo "distance: ".$distance;
#print_r($value);
}
//}*/
/*$tempAllStations = $this->allStations;
asort($tempAllStations);
var_dump($tempAllStations);*/
//var_dump($this->allStations);
/*foreach ($this->fiveClosestStations as $k) {
echo "$k ";
}*/
}
private function calculateDistance($latitudeOrigin, $longitudeOrigin, $latitudeDestination, $longitudeDestination)
{
$earthRadius = 6.371;//km
$latitudeDifference = $latitudeOrigin-$latitudeDestination;
$longitudeDifference = $longitudeOrigin-$longitudeDestination;
$a = pow(sin($latitudeDifference/2),2) + cos($latitudeOrigin) * cos($latitudeDestination) * pow(sin($longitudeDifference/2), 2);
$c = 2 * $a * pow(tan(sqrt($a)*sqrt(1-$a)) ,2);
return $earthRadius * $c;
}
private function askLocation()
@ -178,6 +238,10 @@ function showPosition(position) {
#echo "$location";
}
/*
* PARA APAGAR
*/
public function fetchData()
{
$client = new Client(); //GuzzleHttp\Client
@ -235,7 +299,7 @@ function showPosition(position) {
{
$stationData = str_replace(";","\n",$stationData); #substitui o ; por paragrafo
$stationData = preg_replace("/'/", "", $stationData);
$stationData = preg_replace("/fAD[0-9][0-9]\(/","",$stationData); #remove as funcoes javascript
$stationData = str_replace("function","",$stationData); #remove as funcoes javascript
$stationData = str_replace("{","",$stationData); #remove as funcoes javascript
@ -251,23 +315,28 @@ function showPosition(position) {
{
#$link = "http://www.precoscombustiveis.dgeg.pt/wwwbase/raiz/mlkListagemCallback_v11.aspx?linha=$stationId&fi=7745&geradorid=5372&nivel=2&codigoms=0&codigono=62796281AAAAAAAAAAAAAAAA";
#$link = "http://www.precoscombustiveis.dgeg.pt/wwwbase/raiz/mlkListagemCallback_v11.aspx?linha=$stationId&fi=7745&geradorid=5372&nivel=2&codigoms=0&codigono=62796281AAAAAAAAAAAAAAAA";
#$link = "http://www.precoscombustiveis.dgeg.pt/wwwbase/raiz/mlkListagemCallback_v11.aspx?linha=$stationId&fi=7745&geradorid=5372&nivel=2&codigoms=0&codigono=62796281AAAAAAAAAAAAAAAA";
#$link = "http://www.precoscombustiveis.dgeg.pt/wwwbase/raiz/mlkListagemCallback_v11.aspx?linha=181911&fi=7745&geradorid=5372&nivel=2&codigoms=0&codigono=62796281AAAAAAAAAAAAAAAA";
foreach ($this->fetchStationID() as $value) {
/*foreach ($this->fetchStationID() as $value) {
# code...
# sleep(20);
$link = 'http://www.precoscombustiveis.dgeg.pt/wwwbase/raiz/mlkListagemCallback_v11.aspx?linha='.$value.'&fi=7745&geradorid=5372&nivel=2&codigoms=0&codigono=62796281AAAAAAAAAAAAAAAA';
$guzzle = new GuzzleHttp\Client();
$request = $guzzle->request('GET', $link);
$crawler = new Crawler((string) $request->getBody());
$result = $crawler->filter('div .esq ')->count();
$result = $crawler->filter('div .esq ')->text();
echo $result;
sleep(20);
}
}*/
}
public function receiveGPSCoordinates()
@ -329,8 +398,10 @@ $uniqueMatch1 = array();
}
$matches = array_unique($uniqueMatch1);
return $matches;
#print_r($uniqueMatch1);
#return $matches;
asort($matches);
print_r($matches);
}
}

View File

@ -7,6 +7,7 @@
"require": {
"php": ">=5.6.4",
"fabpot/goutte": "^3.2",
"fzaninotto/faker": "^1.6",
"guzzlehttp/guzzle": "^6.2",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
@ -14,7 +15,6 @@
"twbs/bootstrap": "^3.3"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7"
},

98
laravel/composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "ff5fc056f08dc361457f0f06d782f298",
"content-hash": "2237e12427c578412ee40caf2ac3a27a",
"packages": [
{
"name": "dnoegel/php-xdg-base-dir",
@ -197,6 +197,54 @@
],
"time": "2017-01-03T13:21:43+00:00"
},
{
"name": "fzaninotto/faker",
"version": "v1.6.0",
"source": {
"type": "git",
"url": "https://github.com/fzaninotto/Faker.git",
"reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/44f9a286a04b80c76a4e5fb7aad8bb539b920123",
"reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123",
"shasum": ""
},
"require": {
"php": "^5.3.3|^7.0"
},
"require-dev": {
"ext-intl": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~1.5"
},
"type": "library",
"extra": {
"branch-alias": []
},
"autoload": {
"psr-4": {
"Faker\\": "src/Faker/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "François Zaninotto"
}
],
"description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
"data",
"faker",
"fixtures"
],
"time": "2016-04-29T12:21:54+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.2.3",
@ -2413,54 +2461,6 @@
],
"time": "2015-06-14T21:17:01+00:00"
},
{
"name": "fzaninotto/faker",
"version": "v1.6.0",
"source": {
"type": "git",
"url": "https://github.com/fzaninotto/Faker.git",
"reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/44f9a286a04b80c76a4e5fb7aad8bb539b920123",
"reference": "44f9a286a04b80c76a4e5fb7aad8bb539b920123",
"shasum": ""
},
"require": {
"php": "^5.3.3|^7.0"
},
"require-dev": {
"ext-intl": "*",
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~1.5"
},
"type": "library",
"extra": {
"branch-alias": []
},
"autoload": {
"psr-4": {
"Faker\\": "src/Faker/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "François Zaninotto"
}
],
"description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
"data",
"faker",
"fixtures"
],
"time": "2016-04-29T12:21:54+00:00"
},
{
"name": "hamcrest/hamcrest-php",
"version": "v1.2.2",

View File

@ -46,8 +46,8 @@ return [
'database' => env('DB_DATABASE', 'geocomb'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,

View File

@ -16,7 +16,6 @@ class CreateDistrictTable extends Migration
Schema::create('District', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('station');
});
}

View File

@ -18,6 +18,7 @@ class CreateStationTable extends Migration
$table->string('name');
$table->string('brand');
$table->integer('location');
$table->integer('district');
$table->integer('fuel_price');
$table->integer('services');
$table->date('last_update');

View File

@ -12,6 +12,10 @@ class DistrictTableSeeder extends Seeder
*/
public function run()
{
$data = array(['name' => 'Aveiro'],['name' => 'Beja'],['name' => 'Braga'],['name' => 'Bragança'],['name' => 'Castelo Branco'],['name' => 'Coimbra'],['name' => 'Évora'],['name' => 'Faro'],['name' => 'Guarda'],['name' => 'Leiria'],['name' => 'Lisboa'],['name' => 'Portalegre'],['name' => 'Porto'],['name' => 'Santarém'],['name' => 'Setúbal'],['name' => 'Viana do Castelo' ],['name' => 'Vila Real'],['name' => 'Viseu']);
DB::table('District')->insert($data);
/*
$data = array([
'name' => 'Leiria',
'station' => 1
@ -26,6 +30,6 @@ class DistrictTableSeeder extends Seeder
'station' => 4
]);
DB::table('District')->insert($data);
DB::table('District')->insert($data);*/
}
}

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Seeder;
class FuelpriceTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i = 0; $i < 10; $i++) {
for($j=0;$j<13;$j++){
$pricesArray[$j] = $this->randomPrice(1.12, 1.60);
}
DB::table('Fuel_price')->insert([ //,
'diesel' => $pricesArray[0],
'diesel_colored' => $pricesArray[1],
'diesel_special' => $pricesArray[2],
'diesel_simple' => $pricesArray[3],
'petrol_95' => $pricesArray[4],
'petrol_98' => $pricesArray[5],
'petrol_special_95' => $pricesArray[6],
'petrol_special_98' => $pricesArray[7],
'petrol_simple_95' => $pricesArray[8],
'gas_natural_compressed_kg' => $pricesArray[9],
'gas_natural_compressed_m3' => $pricesArray[10],
'gas_natural_liquefied' => $pricesArray[11],
'gpl' => $pricesArray[12]
]);
}
}
private function randomPrice ($min,$max) {
return ($min + lcg_value()*(abs($max - $min)));
}
}

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Seeder;
class LocalizationTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
$minLatitude = 36.844;
$maxLatitude = 42.196;
$minLongitude = -9.756;
$maxLongitude = -6.021;
for ($i = 0; $i < 10; $i++) {
DB::table('Localization')->insert([ //,
'latitude' => $this->randomCoordinate($minLatitude, $maxLatitude),
'longitude' => $this->randomCoordinate($minLongitude, $maxLongitude)
]);
}
}
private function randomCoordinate ($min,$max) {
return ($min + lcg_value()*(abs($max - $min)));
}
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Seeder;
class ScheduleTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i = 0; $i < 10; $i++) {
DB::table('Schedule')->insert([ //,
'week_opening' => "8:00",
'week_closing' => "23:00",
'saturday_opening' => "8:00",
'saturday_closing' => "23:00",
'sunday_opening' => "8:00",
'sunday_closing' => "23:00"
]);
}
}
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Seeder;
class ServicesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i = 0; $i < 10; $i++) {
for ($j=0; $j < 5; $j++) {
$booleanArray[$j] = $this->generateRandomBoolean();
}
DB::table('Services')->insert([
'atm' => $booleanArray[0],
'wc' => $booleanArray[1],
'carwash' => $booleanArray[2],
'shop' => $booleanArray[3],
'disabled_person' => $booleanArray[4]
]);
}
}
private generateRandomBoolean()
{
rand(0,1) == 1? return true: return false;
}
}

View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Seeder;
class StationTableSeeder extends Seeder
{
$min = 1;
$max = 10;
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
for ($i = 0; $i < 10; $i++) {
for ($j=0; $j < 5; $j++) {
$location = $this->generateRandomNumber(1,10);
$district = $this->generateRandomNumber(1,18);
$fuel_price = $this->generateRandomNumber(1,10);
$services = $this->generateRandomNumber(1,10);
$schedule = $this->generateRandomNumber(1,10);
}
DB::table('Station')->insert([
'name' => "a$i",
'brand' => "galp",
'location' => $location,
'district' => $district,
'fuel_price' => $fuel_price,
'services' => $services,
'last_update' => "12/04/2017 19:00",
'schedule' => $schedule
]);
}
}
private function generateRandomNumber($min, $max)
{
return ($min + lcg_value()*(abs($max - $min)));
}
}