-
Notifications
You must be signed in to change notification settings - Fork 5
/
miscparsers.py
47 lines (40 loc) · 1.28 KB
/
miscparsers.py
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
'''
Created on May 3, 2013
@author: egg
'''
from dataparser import DataParser
import datamapper as dm
from datamapper import DataObjectCollection, DataObject, TimeSeries
class ToyDataParser(DataParser):
def parse(self, listofdicts):
doc = DataObjectCollection()
for curdict in listofdicts:
do = DataObject()
for key, val in curdict.items():
do[key] = val
doc.append(do)
return doc
class SineDictParser(DataParser):
''' Expects a single dict from numbers 0..n to sine timeseries(-1..1) '''
def parse(self, sines):
doc = DataObjectCollection()
do = DataObject()
for key, sine in sines.items():
ts = TimeSeries(sine)
ts.sample_rate = 1
# ts.rangex = (-1,1)
do[key] = ts
doc.append(do)
return doc
class MultiSineDictParser(DataParser):
''' Expects a list of dicts from numbers 0..n to sine timeseries(-1..1) '''
def parse(self, sineslist):
doc = DataObjectCollection()
for sines in sineslist:
do = DataObject()
for key, sine in sines.items():
ts = TimeSeries(sine)
ts.sample_rate = 1
do[key] = ts
doc.append(do)
return doc