Zeiten besser dargestellt
Werte in europäisches System umgerechnet
This commit is contained in:
@@ -48,15 +48,8 @@ function renderCharts(apiData) {
|
|||||||
const rainData = apiData.rain_hourly;
|
const rainData = apiData.rain_hourly;
|
||||||
|
|
||||||
// Konvertiere Timestamps in Millisekunden
|
// Konvertiere Timestamps in Millisekunden
|
||||||
const timestamps = data.map(d => {
|
const timestamps = data.map(d => d.dateTime)
|
||||||
const [date, time] = d.dateTime.split(' ');
|
const rainTimestamps = rainData.map(d => new Date(d.hour).getTime())
|
||||||
return new Date(date + 'T' + time).getTime();
|
|
||||||
});
|
|
||||||
|
|
||||||
const rainTimestamps = rainData.map(d => {
|
|
||||||
const [date, time] = d.hour.split(' ');
|
|
||||||
return new Date(date + 'T' + time).getTime();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Berechne Zeitbereich für die Achsen
|
// Berechne Zeitbereich für die Achsen
|
||||||
const minTime = Math.min(...timestamps, ...rainTimestamps);
|
const minTime = Math.min(...timestamps, ...rainTimestamps);
|
||||||
@@ -66,7 +59,7 @@ function renderCharts(apiData) {
|
|||||||
const ONE_HOUR = 3600000;
|
const ONE_HOUR = 3600000;
|
||||||
const FOUR_HOURS = ONE_HOUR * 4;
|
const FOUR_HOURS = ONE_HOUR * 4;
|
||||||
|
|
||||||
// Temperatur
|
// Temperatur (Fahrenheit -> Celsius umrechnen)
|
||||||
Highcharts.chart('temp-chart', {
|
Highcharts.chart('temp-chart', {
|
||||||
chart: { type: 'line', height: DEFAULT_CHART_HEIGHT, spacingRight: 20 },
|
chart: { type: 'line', height: DEFAULT_CHART_HEIGHT, spacingRight: 20 },
|
||||||
title: { text: '🌡️ Temperatur (°C)' },
|
title: { text: '🌡️ Temperatur (°C)' },
|
||||||
@@ -74,13 +67,14 @@ function renderCharts(apiData) {
|
|||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
title: { text: 'Zeit' },
|
title: { text: 'Zeit' },
|
||||||
labels: { format: '{value:%H}' },
|
labels: { format: '{value:%H}' },
|
||||||
tickInterval: FOUR_HOURS
|
tickInterval: FOUR_HOURS,
|
||||||
|
gridLineWidth: 1
|
||||||
},
|
},
|
||||||
yAxis: { title: { text: '°C' } },
|
yAxis: { title: { text: '°C' } },
|
||||||
legend: { enabled: true },
|
legend: { enabled: true },
|
||||||
series: [{
|
series: [{
|
||||||
name: 'Temperatur',
|
name: 'Temperatur',
|
||||||
data: data.map((d, i) => [timestamps[i], d.outTemp]),
|
data: data.map((d, i) => [d.dateTime*1000, (d.outTemp - 32) * 5/9]),
|
||||||
color: '#ff6b6b',
|
color: '#ff6b6b',
|
||||||
lineWidth: 2
|
lineWidth: 2
|
||||||
}],
|
}],
|
||||||
@@ -95,20 +89,21 @@ function renderCharts(apiData) {
|
|||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
title: { text: 'Zeit' },
|
title: { text: 'Zeit' },
|
||||||
labels: { format: '{value:%H}' },
|
labels: { format: '{value:%H}' },
|
||||||
tickInterval: FOUR_HOURS
|
tickInterval: FOUR_HOURS,
|
||||||
|
gridLineWidth: 1
|
||||||
},
|
},
|
||||||
yAxis: { title: { text: '%' } },
|
yAxis: { title: { text: '%' } },
|
||||||
legend: { enabled: true },
|
legend: { enabled: true },
|
||||||
series: [{
|
series: [{
|
||||||
name: 'Luftfeuchtigkeit',
|
name: 'Luftfeuchtigkeit',
|
||||||
data: data.map((d, i) => [timestamps[i], d.outHumidity]),
|
data: data.map((d, i) => [d.dateTime*1000, d.outHumidity]),
|
||||||
color: '#4ecdc4',
|
color: '#4ecdc4',
|
||||||
lineWidth: 2
|
lineWidth: 2
|
||||||
}],
|
}],
|
||||||
credits: { enabled: false }
|
credits: { enabled: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Luftdruck
|
// Luftdruck (inHg -> hPa umrechnen)
|
||||||
Highcharts.chart('pressure-chart', {
|
Highcharts.chart('pressure-chart', {
|
||||||
chart: { type: 'line', height: DEFAULT_CHART_HEIGHT, spacingRight: 20 },
|
chart: { type: 'line', height: DEFAULT_CHART_HEIGHT, spacingRight: 20 },
|
||||||
title: { text: '🎈 Luftdruck (hPa)' },
|
title: { text: '🎈 Luftdruck (hPa)' },
|
||||||
@@ -116,13 +111,14 @@ function renderCharts(apiData) {
|
|||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
title: { text: 'Zeit' },
|
title: { text: 'Zeit' },
|
||||||
labels: { format: '{value:%H}' },
|
labels: { format: '{value:%H}' },
|
||||||
tickInterval: FOUR_HOURS
|
tickInterval: FOUR_HOURS,
|
||||||
|
gridLineWidth: 1
|
||||||
},
|
},
|
||||||
yAxis: { title: { text: 'hPa' } },
|
yAxis: { title: { text: 'hPa' } },
|
||||||
legend: { enabled: true },
|
legend: { enabled: true },
|
||||||
series: [{
|
series: [{
|
||||||
name: 'Luftdruck',
|
name: 'Luftdruck',
|
||||||
data: data.map((d, i) => [timestamps[i], d.barometer]),
|
data: data.map((d, i) => [d.dateTime*1000, d.barometer * 33.8639]),
|
||||||
color: '#95e1d3',
|
color: '#95e1d3',
|
||||||
lineWidth: 2
|
lineWidth: 2
|
||||||
}],
|
}],
|
||||||
@@ -137,41 +133,42 @@ function renderCharts(apiData) {
|
|||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
title: { text: 'Zeit' },
|
title: { text: 'Zeit' },
|
||||||
labels: { format: '{value:%H}' },
|
labels: { format: '{value:%H}' },
|
||||||
tickInterval: FOUR_HOURS
|
tickInterval: FOUR_HOURS,
|
||||||
|
gridLineWidth: 1
|
||||||
},
|
},
|
||||||
yAxis: { title: { text: 'mm' } },
|
yAxis: { title: { text: 'mm' } },
|
||||||
legend: { enabled: false },
|
legend: { enabled: false },
|
||||||
series: [{
|
series: [{
|
||||||
name: 'Regen',
|
name: 'Regen',
|
||||||
data: rainData.map((d, i) => [rainTimestamps[i], d.rain]),
|
data: rainData.map((d, i) => [d.dateTime*1000, d.rain]),
|
||||||
color: '#3498db'
|
color: '#3498db'
|
||||||
}],
|
}],
|
||||||
credits: { enabled: false }
|
credits: { enabled: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Windgeschwindigkeit
|
// Windgeschwindigkeit (mph -> km/h umrechnen)
|
||||||
Highcharts.chart('wind-speed-chart', {
|
Highcharts.chart('wind-speed-chart', {
|
||||||
chart: { type: 'line', height: DEFAULT_CHART_HEIGHT, spacingRight: 20 },
|
chart: { type: 'line', height: DEFAULT_CHART_HEIGHT, spacingRight: 20 },
|
||||||
title: { text: '💨 Windgeschwindigkeit (m/s)' },
|
title: { text: '💨 Windgeschwindigkeit (km/h)' },
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
title: { text: 'Zeit' },
|
title: { text: 'Zeit' },
|
||||||
labels: { format: '{value:%H}' },
|
labels: { format: '{value:%H}' },
|
||||||
tickInterval: FOUR_HOURS
|
tickInterval: FOUR_HOURS,
|
||||||
|
gridLineWidth: 1
|
||||||
},
|
},
|
||||||
yAxis: { title: { text: 'm/s' } },
|
yAxis: { title: { text: 'km/h' } },
|
||||||
legend: { enabled: true },
|
legend: { enabled: true },
|
||||||
series: [{
|
series: [{
|
||||||
name: 'Windgeschwindigkeit',
|
name: 'Windgeschwindigkeit',
|
||||||
data: data.map((d, i) => [timestamps[i], d.windSpeed]),
|
data: data.map((d, i) => [d.dateTime*1000, d.windSpeed * 1.60934]),
|
||||||
color: '#f38181',
|
color: 'blue',
|
||||||
lineWidth: 2
|
lineWidth: 2
|
||||||
}, {
|
}, {
|
||||||
name: 'Böen',
|
name: 'Böen',
|
||||||
data: data.map((d, i) => [timestamps[i], d.windGust]),
|
data: data.map((d, i) => [d.dateTime*1000, d.windGust * 1.60934]),
|
||||||
color: '#aa96da',
|
color: 'red',
|
||||||
lineWidth: 2,
|
lineWidth: 2,
|
||||||
dashStyle: 'dash'
|
|
||||||
}],
|
}],
|
||||||
credits: { enabled: false }
|
credits: { enabled: false }
|
||||||
});
|
});
|
||||||
@@ -184,20 +181,38 @@ function renderCharts(apiData) {
|
|||||||
type: 'datetime',
|
type: 'datetime',
|
||||||
title: { text: 'Zeit' },
|
title: { text: 'Zeit' },
|
||||||
labels: { format: '{value:%H}' },
|
labels: { format: '{value:%H}' },
|
||||||
tickInterval: FOUR_HOURS
|
tickInterval: FOUR_HOURS,
|
||||||
|
gridLineWidth: 1
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
title: { text: 'Richtung (°)' },
|
title: { text: 'Richtung (°)' },
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 360,
|
max: 360,
|
||||||
tickPositions: [0, 90, 180, 270, 360]
|
// tickPositions: [0, 90, 180, 270, 360]
|
||||||
|
tickInterval: 90,
|
||||||
|
labels: {
|
||||||
|
formatter: function() {
|
||||||
|
// Windrichtungen zuordnen
|
||||||
|
const directions = {
|
||||||
|
0: 'Nord',
|
||||||
|
90: 'Ost',
|
||||||
|
180: 'Süd',
|
||||||
|
270: 'West',
|
||||||
|
360: 'Nord'
|
||||||
|
};
|
||||||
|
return directions[this.value] || this.value + '°';
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
legend: { enabled: true },
|
legend: { enabled: true },
|
||||||
series: [{
|
series: [{
|
||||||
name: 'Windrichtung',
|
name: 'Windrichtung',
|
||||||
data: data.map((d, i) => [timestamps[i], d.windDir || 0]),
|
data: data.map((d, i) => [d.dateTime*1000, d.windDir || 0]),
|
||||||
color: '#f39c12',
|
color: '#f39c12',
|
||||||
lineWidth: 2
|
marker: {
|
||||||
|
radius: 2
|
||||||
|
}
|
||||||
|
// lineWidth: 2
|
||||||
}],
|
}],
|
||||||
credits: { enabled: false }
|
credits: { enabled: false }
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class WetterDB:
|
|||||||
conn.row_factory = sqlite3.Row
|
conn.row_factory = sqlite3.Row
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
time_threshold = (datetime.now() - timedelta(hours=hours)).strftime('%Y-%m-%d %H:%M:%S')
|
time_threshold = int((datetime.now() - timedelta(hours=hours)).timestamp())
|
||||||
|
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
SELECT * FROM wetterdaten
|
SELECT * FROM wetterdaten
|
||||||
@@ -51,11 +51,11 @@ class WetterDB:
|
|||||||
conn = sqlite3.connect(self.db_file)
|
conn = sqlite3.connect(self.db_file)
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
time_threshold = (datetime.now() - timedelta(hours=hours)).strftime('%Y-%m-%d %H:%M:%S')
|
time_threshold = int((datetime.now() - timedelta(hours=hours)).timestamp())
|
||||||
|
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
SELECT
|
SELECT
|
||||||
strftime('%Y-%m-%d %H:00:00', dateTime) as hour,
|
strftime('%Y-%m-%d %H:00:00', datetime(dateTime, 'unixepoch', 'localtime')) as hour,
|
||||||
SUM(rainRate) as total_rain
|
SUM(rainRate) as total_rain
|
||||||
FROM wetterdaten
|
FROM wetterdaten
|
||||||
WHERE dateTime >= ?
|
WHERE dateTime >= ?
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class WetterDB:
|
|||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS wetterdaten (
|
CREATE TABLE IF NOT EXISTS wetterdaten (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
dateTime TEXT NOT NULL,
|
dateTime INTEGER NOT NULL,
|
||||||
barometer REAL,
|
barometer REAL,
|
||||||
outTemp REAL,
|
outTemp REAL,
|
||||||
outHumidity INTEGER,
|
outHumidity INTEGER,
|
||||||
@@ -86,7 +86,7 @@ def health():
|
|||||||
return jsonify({'status': 'ok', 'service': 'ingestion'}), 200
|
return jsonify({'status': 'ok', 'service': 'ingestion'}), 200
|
||||||
|
|
||||||
|
|
||||||
@app.route('/api/data/upload', methods=['POST'])
|
# @app.route('/api/data/upload', methods=['POST'])
|
||||||
@app.route('/api/data/upload/', methods=['POST'])
|
@app.route('/api/data/upload/', methods=['POST'])
|
||||||
def upload_data():
|
def upload_data():
|
||||||
"""HTTP-POST Endpoint für Wetterdaten"""
|
"""HTTP-POST Endpoint für Wetterdaten"""
|
||||||
|
|||||||
Reference in New Issue
Block a user