Commit c3faebd6 authored by Léo-Paul Géneau's avatar Léo-Paul Géneau 👾

erp5_wendelin_drone: convert data if data line was deleted

parent 93dfd2fa
import pandas as pd import pandas as pd
import numpy as np import numpy as np
from zExceptions import BadRequest
# Function to remove non-ASCII characters from a string, because I can not be bothered to make to_records with utf8 right now # Function to remove non-ASCII characters from a string, because I can not be bothered to make to_records with utf8 right now
def remove_non_ascii(text): def remove_non_ascii(text):
...@@ -8,36 +7,34 @@ def remove_non_ascii(text): ...@@ -8,36 +7,34 @@ def remove_non_ascii(text):
progress_indicator = in_stream["Progress Indicator"]
in_data_stream = in_stream["Data Bucket Stream"] in_data_stream = in_stream["Data Bucket Stream"]
out_data_array = out_array["Data Array"]
keys = in_data_stream.getKeyList() keys = in_data_stream.getKeyList()
end = progress_indicator.getStringOffsetIndex()
if end is None:
end = ""
if len(keys) == 0: if len(keys) == 0:
context.log("No Keys found") context.log("No Keys found")
return return
out_data_array = out_array["Data Array"]
dtype= {'timestamp (ms)': '<f8', if out_data_array.getArray() is not None:
'latitude ()': '<f8', key_list = [key for key in keys if not out_data_array.hasContent(key)]
'longitude ()': '<f8', else:
'AMSL (m)': '<f8', key_list = keys
'rel altitude (m)': '<f8',
'yaw ()': '<f8', if len(key_list) == 0:
'ground speed (m/s)': '<f8', context.log("No new keys found")
'climb rate (m/s)': '<f8'} return
if len([x for x in keys if x not in end]) == 0: dtype= {
context.log("No new keys found") 'timestamp (ms)': '<f8',
return 'latitude ()': '<f8',
'longitude ()': '<f8',
new_end = "" 'AMSL (m)': '<f8',
for key in [x for x in keys if x not in end]: 'rel altitude (m)': '<f8',
'yaw ()': '<f8',
'ground speed (m/s)': '<f8',
'climb rate (m/s)': '<f8',
}
for key in key_list:
try: try:
log = in_data_stream.getBucketByKey(key) log = in_data_stream.getBucketByKey(key)
df = pd.read_csv(log, sep=';', dtype=dtype) df = pd.read_csv(log, sep=';', dtype=dtype)
...@@ -55,25 +52,16 @@ for key in [x for x in keys if x not in end]: ...@@ -55,25 +52,16 @@ for key in [x for x in keys if x not in end]:
ndarray = df.to_records(index = False) #column_dtypes does not work here for some reasone, even if it is an actuall parameter ndarray = df.to_records(index = False) #column_dtypes does not work here for some reasone, even if it is an actuall parameter
zbigarray = out_data_array.getArray() zbigarray = out_data_array.getArray()
if zbigarray is None: if zbigarray is None:
zbigarray = out_data_array.initArray(shape=(0,), dtype=ndarray.dtype.fields) zbigarray = out_data_array.initArray(shape=(0,), dtype=ndarray.dtype.fields)
start_array = zbigarray.shape[0] start_array = zbigarray.shape[0]
zbigarray.append(ndarray) zbigarray.append(ndarray)
try: data_array_line = out_data_array.newContent(id=key,
data_array_line = out_array.get(key) portal_type="Data Array Line")
if data_array_line is None: data_array_line.edit(
data_array_line = out_data_array.newContent(id=key, reference=key,
portal_type="Data Array Line") index_expression="%s:%s" %(start_array, zbigarray.shape[0]),
data_array_line.edit(reference=key, )
index_expression="%s:%s" %(start_array, zbigarray.shape[0])
)
except BadRequest:
context.log("Data Array Line already exists")
except ValueError: except ValueError:
context.log("File "+str(key)+ " is not well formated") context.log("File "+str(key)+ " is not well formated")
new_end = new_end + str(key)
progress_indicator.setStringOffsetIndex(end + new_end)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment