The UFZ services GitLab and Mattermost will be unavailable on Monday, December 06 from 06:00 AM to 08:00 AM due to maintenance work.

Commit ed9ee723 authored by David Schäfer's avatar David Schäfer
Browse files

make the generic rewrite upload more robust

parent e7f7b837
......@@ -40,25 +40,14 @@ func (db *DataBase) querySensorPositions(projectId, loggerId int) (*SensorPositi
func (positions SensorPositions) Count() int {
// map configuration start dates to number count
counter := map[string]int{}
out := 0
for _, pos := range positions {
date := pos.StartDate.Format()
_, exists := counter[date]
if !exists {
counter[date] = 0
if pos.Position > out {
out = pos.Position
}
counter[date] += 1
}
// find the maximum number of sensors in all configurations
out := 0
for _, value := range counter {
if value > out {
out = value
}
}
return out
return out + 1
}
func (positions SensorPositions) TimePosition(date UploadDate) (int, error) {
......@@ -96,6 +85,11 @@ func (values Values) Encode(positions *SensorPositions) (string, error) {
colCount := positions.Count()
header := make([]string, colCount)
for _, pos := range *positions {
header[pos.Position] = pos.SensorLabel
}
table := map[string][]string{}
for _, value := range values {
......@@ -123,7 +117,7 @@ func (values Values) Encode(positions *SensorPositions) (string, error) {
row[pos] = fmt.Sprintf("%.12f", value.Value)
}
out := []string{}
out := []string{strings.Join(header, ",")}
for _, row := range table {
out = append(out, strings.Join(row, ","))
}
......
package db
import (
s "dmpapi/settings"
"fmt"
"io/ioutil"
)
......@@ -14,10 +15,13 @@ func readQuery(fname string) string {
}
var (
MIN_DATE = s.MIN_DATE.Format(s.DATE_FORMAT)
MAX_DATE = s.MAX_DATE.Format(s.DATE_FORMAT)
// TODO: unify naming scheme
VALUE_ID_QUERY = readQuery("queries/value_ids.sql")
SENSORS_POSITION_QUERY = readQuery("queries/sensors_positions.sql")
SENSORS_POSITION_QUERY = fmt.Sprintf(readQuery("queries/sensors_positions.sql"), MIN_DATE, MAX_DATE)
SENSORS_BASE_QUERY = readQuery("queries/sensors.sql")
SENSORS_QUERY = fmt.Sprintf(SENSORS_BASE_QUERY, "")
SENSORS_BY_SENSORNAME_QUERY = fmt.Sprintf(SENSORS_BASE_QUERY, "AND s.NAME = :4")
......
......@@ -2,8 +2,8 @@ SELECT
s.name AS
, s.label
, s.position
, TO_CHAR(c.config_start, 'YYYY-MM-DD HH24:MI:SS') AS start_date
, CASE WHEN c.config_end IS NULL THEN '2099-12-31 23:59:59' ELSE TO_CHAR(c.config_end, 'YYYY-MM-DD HH24:MI:SS') END AS end_date
, CASE WHEN c.config_start IS NULL THEN '%s' ELSE TO_CHAR(c.config_start, 'YYYY-MM-DD HH24:MI:SS') END AS start_date
, CASE WHEN c.config_end IS NULL THEN '%s' ELSE TO_CHAR(c.config_end, 'YYYY-MM-DD HH24:MI:SS') END AS end_date
, CASE WHEN s.sampling_media_name = 'TIME' AND s.evaluate_sensor = 0 THEN 1 ELSE 0 END AS is_time
FROM
logger.sensor s
......@@ -11,8 +11,9 @@ SELECT
JOIN logger.logger l on l.logger_id = c.logger_id
WHERE l.datenprojekt_id = :1
AND l.logger_id = :2
AND s.updated = 0 -- the generic rewrite parser only uses the latest setup
AND s.virtual_sensor = 0 -- we don't want virtual sensors, as they don't accept upload data
AND l.deleted = 0 -- leave the dead alone
AND s.deleted = 0
AND c.deleted = 0
-- AND c.config_end IS NULL
AND c.config_end IS NULL -- the generic rewrite parser does not support writing into old sensor configurations
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment