@@ 162-199 (lines=38) @@ | ||
159 | ||
160 | self.query["dataset"] = {} |
|
161 | ||
162 | def addStream(self, stream, interpolator="closest", t1=None, t2=None, dt=None, limit=None, i1=None, i2=None, transform=None,colname=None): |
|
163 | """Adds the given stream to the query construction. Additionally, you can choose the interpolator to use for this stream, as well as a special name |
|
164 | for the column in the returned dataset. If no column name is given, the full stream path will be used. |
|
165 | ||
166 | addStream also supports Merge queries. You can insert a merge query instead of a stream, but be sure to name the column:: |
|
167 | ||
168 | d = Dataset(cdb, t1=time.time()-1000,t2=time.time(),dt=10.) |
|
169 | d.addStream("temperature","average") |
|
170 | d.addStream("steps","sum") |
|
171 | ||
172 | m = Merge(cdb) |
|
173 | m.addStream("mystream") |
|
174 | m.addStream("mystream2") |
|
175 | d.addStream(m,colname="mycolumn") |
|
176 | ||
177 | result = d.run() |
|
178 | """ |
|
179 | ||
180 | streamquery = query_maker(t1, t2, limit, i1, i2, transform) |
|
181 | param_stream(self.cdb, streamquery, stream) |
|
182 | ||
183 | streamquery["interpolator"] = interpolator |
|
184 | ||
185 | if colname is None: |
|
186 | # What do we call this column? |
|
187 | if isinstance(stream, six.string_types): |
|
188 | colname = stream |
|
189 | elif isinstance(stream, Stream): |
|
190 | colname = stream.path |
|
191 | else: |
|
192 | raise Exception( |
|
193 | "Could not find a name for the column! use the 'colname' parameter.") |
|
194 | ||
195 | if colname in self.query["dataset"] or colname is "x": |
|
196 | raise Exception( |
|
197 | "The column name either exists, or is labeled 'x'. Use the colname parameter to change the column name.") |
|
198 | ||
199 | self.query["dataset"][colname] = streamquery |
|
200 | ||
201 | def run(self): |
|
202 | """Runs the dataset query, and returns the result""" |
|
@@ 132-160 (lines=29) @@ | ||
129 | ||
130 | """ |
|
131 | ||
132 | def __init__(self, cdb, x=None, t1=None, t2=None, dt=None, limit=None, i1=None, i2=None, transform=None, itransform=None): |
|
133 | """In order to begin dataset generation, you need to specify the reference time range or stream. |
|
134 | ||
135 | To generate a T-dataset:: |
|
136 | d = Dataset(cdb, t1=start, t2=end, dt=tchange) |
|
137 | To generate a Y-dataset:: |
|
138 | d = Dataset(cdb,"mystream", i1=start, i2=end) |
|
139 | ||
140 | Note that everywhere you insert a stream name, you are also free to insert Stream objects |
|
141 | or even Merge queries. The Dataset query in ConnectorDB supports merges natively for each field. |
|
142 | ||
143 | The only "special" field in this query is the "itransform". This is a special transform to run on the |
|
144 | entire row of data after the all of the interpolations complete. |
|
145 | """ |
|
146 | self.cdb = cdb |
|
147 | self.query = query_maker(t1, t2, limit, i1, i2, transform) |
|
148 | ||
149 | if x is not None: |
|
150 | if dt is not None: |
|
151 | raise Exception( |
|
152 | "Can't do both T-dataset and X-dataset at the same time") |
|
153 | # Add the stream to the query as the X-dataset |
|
154 | param_stream(self.cdb, self.query, x) |
|
155 | elif dt is not None: |
|
156 | self.query["dt"] = dt |
|
157 | else: |
|
158 | raise Exception("Dataset must have either x or dt parameter") |
|
159 | ||
160 | self.query["dataset"] = {} |
|
161 | ||
162 | def addStream(self, stream, interpolator="closest", t1=None, t2=None, dt=None, limit=None, i1=None, i2=None, transform=None,colname=None): |
|
163 | """Adds the given stream to the query construction. Additionally, you can choose the interpolator to use for this stream, as well as a special name |