Skip to content

Commit

Permalink
Merge pull request #54 from introlab/dev
Browse files Browse the repository at this point in the history
Enabling CSV export. Fixed export for GPS.
  • Loading branch information
doumdi authored Mar 14, 2020
2 parents 2c6f58b + 717c0f5 commit 870d838
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
40 changes: 37 additions & 3 deletions python/libopenimu/db/DBManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from libopenimu.models.Recordset import Recordset
from libopenimu.models.Channel import Channel
from libopenimu.models.SensorData import SensorData
from libopenimu.models.sensor_types import SensorType
from libopenimu.models.SensorTimestamps import SensorTimestamps
from libopenimu.models.DataSet import DataSet
from libopenimu.models.ProcessedData import ProcessedData
Expand Down Expand Up @@ -612,10 +613,44 @@ def export_csv_recordset(self, participant : Participant, recordset : Recordset,
for sensor in sensors:
# Do something
all_data = self.get_all_sensor_data(recordset=recordset, sensor=sensor)
if sensor.id_sensor_type is not SensorType.GPS:
self.export_csv_sensor_data(sensor, all_data, record_dir)
else:
self.export_csv_sensor_data_gps(sensor, all_data, record_dir)

self.export_csv_sensor_data(sensor, all_data, record_dir)
def export_csv_sensor_data_gps(self, sensor: Sensor, sensors_data: list, directory):

def export_csv_sensor_data(self, sensor : Sensor, sensors_data : list, directory):
# GPS is stored as SIRF data structures.
from libopenimu.importers.wimu import GPSGeodetic

filename = directory + sensor.name + '.CSV'
print('output to file : ', filename)

# Write CSV header
header = str()
channels = self.get_all_channels(sensor=sensor)

# Create data array
# TODO, WILL HANDLE ONLY ONE GPS CHANNEL FOR NOW
my_array = np.zeros(shape=(len(sensors_data), 3))

for channel in channels:
header = header + 'TIME;' + channel.label + '-Latitude;' + channel.label + '-Longitude;'

for i in range(0, len(sensors_data)):
gps_data = GPSGeodetic()
gps_data.from_bytes(sensors_data[i].data)
# Fill data
my_array[i][0] = sensors_data[i].timestamps.start_timestamp.timestamp()
my_array[i][1] = gps_data.get_latitude()
my_array[i][2] = gps_data.get_longitude()

# Save CSV
# print('dims:', my_array.shape)
# Write values
np.savetxt(filename, my_array, delimiter=";", header=header)

def export_csv_sensor_data(self, sensor: Sensor, sensors_data: list, directory):
result = {}
for sensor_data in sensors_data:
if not result.__contains__(sensor_data.channel.id_channel):
Expand All @@ -635,7 +670,6 @@ def export_csv_sensor_data(self, sensor : Sensor, sensors_data : list, directory
for channel in channels:
header = header + 'TIME;' + channel.label + ';'


for channel_key in result:
time = []
values = []
Expand Down
5 changes: 3 additions & 2 deletions python/libopenimu/qt/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ def import_requested(self):
def export_csv_requested(self):
exporter = ExportWindow(self.dbMan, self)
exporter.setStyleSheet(self.styleSheet())
# if exporter.exec() == QDialog.Accepted:
# print("Accepted")
if exporter.exec() == QDialog.Accepted:
print("Accepted")

@pyqtSlot()
def infos_requested(self):
Expand Down Expand Up @@ -569,3 +569,4 @@ def __init__(self, callable_method):

def write(self, text):
self.callback(text)

2 changes: 1 addition & 1 deletion python/resources/ui/StartDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Version 0.6.1</string>
<string>Version 0.6.2</string>
</property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignRight|Qt::AlignTrailing</set>
Expand Down

0 comments on commit 870d838

Please sign in to comment.