示例#1
0
 def end_batch(self, batch_meta):
     x, y = self._align()
     result = lmtest.grangertest(x, y, order=self._order)
     p_value = (float(result[3][1]))
     response = udf_pb2.Response()
     response.point.time = batch_meta.tmax
     response.point.fieldsDouble["grangervalue"] = p_value
     self._agent.write_response(response)
示例#2
0
 def info(self):
     response = udf_pb2.Response()
     response.info.wants = udf_pb2.BATCH
     response.info.provides = udf_pb2.STREAM
     response.info.options['field1'].valueTypes.append(udf_pb2.STRING)
     response.info.options['field2'].valueTypes.append(udf_pb2.STRING)
     response.info.options['order'].valueTypes.append(udf_pb2.INT)
     return response
示例#3
0
    def init(self, init_req):
        success = True
        msg = ''
        for opt in init_req.options:
            if opt.name == 'order':
                self._order = opt.values[0].intValue

        response = udf_pb2.Response()
        response.init.success = success
        response.init.error = msg
        return response
示例#4
0
 def info(self):
     print("Info for Spirit", file=sys.stderr)
     print("Info for Spirit", file=self._logfile)
     self._logfile.flush()
     response = udf_pb2.Response()
     response.info.wants = udf_pb2.STREAM
     response.info.provides = udf_pb2.STREAM
     #response.info.options['field'].valueTypes.append(udf_pb2.STRING)
     response.info.options['n'].valueTypes.append(
         udf_pb2.INT)  # the number of components (raw data)
     response.info.options['k'].valueTypes.append(
         udf_pb2.INT)  # the number of components (projection)
     return response
示例#5
0
    def point(self, point):
        #print("POINT", file=sys.stderr)
        value = point.fieldsDouble["value"]
        tag = point.tags["depth"]
        #print ("{} {} {} {}".format("Point:", value, tag, self._count), file=self._logfile)
        self._point[tag] = float(value)
        #print ("Got a point", file=self._logfile)
        #print (value, file=self._logfile)
        #print (tag, file=self._logfile)
        #print (self._count, file=self._logfile)
        self._count += 1
        #self._logfile.flush()
        if self._count == self._n:
            print("CALCULATING SPIRIT", file=sys.stderr)
            #print ("self._count == {}".format(self._count), file=self._logfile)
            #print ("length of items list = {}".format(len(self._point.items()), file=self._logfile))
            x = np.array([[
                i[1] for i in sorted(self._point.items(), key=lambda ii: ii[0])
            ]]).T
            x_df = pd.DataFrame(x)
            ff = x_df.fillna(method='ffill')
            x = ff.as_matrix()
            #print("count = {}".format(self._count), file=self._logfile)
            #print("shape of update {}".format(x.shape), file=self._logfile)
            y, xr, rel_err = self._se.update(x)
            y = -y
            #print("y = {}".format(y), file=self._logfile)
            #print("y[0,0] = {}".format(y), file=self._logfile)
            self._count = 0
            self._point = {tag.strip(): None for tag in self._tags}
            response = udf_pb2.Response()
            #print ("type of point.time = {}".format(type(point.time)), file=self._logfile)
            #print ("point.time = {}".format(point.time), file=self._logfile)
            #self._logfile.flush()
            #print ("response.point.time before = {}".format(response.point.time, file=self._logfile))
            response.point.time = point.time
            #print ("point.time assigned to response.point.time is {}".format(response.point.time), file=self._logfile)
            #self._logfile.flush()
            #print ("response.point.time after = {}".format(response.point.time, file=self._logfile))
            response.point.fieldsDouble["hv1value"] = y[0, 0]

            #response.point.fieldsDouble["hv2value"] = y[0,1]

            #print ("WRITING SPIRIT RESPONSE", file=sys.stderr)
            self._agent.write_response(response, True)
示例#6
0
 def init(self, init_req):
     print("INIT", file=sys.stderr)
     print("initializing", file=self._logfile)
     self._logfile.flush()
     success = True
     msg = ''
     for opt in init_req.options:
         if opt.name == 'k':
             self._k = opt.values[0].intValue
         if opt.name == 'n':
             self._n = opt.values[0].intValue
     if self._n and self._k:
         self._se = SPIRIT(self._n, self._k)
         self._point = {tag.strip(): None for tag in self._tags}
     response = udf_pb2.Response()
     response.init.success = success
     response.init.error = msg
     return response
示例#7
0
 def snapshot(self):
     print("SNAPSHOT", file=sys.stderr)
     response = udf_pb2.Response()
     response.snapshot.snapshot = ''
     return response
示例#8
0
 def snapshot(self):
     response = udf_pb2.Response()
     response.snapshot.snapshot = ''
     return response