MAPG-111 query map area from DB

modify calculations to be in square km (instead of m)
This commit is contained in:
bence committed 2020-06-12 21:55:04 +02:00
1 parent 4d7c86fd1b
commit 7159867db0
6 files changed
+27 -28

No files matched your search

+1 -1
View File
@@ -44,7 +44,7 @@ class GameController
if (!($state = $session->get('state')) || $state['mapId'] !== $mapId) {
$session->set('state', [
'mapId' => $mapId,
'area' => $bounds->calculateApproximateArea(),
'area' => $map['area'],
'rounds' => []
]);
}
+1 -1
View File
@@ -123,7 +123,7 @@ class GameFlowController
private function calculateScore(float $distance, float $area): int
{
$goodness = 1.0 - ($distance / sqrt($area));
$goodness = 1.0 - ($distance / (sqrt($area) * 1000));
return (int) round(pow(static::MAX_SCORE, $goodness));
}
+2 -1
View File
@@ -118,7 +118,8 @@ class MapAdminController implements ISecured
'bound_south_lat' => $mapBounds->getSouthLat(),
'bound_west_lng' => $mapBounds->getWestLng(),
'bound_north_lat' => $mapBounds->getNorthLat(),
'bound_east_lng' => $mapBounds->getEastLng()
'bound_east_lng' => $mapBounds->getEastLng(),
'area' => $mapBounds->calculateApproximateArea(),
];
if (isset($_POST['name'])) {
+18 -20
View File
@@ -6,7 +6,6 @@ use MapGuesser\Interfaces\Authentication\IUser;
use MapGuesser\Interfaces\Database\IResultSet;
use MapGuesser\Interfaces\Request\IRequest;
use MapGuesser\Interfaces\Response\IContent;
use MapGuesser\Util\Geo\Bounds;
use MapGuesser\Response\HtmlContent;
class MapsController
@@ -29,6 +28,7 @@ class MapsController
['maps', 'bound_west_lng'],
['maps', 'bound_north_lat'],
['maps', 'bound_east_lng'],
['maps', 'area'],
new RawExpression('COUNT(places.id) AS num_places')
]);
$select->leftJoin('places', ['places', 'map_id'], '=', ['maps', 'id']);
@@ -39,9 +39,7 @@ class MapsController
$maps = [];
while ($map = $result->fetch(IResultSet::FETCH_ASSOC)) {
$bounds = Bounds::createDirectly($map['bound_south_lat'], $map['bound_west_lng'], $map['bound_north_lat'], $map['bound_east_lng']);
$map['area'] = $this->formatMapAreaForHuman($bounds->calculateApproximateArea());
$map['area'] = $this->formatMapAreaForHuman($map['area']);
$maps[] = $map;
}
@@ -53,29 +51,29 @@ class MapsController
private function formatMapAreaForHuman(float $area): array
{
if ($area < 100.0) {
if ($area < 0.01) {
$digits = 0;
$rounded = round($area * 1000000.0, -2);
$unit = 'm';
} elseif ($area < 0.1) {
$digits = 0;
$rounded = round($area * 1000000.0, -3);
$unit = 'm';
} elseif ($area < 1.0) {
$digits = 2;
$rounded = round($area, 2);
$unit = 'km';
} elseif ($area < 100.0) {
$digits = 0;
$rounded = round($area, 0);
$unit = 'm';
} elseif ($area < 100000.0) {
$unit = 'km';
} elseif ($area < 10000.0) {
$digits = 0;
$rounded = round($area, -2);
$unit = 'm';
} elseif ($area < 1000000.0) {
$digits = 2;
$rounded = round($area / 1000000.0, 2);
$unit = 'km';
} elseif ($area < 100000000.0) {
$digits = 0;
$rounded = round($area / 1000000.0, 0);
$unit = 'km';
} elseif ($area < 10000000000.0) {
$digits = 0;
$rounded = round($area / 1000000.0, -2);
$unit = 'km';
} else {
$digits = 0;
$rounded = round($area / 1000000.0, -4);
$rounded = round($area, -4);
$unit = 'km';
}