Skip to content

Commit

Permalink
Merge branch 'staging' into feat/TM-criteria-by-multiple
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Dec 31, 2024
2 parents 27c56ac + 9556ead commit 2c2c235
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunActiveCountriesTableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function handle(RunActiveCountriesTableService $runActiveCountriesTableSe

Redis::set('dashboard:active-countries-table|' . $this->cacheParameter, json_encode([
'data' => $response,
]));
]), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunActiveProjectsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunActiveProjectsService $runActiveProjectsService)
]
);
$response = $runActiveProjectsService->runActiveProjectsJob($request);
Redis::set('dashboard:active-projects|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:active-projects|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunHectaresRestoredJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunHectaresRestoredService $runHectaresRestoredService)
]
);
$response = $runHectaresRestoredService->runHectaresRestoredJob($request);
Redis::set('dashboard:indicator/hectares-restoration' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:indicator/hectares-restoration' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunJobsCreatedJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(JobsCreatedService $jobsCreatedService)
]);

$response = $jobsCreatedService->calculateJobsCreated($request);
Redis::set('dashboard:jobs-created|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:jobs-created|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunTopTreesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunTopTreesService $runTopTreesService)
]
);
$response = $runTopTreesService->runTopTreesJob($request);
Redis::set('dashboard:top-trees-planted|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:top-trees-planted|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunTotalHeaderJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunTotalHeaderService $runTotalHeaderService)
]
);
$response = $runTotalHeaderService->runTotalHeaderJob($request);
Redis::set('dashboard:total-section-header|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:total-section-header|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunTreeRestorationGoalJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(TreeRestorationGoalService $treeRestorationGoalService)
]);

$response = $treeRestorationGoalService->calculateTreeRestorationGoal($request);
Redis::set('dashboard:tree-restoration-goal|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:tree-restoration-goal|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));

$delayedJob->update([
'status' => DelayedJob::STATUS_SUCCEEDED,
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Dashboard/RunVolunteersAverageJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function handle(RunVolunteersAverageService $runVolunteersAverageService)
]
);
$response = $runVolunteersAverageService->runVolunteersAverageJob($request);
Redis::set('dashboard:volunteers-survival-rate|' . $this->cacheParameter, json_encode($response));
Redis::set('dashboard:volunteers-survival-rate|' . $this->cacheParameter, json_encode($response), 'EX', config('cache.ttl.dashboard'));


$delayedJob->update([
Expand Down
18 changes: 17 additions & 1 deletion app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,22 @@ public function sitePolygons(): HasManyThrough
)->active();
}

public function approvedSitePolygons(): HasManyThrough
{
return $this->hasManyThrough(
SitePolygon::class,
Site::class,
'project_id',
'site_id',
'id',
'uuid'
)
->whereHas('site', function ($query) {
$query->whereIn('status', Site::$approvedStatuses);
})
->active();
}

public function treeSpecies()
{
return $this->morphMany(TreeSpecies::class, 'speciesable');
Expand Down Expand Up @@ -615,6 +631,6 @@ public function getTotalSitePolygonsAttribute()

public function getTotalHectaresRestoredSumAttribute(): float
{
return round($this->sitePolygons->where('status', 'approved')->sum('calc_area'));
return $this->approvedSitePolygons->where('status', 'approved')->sum('calc_area');
}
}
11 changes: 6 additions & 5 deletions app/Validators/Extensions/Polygons/NotOverlapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@ public static function getIntersectionData(string $polygonUuid): array

$mainPolygonArea = PolygonGeometry::where('uuid', $polygonUuid)
->value(DB::raw('ST_Area(geom)'));

$extra_info = $intersects
->filter(fn ($intersect) => $intersect->intersects)
->map(function ($intersect) use ($mainPolygonArea) {
->filter(function ($intersect) {
return $intersect->intersects && $intersect->intersection_area > 1e-10;
})
->map(function ($intersect) use ($mainPolygonArea, $sitePolygon) {
$minArea = min($mainPolygonArea, $intersect->area);
$percentage = $minArea > 0
? round(($intersect->intersection_area / $minArea) * 100, 2)
: 100;
? round(($intersect->intersection_area / $minArea) * 100, 2)
: 100;

return [
'poly_uuid' => $intersect->uuid,
Expand Down
14 changes: 14 additions & 0 deletions config/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,18 @@

'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),

/*
|--------------------------------------------------------------------------
| Cache Timeout Values
|--------------------------------------------------------------------------
|
| Here you may define the cache timeout values for different sections
| of the application. These values can be used in any controllers
| to set the time-to-live (TTL) for cached items.
|
*/

'ttl' => [
'dashboard' => 86400, // 24 hours
]
];

0 comments on commit 2c2c235

Please sign in to comment.