bd5cf9978d
mongo.js, influx_post.js und logit.js lagen in beiden Komponenten doppelt
und waren auseinandergelaufen - so ist der Zeitzonen-Fehler entstanden, den
readin seit jeher richtig loest und readFromcsv.js zwei Jahre lang nicht.
Sie liegen jetzt einmal unter common/.
Wo die Fassungen sich widersprachen:
- MONGOAUTH wird als String verglichen. Die readarchive-Fassung pruefte nur
auf truthy, dadurch schaltete auch MONGOAUTH=false die Auth ein.
- writeDataArray(client, coll, data) nimmt den Collection-Namen direkt;
readarchive baut ihn mit dem neuen dataCollName(styp).
- getallProperties liefert das Array selbst. Die readarchive-Fassung mit
{error, properties} war dort ungenutzt.
- properties_collection heisst einheitlich property_coll.
Das Sammelobjekt statistics lag in readin/readdata.js und wurde von
mongo.js und influx_post.js importiert. Es liegt jetzt in
common/statistics.js, damit die gemeinsamen Module readin nicht kennen
muessen.
Der Build-Kontext beider Images ist dadurch das Repository-Wurzelverzeichnis;
das Layout im Image spiegelt das Repository, damit ../common/... unveraendert
aufgeht. Die Volume-Zeile von readin im Compose zieht deshalb auf
/opt/app/readin/data um.
readarchive folgt jetzt den Konventionen des Stacks: deploy.sh statt
build_and_copy.sh, Dockerfile_readarchive statt Dockerfile_rfcsv, und die
eigene docker-compose.yml entfaellt - der Dienst haengt als Profil "tools"
im Compose des Stacks und wird mit Parametern gestartet:
docker compose run --rm readarchive -t noise -s 2026-07-25 -e 2026-07-29
Getestet: beide Images gebaut, beide gegen Testdatenbanken laufen lassen.
Nicht deployt - die Images in der Registry sind unveraendert.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
import axios from 'axios'
|
|
import * as fs from 'fs'
|
|
import { logit, logerror} from'../common/logit.js'
|
|
import { statistics } from '../common/statistics.js'
|
|
import { DateTime } from 'luxon'
|
|
const API_URL = 'https://api.sensor.community/static/v1/data.json'; // URL to API on 'luftdaten.info'
|
|
const SAVE_NAME = './data/aktdata.json'; // filename for actual data
|
|
|
|
let LIVE = process.env.LIVE || 'true'
|
|
|
|
export const doReadfromAPI = async () => {
|
|
logit(`LIVE = ${LIVE}`)
|
|
let start = DateTime.now()
|
|
let data = []
|
|
if (LIVE === 'true') {
|
|
logit(`Start Reading from API`)
|
|
let body
|
|
for(let count = 1; count <= 3; count++) {
|
|
try {
|
|
logit(`Try - ${count}`)
|
|
let ret = await axios(API_URL, {timeout: 10000})
|
|
if (ret.status != 200) {
|
|
continue
|
|
}
|
|
data = ret.data
|
|
saveDatatoFile(SAVE_NAME, JSON.stringify(data))
|
|
break
|
|
} catch (e) {
|
|
logerror(`doReadfromAPI ${e}`)
|
|
}
|
|
}
|
|
} else {
|
|
logit('Start using data on disk')
|
|
data = readDatafromFile(SAVE_NAME)
|
|
}
|
|
statistics.readInTime = start.diffNow('seconds').toObject().seconds * -1
|
|
statistics.entries = data.length
|
|
logit(`ReadIn-Time: ${statistics.readInTime} sec`)
|
|
return data
|
|
}
|
|
|
|
|
|
// die Daten in eimnr Datei zwischenspeichern
|
|
function saveDatatoFile(fn, data) {
|
|
fs.writeFileSync(fn, data)
|
|
}
|
|
|
|
// Daten wieder vom File lesen
|
|
function readDatafromFile(fn) {
|
|
return JSON.parse(fs.readFileSync(fn))
|
|
}
|