fields and tags
This commit is contained in:
@@ -81,22 +81,11 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build tags
|
// Build tags
|
||||||
tags := map[string]string{
|
tags := make(map[string]string)
|
||||||
"application": measurement.Application,
|
|
||||||
}
|
|
||||||
if measurement.Device != "" {
|
if measurement.Device != "" {
|
||||||
tags["device"] = measurement.Device
|
tags["device"] = measurement.Device
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add attributes as tags
|
|
||||||
for key, value := range measurement.Attributes {
|
|
||||||
if strValue, ok := value.(string); ok {
|
|
||||||
tags[key] = strValue
|
|
||||||
} else {
|
|
||||||
tags[key] = fmt.Sprintf("%v", value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build fields from Values
|
// Build fields from Values
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
for key, varType := range measurement.Values {
|
for key, varType := range measurement.Values {
|
||||||
@@ -107,13 +96,22 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
|
|||||||
if varType.Unit != "" {
|
if varType.Unit != "" {
|
||||||
fields[key+"_unit"] = varType.Unit
|
fields[key+"_unit"] = varType.Unit
|
||||||
}
|
}
|
||||||
if varType.Variable != "" {
|
// This is already the column name, so we can skip it
|
||||||
fields[key+"_variable"] = varType.Variable
|
//if varType.Variable != "" {
|
||||||
}
|
// fields[key+"_variable"] = varType.Variable
|
||||||
|
//}
|
||||||
if varType.Status != "" {
|
if varType.Status != "" {
|
||||||
fields[key+"_status"] = varType.Status
|
fields[key+"_status"] = varType.Status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Add attributes as fields
|
||||||
|
for key, value := range measurement.Attributes {
|
||||||
|
if strValue, ok := value.(string); ok {
|
||||||
|
fields[key] = strValue
|
||||||
|
} else {
|
||||||
|
fields[key] = fmt.Sprintf("%v", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure we have at least one field
|
// Ensure we have at least one field
|
||||||
if len(fields) == 0 {
|
if len(fields) == 0 {
|
||||||
@@ -124,7 +122,7 @@ func (self *DatabaseHandle) StoreMeasurement(measurement *Measurement) {
|
|||||||
|
|
||||||
// Create point
|
// Create point
|
||||||
pt, err := influxdb.NewPoint(
|
pt, err := influxdb.NewPoint(
|
||||||
"observation",
|
measurement.Application,
|
||||||
tags,
|
tags,
|
||||||
fields,
|
fields,
|
||||||
measurement.Time,
|
measurement.Time,
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
create extension if not exists timescaledb;
|
|
||||||
|
|
||||||
create table application_t (
|
|
||||||
id serial not null primary key,
|
|
||||||
label text not null unique,
|
|
||||||
attributes jsonb
|
|
||||||
);
|
|
||||||
|
|
||||||
create table sensor_type_t (
|
|
||||||
id serial not null primary key,
|
|
||||||
label text not null unique,
|
|
||||||
variable text not null,
|
|
||||||
unit text not null,
|
|
||||||
converter text not null,
|
|
||||||
attributes jsonb
|
|
||||||
);
|
|
||||||
|
|
||||||
create table sensor_t (
|
|
||||||
id serial not null primary key,
|
|
||||||
label text not null,
|
|
||||||
application int references application_t(id),
|
|
||||||
sensor_type int references sensor_type_t(id),
|
|
||||||
attributes jsonb,
|
|
||||||
unique (label, application)
|
|
||||||
);
|
|
||||||
|
|
||||||
create table measurement_t (
|
|
||||||
time timestamp without time zone not null,
|
|
||||||
application text not null,
|
|
||||||
sensor_type text not null,
|
|
||||||
sensor text not null,
|
|
||||||
variable text not null,
|
|
||||||
unit text not null,
|
|
||||||
value double precision not null,
|
|
||||||
attributes jsonb
|
|
||||||
);
|
|
||||||
|
|
||||||
select create_hypertable('measurement_t', 'time');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user