Train Points Importer


Import Tool for transforming collected hits from Arduino serial port, to ATT readable hit format.


Import points from arduino format

SOURCE FORMAT:
"hit: { [tstamp]:[level] [tstamp]:[level] ... [tstamp]:[level] [side]}"
from file: src/arduino/data/[file]

To internal format

TARGET FORMAT:
"[x_coord],[y_coord],[tstamp],[tstamp], ... ,[tstamp]"
to file: src/python/data/[file]
</span>


Abstract


Let's have a look at the raw data,


In [1]:
!head -10 train_points_import_data/arduino_raw_data.txt


(6,6)
hit: {0:25 1549:4 2757:4 1392:4 2264:7 1764:7 1942:5 2984:5 r}
hit: {0:33 1521:6 2712:4 1364:4 2226:10 1894:10 1905:8 2932:5 r}
hit: {0:34 1554:7 2766:5 1233:4 2273:10 1766:4 1951:12 2993:4 r}
hit: {0:31 1667:6 2878:4 1345:4 2209:4 1880:8 2056:14 2935:4 r}
hit: {0:28 1529:6 2737:5 1211:5 2244:9 1735:4 1920:6 2967:4 r}
hit: {0:35 1525:8 2720:5 1207:6 2237:10 1744:5 1922:5 2939:5 r}
hit: {0:9 1521:10 2746:5 1218:8 2251:9 1744:5 1929:4 2971:4 r}
hit: {0:16 1694:6 2910:5 1372:4 2415:8 1913:6 2098:10 2965:4 r}
hit: {0:5 1703:6 2911:5 1561:4 2416:9 1402:4 2094:6 3136:5 r}

We want to have this data in a more standard format, a CSV file for instance. More like this way:


In [2]:
!head -10 train_points_import_data/processed_data.csv


6,6,0,1549,2757,1392,2264,1764,1942,2984
6,6,0,1521,2712,1364,2226,1894,1905,2932
6,6,0,1554,2766,1233,2273,1766,1951,2993
6,6,0,1667,2878,1345,2209,1880,2056,2935
6,6,0,1529,2737,1211,2244,1735,1920,2967
6,6,0,1525,2720,1207,2237,1744,1922,2939
6,6,0,1521,2746,1218,2251,1744,1929,2971
6,6,0,1694,2910,1372,2415,1913,2098,2965
6,6,0,1703,2911,1561,2416,1402,2094,3136
6,6,0,1690,4420,1211,2230,1731,1909,2930

Data cleaning and preparation

</span>
We are going to create an importer and import the data from the Arduino raw serial into a more readable format, CSV.

First, set libraries path and import the Importer module


In [4]:
# Import points from arduino format:
# 
#   "hit: { [tstamp]:[level] [tstamp]:[level] ... [tstamp]:[level] [side]}"
#   from file: src/arduino/data/[file]
#
# To internal format:
#   "[x_coord],[y_coord],[tstamp],[tstamp], ... ,[tstamp]"
#   to file: src/python/data/[file]

import sys
#sys.path.insert(0, '/home/asanso/workspace/att-spyder/att/src/python/')
sys.path.insert(0, 'i:/dev/workspaces/python/att-workspace/att/src/python/')


import hit.importer.train_points_importer as imp

Create an Importer instance now:


In [5]:
importer = imp.TrainPointsImporter()

Now it is time to set some paths, in order to point the source raw data files and the target CSV files:


In [6]:
str_left_input_file = "../src/arduino/data/train_20160129_left.txt"
str_left_output_file = "../src/python/data/train_points_20160129_left.txt"

That was for the left-side collected hit info.


In [7]:
str_right_input_file = "../src/arduino/data/train_20160129_right.txt"
str_right_output_file = "../src/python/data/train_points_20160129_right.txt"

That was for the right-side collected hit info.
Let's do the left-side import now:


In [8]:
importer.from_file_to_file(str_left_input_file, str_left_output_file)

And the right-side import now:


In [9]:
importer.from_file_to_file(str_right_input_file, str_right_output_file)

In [ ]: