data pull and clean script

master
Rob Canning 2023-10-17 16:58:11 +02:00
parent fdcb294034
commit 7e8d65a9ab
12 changed files with 63 additions and 50066 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

37
data/get_data.sh 100755
View File

@ -0,0 +1,37 @@
#!/bin/bash
STATION_A='D7:80:BE:2C:63:BD'
STATION_B='F1:CC:C3:0B:7F:5C'
STATIONS=($STATION_A $STATION_B)
TOKEN=$(curl --insecure --data \
"username=data-api-user&password=jBD0CD1wGOKoTVtC&grant_type=password&client_id=phenode" \
https://phenode-link.com:8443/realms/grafana/protocol/openid-connect/token \
| python3 -c "import sys, json; print(json.load(sys.stdin)['access_token'])")
#rm -r all-data *.zip
for data in "${STATIONS[@]}"
do
if [ -d $data ]
then echo "removing old data directories" ; rm -r $data
else echo "nothing to remove"
fi ## if data dir exists then remove it
echo "downloading data from device with MAC: $data"
curl --insecure \
-X POST https://phenode-link.com:2537/devices/$data/all-data/2023-04-10T16:52:21Z \
-H "Authorization: Bearer $TOKEN" \
--output $data.zip
unzip $data.zip && mv all-data $data && rm $data.zip && cd $data
# remove the null data and replace with 0
sed -i 's/^,/0,/; :a;s/,,/,0,/g;ta' sensor_data.csv
# clear the ugly rows from Growing Degree Days
awk -F, 'NR==1{print} NR>1 && $2=="0" {gsub(/[)(\]\[]/,"",$0);print}' sensor_data.csv > tmp && mv tmp sensor_data_clean.csv
cd ../
done

View File

@ -3,16 +3,16 @@
s.options.numInputBusChannels = 4;
s.options.numOutputBusChannels = 4;
~dataPath = "/home/rob/konS/witw/data/D7-80-BE-2C-63-BD/all-data/"; // CHANGE THIS TO RELATIVE PATH
~dataPath = "/home/rizoma/witw/data/D7:80:BE:2C:63:BD/"; // CHANGE THIS TO RELATIVE PATH
"echo curl -v -X POST http://3.139.191.80:2537/devices/dev:864475040526732/all-data/2023-09-20T16:52:21Z -H 'Authorization: Bearer token' --output dev:864475040526732.zip".unixCmd;
s.waitForBoot{
// create 8 control busses to pass data between synths
~ctrlBus = 8.collect({arg i; Bus.control(s,1); });
// define synths
SynthDef(\sgrain, { | out=0, atk=0.01, dcy=0.01, freq=100, pan=0, amp=0.5|
var sig, env;
env = EnvGen.ar(Env.perc(atk, dcy), doneAction: 2);
@ -20,7 +20,7 @@ s.waitForBoot{
sig = sig * (env * amp);
sig = Pan2.ar(sig, pan);
Out.ar(out, sig);
Out.kr(~ctrlBus[0],freq)
Out.kr(~ctrlBus[0],freq);
}).add;
SynthDef(\sslew, {
@ -38,16 +38,19 @@ s.waitForBoot{
// todo preprocess file with Sed
// growing degree days causes nil in other fields - filter these out
~csvFile=CSVFileReader.readInterpret(~dataPath ++ "sensor_data-notime-noheader-cutrows1.csv",true,true);
//~csvFile=CSVFileReader.readInterpret(~dataPath ++ "sensor_data-notime-noheader-cutrows1.csv",true,true);
~csvFile=CSVFileReader.read(~dataPath ++ "sensor_data.csv",true,true);
// flatten ~data from 2D Array to regular array (per column);
// ~data = ( ~csvFile[0].size-1 ).collect({ arg itt;
~data = ( ~csvFile[0].size ).collect({ arg itt;
Array.fill( ~csvFile.size,{ arg i;
~csvFile.at(i).asArray.at(itt)});
Array.fill( ~csvFile.size-1,{ arg i;
~csvFile.at(i+1).asArray.at(itt)}); // +1 to skip the column name
});
~data[0]; // Temperature C
~data[1]; // F
~data[2]; // Temperature C
~data[3]; // F
~data[10]; // wind speed MPH
~data[11]; // wind direction
~data[13]; // wind gusts MPH
@ -57,30 +60,32 @@ s.waitForBoot{
~data[21]; // LAT
// normalize data ranges //////
~freq=~data[0].normalize(20, 5000);
~atk=~data[0].normalize(0.02, 0.1);
~dcy=~data[0].normalize(0.05, 0.3);
~dur=~data[0].normalize(0.01, 0.3);
~level=~data[0].normalize(0.01, 0.1);
~date=~data[0];
~freq=~data[2].asFloat.normalize(20, 1000);
~atk=~data[2].asFloat.normalize(0.02, 0.04);
~dcy=~data[2].asFloat.normalize(0.05, 0.1);
~dur=~data[2].asFloat.normalize(0.03, 0.3);
~level=~data[2].asFloat.normalize(0.01, 0.1);
//start the slewing synth /////////////////////////////
~sslew1 = Synth(\sslew,[\out,0,\freq,220,\amp,0.01,\slewrate,1000]);
~sslew1.map(\freq, ~ctrlBus[0]); // map control bus to freq parameter
//~sslew1 = Synth(\sslew,[\out,0,\freq,220,\amp,0.01,\slewrate,1000]);
//~sslew1.map(\freq, ~ctrlBus[0]); // map control bus to freq parameter
//o = OSCFunc({ |msg| msg.postln }, '/tr', s.addr);
// perform the data sonification /////////////////////
( p = Pbind(\instrument, \sgrain,
\freq, Pseq(~freq.round(300),1),
\freq, Pseq(~freq.round(100),1),
\atk, Pseq(~atk,1),
\dcy, Pseq(~dcy,1),
\pan, Pseq([0,1], inf),
\dur, Pseq(~dur,1),
\amp, Pseq(~level,1)
\amp, Pseq(~level,1),
//\renoise, Pfunc({|e| e.use { ~date.postln } })
).play;
);
}; // closes s.waitForBoot
p.stop;
//p.stop;
//~sslew1.stop;