-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #649 from OpenLitterMap/staging
merge master into staging
- Loading branch information
Showing
747 changed files
with
281,904 additions
and
35,621 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
APP_NAME=OpenLitterMap | ||
APP_ENV=testing | ||
APP_KEY=base64:wtfMWBVJMehE9KRxZqwTmY+G0vPoCoPOwtloNZmueLM= | ||
APP_DEBUG=true | ||
APP_URL=http://olm.test | ||
APP_ROOT_DIR=/home/vagrant/Code/olm | ||
|
||
LOG_CHANNEL=stack | ||
|
||
DB_CONNECTION=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=olm | ||
DB_USERNAME=homestead | ||
DB_PASSWORD=secret | ||
|
||
# For Testing | ||
DB_FOREIGN_KEYS=false | ||
|
||
REDIS_HOST=127.0.0.1 | ||
REDIS_PASSWORD=null | ||
REDIS_PORT=6379 | ||
|
||
LOCATE_API_KEY= | ||
|
||
MIX_GOOGLE_RECAPTCHA_KEY= | ||
MIX_GOOGLE_RECAPTCHA_SECRET= | ||
|
||
BROADCAST_DRIVER=pusher | ||
CACHE_DRIVER=file | ||
SESSION_DRIVER=file | ||
QUEUE_DRIVER=redis | ||
QUEUE_CONNECTION=redis | ||
|
||
MAIL_DRIVER=smtp | ||
MAILGUN_DOMAIN= | ||
MAILGUN_SECRET= | ||
MAIL_HOST=smtp.mailgun.org | ||
MAIL_PORT=587 | ||
MAIL_USERNAME= | ||
MAIL_PASSWORD= | ||
MAIL_ENCRYPTION=tls | ||
|
||
STRIPE_KEY= | ||
STRIPE_SECRET= | ||
STRIPE_MODEL=App\User | ||
MIX_STRIPE_KEY= | ||
MIX_STRIPE_PUBLIC_KEY= | ||
|
||
CASHIER_MODEL=App\User | ||
CASHIER_CURRENCY=eur | ||
|
||
AWS_KEY=homestead | ||
AWS_SECRET=secretkey | ||
AWS_BUCKET=olm-public | ||
AWS_REGION=us-east-1 | ||
AWS_ENDPOINT=http://192.168.56.4:9600 | ||
|
||
x500_AWS_KEY=homestead | ||
x500_AWS_SECRET=secretkey | ||
x500_AWS_REGION=us-east-1 | ||
x500_AWS_BUCKET=olm-public-bbox | ||
x500_AWS_ENDPOINT=http://192.168.56.4:9600 | ||
|
||
PUSHER_APP_ID= | ||
PUSHER_APP_KEY= | ||
PUSHER_APP_SECRET= | ||
PUSHER_APP_CLUSTER=eu | ||
LARAVEL_WEBSOCKETS_PORT=6002 | ||
|
||
WEBSOCKET_BROADCAST_HOST=192.168.56.4 | ||
|
||
LOCATION_API_KEY= | ||
|
||
BACKUP_NAME=OpenLitterMap_Backup | ||
BACKUP_ARCHIVE_PASSWORD= | ||
DROPBOX_TOKEN= | ||
|
||
SLACK_WEBHOOK_URL= | ||
|
||
ROOT_KEY= | ||
OWNER_PKH= | ||
|
||
# consumer keys | ||
TWITTER_API_CONSUMER_KEY= | ||
TWITTER_API_CONSUMER_SECRET= | ||
|
||
# tokens | ||
TWITTER_API_BEARER_TOKEN= | ||
|
||
# access token + secret | ||
TWITTER_API_ACCESS_TOKEN= | ||
TWITTER_API_ACCESS_SECRET= | ||
|
||
# new | ||
TWITTER_API_CLIENT_ID= | ||
TWITTER_API_CLIENT_SECRET= | ||
|
||
ENTROPY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/storage/*.key | ||
/vendor | ||
.env | ||
.env.testing | ||
.env.backup | ||
.phpunit.result.cache | ||
Homestead.json | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands\Photos; | ||
|
||
use App\Models\Photo; | ||
use App\Models\User\User; | ||
use App\Models\Location\City; | ||
use App\Models\Location\State; | ||
use App\Models\Location\Country; | ||
use Illuminate\Console\Command; | ||
use Illuminate\Support\Facades\File; | ||
use App\Actions\Photos\AddTagsToPhotoAction; | ||
use Illuminate\Support\Facades\Redis; | ||
|
||
class GenerateData extends Command | ||
{ | ||
protected $signature = 'olm:generate-data {photos=1500}'; | ||
|
||
protected $description = 'Generates data in Cork, Ireland. Default = 1500 photos'; | ||
|
||
private AddTagsToPhotoAction $addTagsToPhotoAction; | ||
|
||
public function __construct (AddTagsToPhotoAction $addTagsToPhotoAction) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->addTagsToPhotoAction = $addTagsToPhotoAction; | ||
} | ||
|
||
public function handle (): void | ||
{ | ||
$userId = User::first()->id; | ||
|
||
$country = Country::firstOrCreate([ | ||
'country' => 'Ireland', | ||
'shortcode' => 'ie', | ||
'created_by' => $userId, | ||
]); | ||
|
||
State::firstOrCreate([ | ||
'state' => 'County Cork', | ||
'country_id' => $country->id, | ||
'created_by' => $userId | ||
]); | ||
|
||
$city = City::firstOrCreate([ | ||
'city' => 'Cork', | ||
'country_id' => $country->id, | ||
'created_by' => $userId | ||
]); | ||
|
||
$photosToGen = $this->argument('photos'); | ||
|
||
$this->generatePhotos($photosToGen, $country, $city); | ||
} | ||
|
||
protected function generatePhotos ($photosToGen, $country, $city): array | ||
{ | ||
$this->line('Generating photos...'); | ||
|
||
$bar = $this->output->createProgressBar($photosToGen); | ||
$bar->setFormat('debug'); | ||
$bar->start(); | ||
|
||
$photos = []; | ||
$litterJson = $this->getLitterJson(); | ||
$categories = ['smoking', 'food', 'coffee', 'alcohol', 'softdrinks', 'sanitary', 'other', 'brands']; | ||
|
||
// Get max 10 users | ||
$users = User::inRandomOrder()->limit(10)->get(); | ||
|
||
for ($i = 0; $i < $photosToGen; $i++) | ||
{ | ||
$lat = rand(51.85391800 * 100000000, 51.92249800 * 100000000) / 100000000; | ||
$lon = rand(-8.53209200 * 100000000, -8.36823900 * 100000000) / 100000000; | ||
|
||
$tags = []; | ||
|
||
foreach ($categories as $category) | ||
{ | ||
if (isset($litterJson[$category])) | ||
{ | ||
$litterTypes = array_keys($litterJson[$category]); | ||
|
||
// Ensure that we only select as many items as are available | ||
$availableItems = count($litterTypes); | ||
$numberToSelect = min(rand(1, 5), $availableItems); | ||
|
||
// Select 1-5 random types of litter from the category | ||
$selectedLitter = collect($litterTypes)->random($numberToSelect); | ||
|
||
// Populate tags array with randomly selected litter types and quantities | ||
foreach ($selectedLitter as $litterKey) { | ||
$tags[$category][$litterKey] = rand(1, 5); | ||
} | ||
} | ||
} | ||
|
||
// Pick 1 random user | ||
$user = $users->random(); | ||
|
||
$createdAt = now()->subWeek()->startOfWeek()->addHour(); | ||
|
||
$photo = Photo::create([ | ||
'user_id' => $user->id, | ||
'country_id' => $country->id, | ||
'city_id' => $city->id, | ||
'lat' => $lat, | ||
'lon' => $lon, | ||
'model' => "iPhone 5", | ||
'filename' => "dummy.png", | ||
'datetime' => $createdAt, | ||
'verified' => 2, | ||
'verification' => 1, | ||
'remaining' => 1, | ||
'geohash' => \GeoHash::encode($lat, $lon), | ||
'created_at' => $createdAt, | ||
'updated_at' => $createdAt, | ||
]); | ||
|
||
$litterTotals = $this->addTagsToPhotoAction->run($photo, $tags); | ||
|
||
$year = $createdAt->year; | ||
$month = $createdAt->month; | ||
$day = $createdAt->day; | ||
$key = "leaderboard:users:$year:$month:$day"; | ||
Redis::zadd($key, $litterTotals['all'], $user->id); | ||
|
||
$photo->save(); | ||
|
||
$bar->advance(); | ||
} | ||
|
||
$bar->finish(); | ||
|
||
return $photos; | ||
} | ||
|
||
protected function getLitterJson (): array | ||
{ | ||
$path = resource_path('js/langs/en/litter.json'); | ||
|
||
$contents = File::get($path); | ||
|
||
return json_decode($contents, true); | ||
} | ||
} |
Oops, something went wrong.