forked from kevinchapron/GoLang-FeatureExtractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensor.go
61 lines (54 loc) · 1.67 KB
/
Sensor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package extractor
import "fmt"
// Definition of Sensor type
type Sensor struct {
x,y,z float64
}
// Definition of ListSensor type, which contains all Sensors for a dataset
// Example: A dataset of 500 rows will have a ListSensor of 500 Sensors instances
// Example2:A 9-DOF dataset of 500 rows will have 3 ListSensor of 500Sensors each (accel, gyro, mag)
type ListSensor struct {
sensors []Sensor
}
func(sensors *ListSensor) AddSensor(sensor Sensor){
sensors.sensors = append(sensors.sensors, sensor)
}
func(sensors *ListSensor) GetSensors() []Sensor{
return sensors.sensors
}
/*
Method to create ListSensor
data:= is the dataset in float64
column_index:= is a slice with indexes of columns for the sensor
==> column_index[0] will be "x"
==> column_index[1] will be "y"
==> column_index[2] will be "z"
return: ListSensor
*/
func GetSensorFromData(data [][]float64, column_index [3]int) ListSensor{
if(len(data[0])<=column_index[0]){
panic(fmt.Sprintf("Error: Too much sensors registered !\nPlease review number of sensors in parameter of function \"%s\"","extractor.GetSensorsData"))
}
var sensors ListSensor
for _, row := range(data){
var sensor Sensor
var c = 0
for _, index := range(column_index){
switch(c){
case 0:sensor.x = row[index]; break;
case 1:sensor.y = row[index]; break;
case 2:sensor.z = row[index]; break;
}
c++
}
sensors.AddSensor(sensor)
}
return sensors
}
func GetSensorsData(float_data [][]float64, nb_device int) []ListSensor{
var return_value []ListSensor;
for i:=0 ; i < nb_device ; i++{
return_value = append(return_value,GetSensorFromData(float_data,[3]int{i*3,(i*3)+1,(i*3)+2}) )
}
return return_value
}