fix parsing the date, it is UTC

This commit is contained in:
Thomas Ruoff
2017-05-31 01:12:20 +02:00
parent 5ced841cde
commit f3375002bd

View File

@@ -3,14 +3,14 @@
# Converts CSV exports from https://www.madavi.de/sensor/csvfiles.php to # Converts CSV exports from https://www.madavi.de/sensor/csvfiles.php to
# InfluxDB LineProtocol https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_reference/ # InfluxDB LineProtocol https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_reference/
# #
# Note: timestamps are in seconds, therefore user precision parameter when # Note: timestamps are in seconds, therefore precision "s" needs to be set
# writing, see https://docs.influxdata.com/influxdb/v1.2/tools/api/#write # when writing, see https://docs.influxdata.com/influxdb/v1.2/tools/api/#write
# CSV file spects # CSV file specs
# #
# | DB Field | DB field | CSV Column | CSV Format # | DB Field | DB field | CSV Column | CSV Format
# |-------------|----------|-----------------------|--------------------- # |-------------|----------|-----------------------|--------------------------
# | time | time | 1 Time | 2017/05/19 00:00:11 # | time | time | 1 Time | 2017/05/19 00:00:11 (UTC)
# | | | 2 durP1 | # | | | 2 durP1 |
# | | | 3 ratioP1 | # | | | 3 ratioP1 |
# | | | 4 P1 | # | | | 4 P1 |
@@ -31,9 +31,10 @@
# | max_micro | field | 19 Max_cycle | 25198 # | max_micro | field | 19 Max_cycle | 25198
# | | | 20 Signal | -91 # | | | 20 Signal | -91
# | node | tag | -- -- | e.g. esp8266-16229960 # | node | tag | -- -- | e.g. esp8266-16229960
#
# TODO: # TODO:
# - check if CSV export is in UTC ? # - using "date" to parse the UTC date for each line is super slow, but
# works. There must be something better out there.
SRC_FILE=${1:-/dev/stdin} SRC_FILE=${1:-/dev/stdin}
@@ -44,10 +45,12 @@ NODE=esp8266-$SENSOR_ID
STRIP_CSV_HEADERS="tail -n +2" STRIP_CSV_HEADERS="tail -n +2"
cat $SRC_FILE \ cat $SRC_FILE \
| $STRIP_CSV_HEADERS \ | $STRIP_CSV_HEADERS \
| gawk -v db="$DATABASE" -v node="$NODE" \ | gawk -v db="$DATABASE" -v node="$NODE" \
'BEGIN { FS = ";" } ; \ 'BEGIN { FS = ";" } ; \
{ timestamp=mktime(gensub(/\/|:/," ", "g", $1)); \ { convertDate = "date -u --date=\""$1"\" +%s"; \
print db",node="node" SDS_P1="$8",SDS_P2="$9",humidity="$11",min_micro="$18",max_micro="$19",samples="$17",temperature="$10" "timestamp}' convertDate| getline timestamp; \
close(convertDate); \
print db",node="node" SDS_P1="$8",SDS_P2="$9",humidity="$11",min_micro="$18",max_micro="$19",samples="$17",temperature="$10" "timestamp }'