|  | @@ 165-202 (lines=38) @@ | 
                                                            
                                    | 162 |  |  | 
                                                            
                                    | 163 |  |         self.query["dataset"] = {} | 
                                                            
                                    | 164 |  |  | 
                                                            
                                    | 165 |  |     def addStream(self, stream, interpolator="closest", t1=None, t2=None, dt=None, limit=None, i1=None, i2=None, transform=None,colname=None): | 
                                                            
                                    | 166 |  |         """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 | 
                                                            
                                    | 167 |  |         for the column in the returned dataset. If no column name is given, the full stream path will be used. | 
                                                            
                                    | 168 |  |  | 
                                                            
                                    | 169 |  |         addStream also supports Merge queries. You can insert a merge query instead of a stream, but be sure to name the column:: | 
                                                            
                                    | 170 |  |  | 
                                                            
                                    | 171 |  |             d = Dataset(cdb, t1=time.time()-1000,t2=time.time(),dt=10.) | 
                                                            
                                    | 172 |  |             d.addStream("temperature","average") | 
                                                            
                                    | 173 |  |             d.addStream("steps","sum") | 
                                                            
                                    | 174 |  |  | 
                                                            
                                    | 175 |  |             m = Merge(cdb) | 
                                                            
                                    | 176 |  |             m.addStream("mystream") | 
                                                            
                                    | 177 |  |             m.addStream("mystream2") | 
                                                            
                                    | 178 |  |             d.addStream(m,colname="mycolumn") | 
                                                            
                                    | 179 |  |  | 
                                                            
                                    | 180 |  |             result = d.run() | 
                                                            
                                    | 181 |  |         """ | 
                                                            
                                    | 182 |  |  | 
                                                            
                                    | 183 |  |         streamquery = query_maker(t1, t2, limit, i1, i2, transform) | 
                                                            
                                    | 184 |  |         param_stream(self.cdb, streamquery, stream) | 
                                                            
                                    | 185 |  |  | 
                                                            
                                    | 186 |  |         streamquery["interpolator"] = interpolator | 
                                                            
                                    | 187 |  |  | 
                                                            
                                    | 188 |  |         if colname is None: | 
                                                            
                                    | 189 |  |             # What do we call this column? | 
                                                            
                                    | 190 |  |             if isinstance(stream, six.string_types): | 
                                                            
                                    | 191 |  |                 colname = stream | 
                                                            
                                    | 192 |  |             elif isinstance(stream, Stream): | 
                                                            
                                    | 193 |  |                 colname = stream.path | 
                                                            
                                    | 194 |  |             else: | 
                                                            
                                    | 195 |  |                 raise Exception( | 
                                                            
                                    | 196 |  |                     "Could not find a name for the column! use the 'colname' parameter.") | 
                                                            
                                    | 197 |  |  | 
                                                            
                                    | 198 |  |         if colname in self.query["dataset"] or colname is "x": | 
                                                            
                                    | 199 |  |             raise Exception( | 
                                                            
                                    | 200 |  |                 "The column name either exists, or is labeled 'x'. Use the colname parameter to change the column name.") | 
                                                            
                                    | 201 |  |  | 
                                                            
                                    | 202 |  |         self.query["dataset"][colname] = streamquery | 
                                                            
                                    | 203 |  |  | 
                                                            
                                    | 204 |  |     def run(self): | 
                                                            
                                    | 205 |  |         """Runs the dataset query, and returns the result""" | 
                                                                                
                                |  | @@ 132-163 (lines=32) @@ | 
                                                            
                                    | 129 |  |  | 
                                                            
                                    | 130 |  |     """ | 
                                                            
                                    | 131 |  |  | 
                                                            
                                    | 132 |  |     def __init__(self, cdb, x=None, t1=None, t2=None, dt=None, limit=None, i1=None, i2=None, transform=None, posttransform=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 an X-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 "posttransform". 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 |  |         if posttransform is not None: | 
                                                            
                                    | 161 |  |             self.query["posttransform"] = posttransform | 
                                                            
                                    | 162 |  |  | 
                                                            
                                    | 163 |  |         self.query["dataset"] = {} | 
                                                            
                                    | 164 |  |  | 
                                                            
                                    | 165 |  |     def addStream(self, stream, interpolator="closest", t1=None, t2=None, dt=None, limit=None, i1=None, i2=None, transform=None,colname=None): | 
                                                            
                                    | 166 |  |         """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 |