diff --git a/laravel_app/app/Http/Controllers/ProjectController.php b/laravel_app/app/Http/Controllers/ProjectController.php
index 33b56d8..874ac06 100644
--- a/laravel_app/app/Http/Controllers/ProjectController.php
+++ b/laravel_app/app/Http/Controllers/ProjectController.php
@@ -15,7 +15,7 @@ public function index()
public function show(string $projectName,?string $currentTab = null)
{
if($project = Project::firstWhere([['name',$projectName]])) {
- $availableTabs = ['downloads', 'mosaics', 'reports', 'mailings', 'settings'];
+ $availableTabs = ['downloads', 'mosaics', 'reports', 'mailings', 'settings', 'exports'];
return in_array($currentTab, $availableTabs) ? view('projects.show', compact(['project', 'currentTab'])) : redirect(route('project.show', [$projectName,'downloads']));
}
return abort(404);
diff --git a/laravel_app/app/Jobs/ProjectInterpolateGrowthModelJob.php b/laravel_app/app/Jobs/ProjectInterpolateGrowthModelJob.php
index a9bb916..153aa1c 100644
--- a/laravel_app/app/Jobs/ProjectInterpolateGrowthModelJob.php
+++ b/laravel_app/app/Jobs/ProjectInterpolateGrowthModelJob.php
@@ -16,9 +16,8 @@
class ProjectInterpolateGrowthModelJob implements ShouldQueue
{
use Batchable, Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
protected Project $project;
- protected Carbon $date;
- protected int $offset;
public function __construct(Project $project)
{
diff --git a/laravel_app/app/Jobs/newDownloadsUploaded.php b/laravel_app/app/Jobs/newDownloadsUploaded.php
new file mode 100644
index 0000000..ced2e88
--- /dev/null
+++ b/laravel_app/app/Jobs/newDownloadsUploaded.php
@@ -0,0 +1,32 @@
+project = $project;
+ }
+
+ /**
+ * Execute the job.
+ */
+ public function handle(): void
+ {
+ $this->project->newDownloadsUploaded();
+ }
+}
diff --git a/laravel_app/app/Livewire/Projects/Tabs/Exports.php b/laravel_app/app/Livewire/Projects/Tabs/Exports.php
new file mode 100644
index 0000000..9069f3e
--- /dev/null
+++ b/laravel_app/app/Livewire/Projects/Tabs/Exports.php
@@ -0,0 +1,56 @@
+formData = [
+ 'start_date' => now()->subDays(6)->format('Y-m-d'),
+ 'end_date' => now()->subDay()->format('Y-m-d'),
+ ];
+ }
+
+
+
+ public function render()
+ {
+ return view('livewire.projects.tabs.exports');
+ }
+
+ public function downloadRds()
+ {
+ return $this->project->getRdsAsDownload();
+ }
+
+ public function downloadTifs()
+ {
+ $startDate = \Carbon\Carbon::parse($this->formData['start_date']);
+ $endDate = \Carbon\Carbon::parse($this->formData['end_date']);
+ $this->showDownloadTifsModal = false;
+ return $this->project->getTifsAsZip(
+ $startDate, $endDate
+ );
+ }
+
+ public function downloadMosaics()
+ {
+ $startDate = \Carbon\Carbon::parse($this->formData['start_date']);
+ $endDate = \Carbon\Carbon::parse($this->formData['end_date']);
+ $this->showDownloadMosaicsModal = false;
+ return $this->project->getMosaicsAsZip(
+ $startDate, $endDate
+ );
+ }
+}
diff --git a/laravel_app/app/Models/Project.php b/laravel_app/app/Models/Project.php
index f2d04af..def188c 100644
--- a/laravel_app/app/Models/Project.php
+++ b/laravel_app/app/Models/Project.php
@@ -2,6 +2,7 @@
namespace App\Models;
+use App\Jobs\ProjectDownloadRDSJob;
use App\Jobs\ProjectDownloadTiffJob;
use App\Jobs\ProjectInterpolateGrowthModelJob;
use App\Jobs\ProjectMosiacGeneratorJob;
@@ -348,7 +349,7 @@ public function getFileDownloadsFor(Carbon $endDate, int $offset = 7): array
public function getMosaicsFor(Carbon $endDate, int $offset = 7): array
{
return collect(range(0, 3))
- ->map(function() use ($endDate, $offset){
+ ->map(function () use ($endDate, $offset) {
$currentEndDate = $endDate->clone();
if (!$currentEndDate->isDayOfWeek($this->mail_day)) {
$endDate->previous($this->mail_day);
@@ -402,4 +403,101 @@ private function getMinimumDateFromHarvestExcelFile(): Carbon
return min($carry, Carbon::instance(SharedDate::excelToDateTimeObject($value[$season_start_index])));
}, now());
}
+
+ public function newDownloadsUploaded()
+ {
+// $this->createDownloadRecordsInDatabaseAndUpdateStatusForAllDownloadedImages();
+ $date = Carbon::parse('2023-01-01');
+ $now = Carbon::now();
+
+ $offset = (int) $date->diffInDays($now);
+// dispatch_sync(new ProjectDownloadRDSJob($this, Carbon::yesterday(), 1));
+ dispatch_sync(new ProjectInterpolateGrowthModelJob($this));
+ }
+ public function getRdsAsDownload() {
+
+ $path = $this->download_path.'/Data/extracted_ci/cumulative_vals/combined_CI_data.rds';
+
+ return Storage::download(
+ $path, 'combined_CI_data.rds'
+ );
+ }
+
+ public function getTifsAsZip(Carbon $startDate, Carbon $endDate) {
+ $path = $this->download_path.'/merged_final_tif';
+ $files = collect(Storage::files($path))
+ ->filter(fn($file) => Str::endsWith($file, '.tif'))
+ ->filter(function ($file) use ($startDate, $endDate) {
+ $dateString = str_replace('.tif', '', basename($file));
+ $date = Carbon::parse($dateString);
+ return $date->between($startDate, $endDate);
+ });
+
+ return $this->createZipArchiveAndReturn($files);
+ }
+
+ public function getMosaicsAsZip(Carbon $startDate, Carbon $endDate) {
+ $path = $this->download_path.'/weekly_mosaic';
+
+ // create a collection of all week numbers and years for given date range
+ $allowedFiles = collect(CarbonPeriod::create($startDate, $endDate)->toArray())
+ ->map(fn($date) => sprintf('week_%s_%s.tif',$date->weekOfYear, $date->year))
+ ->unique();
+
+
+ $files = collect(Storage::files($path))
+ ->filter(fn($file) => Str::endsWith($file, '.tif'))
+ ->filter(function ($file) use ($allowedFiles) {
+ return $allowedFiles->contains(basename($file));
+ });
+ putenv('TMPDIR='.storage_path('app'));
+
+ return $this->createZipArchiveAndReturn($files);
+ }
+
+ private function createZipArchiveAndReturn(Collection $files)
+ {
+ $zipPath = storage_path('app/'.$this->download_path.'/download.zip');
+ $zip = new \ZipArchive();
+ $zip->open($zipPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
+ $files->each(function ($file) use ($zip) {
+ $zip->addFile(storage_path('app/'.$file), basename($file));
+ });
+ $zip->close();
+
+ return response()->download(
+ $zipPath, 'download.zip'
+ );
+ }
+
+ public function createDownloadRecordsInDatabaseAndUpdateStatusForAllDownloadedImages(): void
+ {
+ $merged_tiffs = $this->getMergedTiffList();
+ $this->downloads->each(function ($download) use ($merged_tiffs) {
+ if ($merged_tiffs->contains($download->path) && $download->status !== 'success') {
+ $download->setStatusSuccess();
+ }
+ });
+
+ $merged_tiffs->each(function ($path) {
+ if ($this->downloads()->where('path', $path)->count() === 0) {
+ $this->downloads()->create([
+ 'path' => $path,
+ 'status' => 'success',
+ 'name' => explode('/', $path)[count(explode('/', $path)) - 1]
+ ]);
+ }
+ });
+ }
+
+ public function createAllMosaicsInDatabaseAndUpdateStatusForAllDownloadedImages()
+ {
+ $list_of_desired_mosaics = $this->getMergedTiffList()
+ ->map(fn($file) => str_replace('.tif', '', basename($file) ))
+ ->map(function($date) {
+ $carbon = Carbon::parse($date);
+ return sprintf('week_%s_%s', $carbon->format('W'), $carbon->year);
+ })
+ ->unique();
+ }
}
diff --git a/laravel_app/public/Sonydownload.zip b/laravel_app/public/Sonydownload.zip
new file mode 100644
index 0000000..d4c8f23
Binary files /dev/null and b/laravel_app/public/Sonydownload.zip differ
diff --git a/laravel_app/resources/views/components/download-mosaics-as-zip-modal.blade.php b/laravel_app/resources/views/components/download-mosaics-as-zip-modal.blade.php
new file mode 100644
index 0000000..79b5809
--- /dev/null
+++ b/laravel_app/resources/views/components/download-mosaics-as-zip-modal.blade.php
@@ -0,0 +1,47 @@
+@props([
+ 'formData',
+])
+
+