From b88fcec50cc943492a782dd9750ebbf4e0888ee5 Mon Sep 17 00:00:00 2001 From: Nico Rey Date: Sun, 27 Sep 2020 20:30:38 -0300 Subject: [PATCH] add a migration script for web panel view --- migrate_data.sh | 39 +++++++++++++++++++++++++++++++++++++++ panel.sql | 13 +++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 migrate_data.sh create mode 100644 panel.sql diff --git a/migrate_data.sh b/migrate_data.sh new file mode 100644 index 0000000..b4e1028 --- /dev/null +++ b/migrate_data.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# TODO: Warn the user +BASEPATH="/var/www/wx/image" +FINALPATH="/var/www/wx/images" +SAT_NAMES="NOAA15 NOAA18 NOAA19 METEOR-M2" +DB_PATH="/var/ramfs/panel.db" + +cd "$BASEPATH" || exit 1 +mkdir -p "$FINALPATH" + +for filename in $(find . -name *.jpg); do + basename="$(echo "$filename" | sed 's~.*/~~')" + for prefix in $SAT_NAMES; do + basedate="$(echo "$basename" | sed -e "s/^$prefix//" | cut -f1,2 -d'-' | sed -e "s/-//")" + if [[ $basename == *"$prefix"* ]]; then + sat_name=$prefix + fi + done + + date_normalized=$(echo "$basedate" | sed -e "s/^$sat_name//;s/./&:/12;s/./&:/10;s/./& /8;s/./&\//6;s/./&\//4") + epoch_date=$(date "+%s" -d "$date_normalized") + passname=$(echo "$basename" | cut -f1,2 -d'-') + echo "Migration in progress: $basename" + cp "$BASEPATH/$filename" "$FINALPATH" + if [[ $basename == *"METEOR"* ]]; then + sqlite3 "$DB_PATH" "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($epoch_date,\"$passname\",1,0);" + elif [[ $basename == *"ZA"* ]]; then + if [[ -f "$FINALPATH/$passname-MSA.jpg" ]]; then + sqlite3 "$DB_PATH" "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($epoch_date,\"$passname\",1,1);" + else + sqlite3 "$DB_PATH" "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($epoch_date,\"$passname\",0,1);" + fi + fi + echo "Done." + echo "" +done + + diff --git a/panel.sql b/panel.sql new file mode 100644 index 0000000..3aac464 --- /dev/null +++ b/panel.sql @@ -0,0 +1,13 @@ +create table predict_passes( + sat_name text not null, + pass_start timestamp primary key default (strftime('%s', 'now')) not null, + pass_end timestamp default (strftime('%s', 'now')) not null, + max_elev int not null); + + +CREATE TABLE decoded_passes( + id integer primary key autoincrement, + pass_start integer, + file_path text not null, + daylight_pass boolean, is_noaa boolean, + foreign key(pass_start) references passes(pass_start));