the weath­er station/software gen­er­ates a csv file of that col­lects val­ues from the sen­sors every 20 minutes.

it’s not a very nice file — it con­tains all the pos­si­ble val­ues (if you where using all the avail­able sen­sor chan­nels) for me that means that 49 of the fields are unnec­es­sary and do not exist in the track­ing database.

some­how i have to clean them out.

i do this by read­ing the por­tion of the file that i need into an array and then after clean­ing up a few fields that are stored in the wrong type I have to move every­thing into a new array so that i can write it to a file that i can feed to MySQL.

(in the fol­low­ing exam­ple $rawRowAr­ray is the array that holds of all of the fields from the csv after the lit­tle prob­lems have been corrected.)

$clean­RowAr­ray = array();

for ($i=1; $i=14; $i++) {
$k = $i — 1; // to get the array keys right
$cleanRowArray[$k] = $rawRowArray[$k]; //add the field to the array
}
//skip ele­ments 14 — 18 (not used)
for ($i=19; $i=37; $i++) {
$k = $i — 1; // to get the array keys right
$cleanRowArray[$k] = $rawRowArray[$k]; //add the field to the array
}

//skip ele­ments 38–46 (not used)
for ($i=47; $i=66; $i++) {
$k = $i — 1; // to get the array keys right
$cleanRowArray[$k] = $rawRowArray[$k]; //add the field to the array
}
//skip ele­ments 67 ‑103 (not used)

there has got to be some­thing more ele­gant but I like this. there’s no mis­tak­ing whats going on and it will be easy to change if we add more sen­sors to the sys­tem. (just change which ele­ments are skipped.)

Facebooktwitterlinkedinmail