From 33cb0dd7daac02f59d2a8c8cfff40b19940760ab Mon Sep 17 00:00:00 2001 From: Martin Folkerts Date: Wed, 24 Jan 2024 21:46:08 +0100 Subject: [PATCH] wip --- .idea/php.xml | 5 +++ build_mosaic.sh | 23 +++++------ build_report.sh | 38 ++++++------------- .../app/Jobs/ProjectDownloadTiffJob.php | 28 ++++---------- .../app/Jobs/ProjectMosiacGeneratorJob.php | 2 +- r_app/2_CI_data_prep.R | 3 -- 6 files changed, 35 insertions(+), 64 deletions(-) diff --git a/.idea/php.xml b/.idea/php.xml index dce468a..e4712ef 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -1,5 +1,10 @@ + + + + + diff --git a/build_mosaic.sh b/build_mosaic.sh index efe24e8..35f0751 100755 --- a/build_mosaic.sh +++ b/build_mosaic.sh @@ -1,30 +1,25 @@ #!/bin/bash -filename="report_dummie.docx" weeks_ago="0" -report_date="2022-12-12" -# Parse de command line argumenten -while [ "$#" -gt 0 ]; do - case "$1" in +# Parse command line arguments +for arg in "$@"; do + case $arg in --weeks_ago=*) - weeks_ago="${1#*=}" + weeks_ago="${arg#*=}" ;; *) - echo "Onbekende optie: $1" + echo "Unknown option: $arg" exit 1 ;; esac - shift done -# Controleer of de vereiste argumenten zijn ingesteld +# Check if required arguments are set if [ -z "$weeks_ago" ]; then - echo "Missende argumenten. Gebruik: build_mosiac.sh --weeks_ago=3" + echo "Missing arguments. Use: build_mosiac.sh --weeks_ago=3" exit 1 fi - -echo "Weeks ago: $weeks_ago" -cd /Users/mfolkerts/smartCane/r_app -Rscript 2_CI_data_prep.R $weeks_ago +cd ../r_app +Rscript 2_CI_data_prep.R $weeks_ago \ No newline at end of file diff --git a/build_report.sh b/build_report.sh index a63e381..e04fbac 100755 --- a/build_report.sh +++ b/build_report.sh @@ -1,51 +1,37 @@ #!/bin/bash -filename="report_dummie.docx" -weeks_ago="0" -report_date="2022-12-12" - -# Parse de command line argumenten -while [ "$#" -gt 0 ]; do - case "$1" in +# Parse command line arguments +for arg in "$@"; do + case $arg in --filename=*) - filename="${1#*=}" + filename="${arg#*=}" ;; --weeks_ago=*) - weeks_ago="${1#*=}" + weeks_ago="${arg#*=}" ;; --report_date=*) - report_date="${1#*=}" + report_date="${arg#*=}" ;; *) - echo "Onbekende optie: $1" + echo "Unknown option: $arg" exit 1 ;; esac - shift done -# Controleer of de vereiste argumenten zijn ingesteld -if [ -z "$filename" ] || [ -z "$weeks_ago" ] || [ -z $report_date ]; then - echo "Missende argumenten. Gebruik: build_reports.sh --filename=hello.txt --weeks_ago=3 --report_date=2020-01-01" +# Check if required arguments are set +if [ -z "$filename" ] || [ -z "$weeks_ago" ] || [ -z "$report_date" ]; then + echo "Missing arguments. Use: build_reports.sh --filename=hello.txt --weeks_ago=3 --report_date=2020-01-01" exit 1 fi -# Je script logica hier +# Script logic here echo "Filename: $filename" echo "Weeks ago: $weeks_ago" echo "Report date: $report_date" -#script_dir="$(dirname "$0")" -#echo $script_dir; -#/bin/ps aux | grep fontd -#output_file="/Users/mfolkerts/smartCane/laravel_app/storage/app/chemba/$filename" - -#echo "Output file: $output_file" echo '\n' echo 'zx28tb' | /usr/bin/sudo -S launchctl load -w /System/Library/LaunchAgents/com.apple.fontd.useragent.plist cd /Users/mfolkerts/smartCane/r_app -#Rscript -e "rmarkdown::render('/Users/mfolkerts/smartCane/r_app/CI_Report_dashboard_planet.Rmd', 'all')" -#Rscript 1_harvest_data_EcoFarm_v2.R -#Rscript 2_CI_data_prep.R $weeks_ago -Rscript -e "rmarkdown::render('CI_report_dashboard_planet.Rmd', output_file='$filename', params=list(ref='$ref', report_date='$report_date'))" +Rscript -e "rmarkdown::render('CI_report_dashboard_planet.Rmd', output_file='$filename', params=list(ref='$ref', report_date='$report_date'))" \ No newline at end of file diff --git a/laravel_app/app/Jobs/ProjectDownloadTiffJob.php b/laravel_app/app/Jobs/ProjectDownloadTiffJob.php index a1e8dc3..7789ed1 100644 --- a/laravel_app/app/Jobs/ProjectDownloadTiffJob.php +++ b/laravel_app/app/Jobs/ProjectDownloadTiffJob.php @@ -6,10 +6,8 @@ use App\Models\ProjectDownload; use Illuminate\Bus\Batchable; use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Process\Exceptions\ProcessFailedException; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use Carbon\Carbon; @@ -37,42 +35,32 @@ public function __construct(ProjectDownload $download, Carbon $date,) */ public function handle(): void { - $projectFolder = base_path('../'); - $command = [ - sprintf('%srunpython.sh', $projectFolder), + sprintf('%srunpython.sh', base_path('../')), sprintf('--date=%s', $this->date->format('Y-m-d')), sprintf('--days=%d', $this->days), sprintf('--project_dir=%s', $this->download->project->download_path), ]; - // Convert commands array to a single string - $process = new Process($command); - $process->setTimeout(3600); // stel een geschikte timeout in - $process->start(); + $process->setTimeout(3600); + $process->run(); - try { - $process->wait(function ($type, $buffer) use (&$myOutput) { - logger($buffer); - }); - } catch (ProcessFailedException $exception) { - logger('error', $exception->getMessage()); + if (!$process->isSuccessful()) { + logger('error', $process->getErrorOutput()); } - $this->download->update([ - 'status' => 'completed', - ]); + $this->download->update(['status' => 'completed']); } public static function handleForDate(Project $project, Carbon $date) { - $filename = sprintf('%s.tif', $date->format('Y-m-d')); + $filename = $date->format('Y-m-d') . '.tif'; if ($project->downloads()->where(['status' => 'completed', 'name' => $filename])->count() > 0) { return; } - $path = sprintf('%s/%s/%s', $project->download_path, 'merged_final_tif', $filename); + $path = $project->download_path . '/merged_final_tif/' . $filename; return new self( $project->downloads()->create([ 'name' => $filename, diff --git a/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php b/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php index e84eb53..9ff7b62 100644 --- a/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php +++ b/laravel_app/app/Jobs/ProjectMosiacGeneratorJob.php @@ -48,7 +48,7 @@ public function handle(): void $process = new Process($command); $process->setTimeout(120); - $currentPath = '/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin/Users/mfolkerts/anaconda3/bin:/Library/Apple/usr/bin'; + $currentPath = 'usr/bin:/usr/gnu/bin:/usr/local/bin:/bin:/usr/bin/Users/mfolkerts/anaconda3/bin:/Library/Apple/usr/bin'; $process->setEnv(['PATH' => $currentPath.':/usr/local/Cellar/pandoc/3.1.8/bin/pandoc']); // $process->setTimeout(36000); // stel een geschikte timeout in diff --git a/r_app/2_CI_data_prep.R b/r_app/2_CI_data_prep.R index b9259c0..d12a2ea 100644 --- a/r_app/2_CI_data_prep.R +++ b/r_app/2_CI_data_prep.R @@ -82,8 +82,6 @@ message("starting ", file) # names(CI) <- c("green","nir") message("raster loaded") - - CI <- CI[[2]]/CI[[1]]-1 # CI <- CI$nir/CI$green-1 message("CI calculated") @@ -100,7 +98,6 @@ message("CI calculated") # v_crop <- mask_raster(v, pivot_sf_q) return(CI) - } # rasters_masked <- map(filtered_files, create_mask_and_crop, pivot_sf_q)