<commit_before>#!/usr/bin/env python
# this line is needed so the execution happens in python environment

import rospy
from std_msgs.msg import Int64
from std_msgs.msg import Header
from boat_imu.msg import measurements

# number of remembered values
history_length = 5
""" Air pressure history
 AirPressure[0] newest """
airPressure = [0 for x in range(history_length)]
accelerometer = [["header", 0, 0, 0] for x in range(history_length)]
magnetometer = [["header", 0, 0, 0] for x in range(history_length)]
gyroscope = [["header", 0, 0, 0] for x in range(history_length)]
# TODO make this a dictionary, that contains: name, header, values
# maybe even dimension?
print('test')
#rospy.loginfo("some text")
print('test')

def storeIntROS(data, storage):
    """ insert new Int value received from ROS in
    the storage list, remove oldest value
    """
    storage.insert(0,data.data)
    storage.pop()
    rospy.logdebug("add value" + str(storage[0]))
    rospy.logdebug(storage)

def store3dROS(data, storage):
    """ insert new header + three directional measurements
    in the handed over storage list, remove oldest value
    """
    storage.insert(0,[data.header, data.x_value, data.y_value, data.z_value])
    storage.pop()
    rospy.logdebug("add value" + str(storage[0]))
    rospy.logdebug(storage)


def imu_listener():
    rospy.init_node('listener', anonymous=True)
    rospy.loginfo('ros imu listener started')
    rospy.Subscriber("AirPressure", Int64, storeIntROS, airPressure)
    rospy.Subscriber("Accelerometer", measurements, store3dROS, accelerometer)
    rospy.Subscriber("Magnetometer", measurements, store3dROS, magnetometer)
    rospy.Subscriber("Gyroscope", measurements, store3dROS, magnetometer)
    rospy.spin()
                                                    

if __name__ == '__main__':
    imu_listener()

<commit_msg>switch to dictionaries for measurement history<commit_after>#!/usr/bin/env python
# this line is needed so the execution happens in python environment

import rospy
from std_msgs.msg import Int64
from std_msgs.msg import Header
from boat_imu.msg import measurements

# number of remembered values
history_length = 5
""" Air pressure history
 AirPressure[0] newest """
# empty history to initialise storage lists
empty_history = [0 for x in range(history_length)]
empty_header_history = ["header" for x in range(history_length)]


airPressure = {
'name': 'Air Pressure', 
'value': empty_history}

accelerometer = {
'name': 'Accelerometer',
'header': map(str, empty_history),
'x_value': empty_history,
'y_value': empty_history,
'z_value': empty_history
}

magnetometer = {
'name': 'Magnetometer',
'header': map(str, empty_history),
'x_value': empty_history,
'y_value': empty_history,
'z_value': empty_history
}

gyroscope = {
'name': 'Gyroscope',
'header': map(str, empty_history),
'x_value': empty_history,
'y_value': empty_history,
'z_value': empty_history
}

def storeIntROS(data, storage):
    """ insert new Int value received from ROS in
    the storage list, remove oldest value
    """
    storage['value'].insert(0,data.data)
    storage['value'].pop()
    rospy.loginfo(
    "add value " + str(storage['value'][0]) + ' to ' + storage['name'])
    rospy.logdebug(storage)

def store3dROS(data, storage):
    """ insert new header + three directional measurements
    in the handed over storage list, remove oldest value
    """
    storage['header'].insert(0, data.header)
    storage['header'].pop()
    storage['x_value'].insert(0, data.x_value)
    storage['x_value'].pop()
    storage['y_value'].insert(0, data.y_value)
    storage['y_value'].pop()
    storage['z_value'].insert(0, data.z_value)
    storage['z_value'].pop()

    rospy.loginfo(
    'add x_value ' + str(storage['x_value'][0]) + 
    ' y_value ' + str(storage['y_value'][0]) +
    ' z_value ' + str(storage['z_value'][0]) +
    ' to ' + storage['name'])
    rospy.logdebug(storage)


def imu_listener():
    rospy.init_node('listener', anonymous=True)
    rospy.loginfo('ros imu listener started')
    rospy.Subscriber("AirPressure", Int64, storeIntROS, airPressure)
    rospy.Subscriber("Accelerometer", measurements, store3dROS, accelerometer)
    rospy.Subscriber("Magnetometer", measurements, store3dROS, magnetometer)
    rospy.Subscriber("Gyroscope", measurements, store3dROS, gyroscope)
    rospy.spin()
                                                    

if __name__ == '__main__':
    imu_listener()


{'fraction_non_alphanumeric': 0.12955465587044535, 'fraction_numerical': 0.009896536212325686, 'mean_word_length': 4.281472684085511, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1991429', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1411, 'n_words': 366}