the weather station/software generates a csv file of that collects values from the sensors every 20 minutes.
it’s not a very nice file — it contains all the possible values (if you where using all the available sensor channels) for me that means that 49 of the fields are unnecessary and do not exist in the tracking database.
somehow i have to clean them out.
i do this by reading the portion of the file that i need into an array and then after cleaning up a few fields that are stored in the wrong type I have to move everything into a new array so that i can write it to a file that i can feed to MySQL.
(in the following example $rawRowArray is the array that holds of all of the fields from the csv after the little problems have been corrected.)
$cleanRowArray = 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 elements 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 elements 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 elements 67 ‑103 (not used)
there has got to be something more elegant but I like this. there’s no mistaking whats going on and it will be easy to change if we add more sensors to the system. (just change which elements are skipped.)