Skip to content

Commit 6827c00

Browse files
authored
Added property type column in export (#3)
1 parent 59ef703 commit 6827c00

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

business/tsextractor/tsextractor.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ func (a *TsExtractor) populateNumericTSDataIntoS3(
162162
a.logger.Debugf("Thing %s - Property %s - %d values\n", thingID, propertyID, response.CountValues)
163163
sampleCount += response.CountValues
164164

165-
propertyName := extractPropertyName(thing, propertyID)
165+
propertyName, propertyType := extractPropertyNameAndType(thing, propertyID)
166166

167167
for i := 0; i < len(response.Times); i++ {
168168

169169
ts := response.Times[i]
170170
value := response.Values[i]
171-
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, strconv.FormatFloat(value, 'f', -1, 64)))
171+
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, strconv.FormatFloat(value, 'f', -1, 64)))
172172
}
173173
}
174174

@@ -183,26 +183,29 @@ func (a *TsExtractor) populateNumericTSDataIntoS3(
183183
return nil
184184
}
185185

186-
func composeRow(ts time.Time, thingID string, thingName string, propertyID string, propertyName string, value string) []string {
187-
row := make([]string, 6)
186+
func composeRow(ts time.Time, thingID string, thingName string, propertyID string, propertyName string, propertyType string, value string) []string {
187+
row := make([]string, 7)
188188
row[0] = ts.UTC().Format(time.RFC3339)
189189
row[1] = thingID
190190
row[2] = thingName
191191
row[3] = propertyID
192192
row[4] = propertyName
193-
row[5] = value
193+
row[5] = propertyType
194+
row[6] = value
194195
return row
195196
}
196197

197-
func extractPropertyName(thing iotclient.ArduinoThing, propertyID string) string {
198+
func extractPropertyNameAndType(thing iotclient.ArduinoThing, propertyID string) (string, string) {
198199
propertyName := ""
200+
propertyType := ""
199201
for _, prop := range thing.Properties {
200202
if prop.Id == propertyID {
201203
propertyName = prop.Name
204+
propertyType = prop.Type
202205
break
203206
}
204207
}
205-
return propertyName
208+
return propertyName, propertyType
206209
}
207210

208211
func isStringProperty(ptype string) bool {
@@ -258,7 +261,7 @@ func (a *TsExtractor) populateStringTSDataIntoS3(
258261
a.logger.Debugf("Thing %s - String Property %s - %d values\n", thingID, propertyID, response.CountValues)
259262
sampleCount += response.CountValues
260263

261-
propertyName := extractPropertyName(thing, propertyID)
264+
propertyName, propertyType := extractPropertyNameAndType(thing, propertyID)
262265

263266
for i := 0; i < len(response.Times); i++ {
264267

@@ -267,7 +270,7 @@ func (a *TsExtractor) populateStringTSDataIntoS3(
267270
if value == nil {
268271
continue
269272
}
270-
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, interfaceToString(value)))
273+
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, interfaceToString(value)))
271274
}
272275
}
273276

@@ -318,7 +321,7 @@ func (a *TsExtractor) populateRawTSDataIntoS3(
318321
a.logger.Infof("Thing %s - Query %s Property %s - %d values\n", thingID, response.Query, propertyID, response.CountValues)
319322
sampleCount += response.CountValues
320323

321-
propertyName := extractPropertyName(thing, propertyID)
324+
propertyName, propertyType := extractPropertyNameAndType(thing, propertyID)
322325

323326
for i := 0; i < len(response.Times); i++ {
324327

@@ -327,7 +330,7 @@ func (a *TsExtractor) populateRawTSDataIntoS3(
327330
if value == nil {
328331
continue
329332
}
330-
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, interfaceToString(value)))
333+
samples = append(samples, composeRow(ts, thingID, thing.Name, propertyID, propertyName, propertyType, interfaceToString(value)))
331334
}
332335
}
333336

internal/csv/csv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const (
1515
baseTmpStorage = "/tmp"
1616
)
1717

18-
var csvHeader = []string{"timestamp", "thing_id", "thing_name", "property_id", "property_name", "value"}
18+
var csvHeader = []string{"timestamp", "thing_id", "thing_name", "property_id", "property_name", "property_type", "value"}
1919

2020
func NewWriter(destinationHour time.Time, logger *logrus.Entry) (*CsvWriter, error) {
2121
filePath := fmt.Sprintf("%s/%s.csv", baseTmpStorage, destinationHour.Format("2006-01-02-15:04"))

0 commit comments

Comments
 (0)