Browse Source

Support datasource kit interface #176 (#177)

* Fix indentation in drop model

* Update datasource-kit version

* GrafanaMetric -> Metric
pull/1/head
rozetko 6 years ago committed by GitHub
parent
commit
d6d0b9f36a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      analytics/models/drop_model.py
  2. 2
      server/package.json
  3. 6
      server/src/models/analytic_unit_model.ts

14
analytics/models/drop_model.py

@ -39,7 +39,7 @@ class DropModel(Model):
segment_from_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['from'], unit='ms')) segment_from_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['from'], unit='ms'))
segment_to_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['to'], unit='ms')) segment_to_index = utils.timestamp_to_index(dataframe, pd.to_datetime(segment['to'], unit='ms'))
segment_data = data[segment_from_index: segment_to_index + 1] segment_data = data[segment_from_index: segment_to_index + 1]
if len(segment_data) == 0: if len(segment_data) == 0:
continue continue
segment_min = min(segment_data) segment_min = min(segment_data)
@ -80,7 +80,7 @@ class DropModel(Model):
convolve_drop = scipy.signal.fftconvolve(labeled_drop, self.model_drop) convolve_drop = scipy.signal.fftconvolve(labeled_drop, self.model_drop)
convolve_list.append(max(auto_convolve)) convolve_list.append(max(auto_convolve))
convolve_list.append(max(convolve_drop)) convolve_list.append(max(convolve_drop))
del_conv_list = [] del_conv_list = []
for segment in segments: for segment in segments:
if segment['deleted']: if segment['deleted']:
@ -106,7 +106,7 @@ class DropModel(Model):
deleted_drop = data[segment_cent_index - self.state['WINDOW_SIZE'] : segment_cent_index + self.state['WINDOW_SIZE'] + 1] deleted_drop = data[segment_cent_index - self.state['WINDOW_SIZE'] : segment_cent_index + self.state['WINDOW_SIZE'] + 1]
deleted_drop = deleted_drop - min(labeled_drop) deleted_drop = deleted_drop - min(labeled_drop)
del_conv_drop = scipy.signal.fftconvolve(deleted_drop, self.model_drop) del_conv_drop = scipy.signal.fftconvolve(deleted_drop, self.model_drop)
del_conv_list.append(max(del_conv_drop)) del_conv_list.append(max(del_conv_drop))
if len(confidences) > 0: if len(confidences) > 0:
self.state['confidence'] = float(min(confidences)) self.state['confidence'] = float(min(confidences))
@ -117,7 +117,7 @@ class DropModel(Model):
self.state['convolve_max'] = float(max(convolve_list)) self.state['convolve_max'] = float(max(convolve_list))
else: else:
self.state['convolve_max'] = self.state['WINDOW_SIZE'] self.state['convolve_max'] = self.state['WINDOW_SIZE']
if len(convolve_list) > 0: if len(convolve_list) > 0:
self.state['convolve_min'] = float(min(convolve_list)) self.state['convolve_min'] = float(min(convolve_list))
else: else:
@ -132,12 +132,12 @@ class DropModel(Model):
self.state['DROP_LENGTH'] = int(max(drop_length_list)) self.state['DROP_LENGTH'] = int(max(drop_length_list))
else: else:
self.state['DROP_LENGTH'] = 1 self.state['DROP_LENGTH'] = 1
if len(del_conv_list) > 0: if len(del_conv_list) > 0:
self.state['conv_del_min'] = float(min(del_conv_list)) self.state['conv_del_min'] = float(min(del_conv_list))
else: else:
self.state['conv_del_min'] = self.state['WINDOW_SIZE'] self.state['conv_del_min'] = self.state['WINDOW_SIZE']
if len(del_conv_list) > 0: if len(del_conv_list) > 0:
self.state['conv_del_max'] = float(max(del_conv_list)) self.state['conv_del_max'] = float(max(del_conv_list))
else: else:
@ -172,7 +172,7 @@ class DropModel(Model):
conv = scipy.signal.fftconvolve(convol_data, pattern_data) conv = scipy.signal.fftconvolve(convol_data, pattern_data)
if conv[self.state['WINDOW_SIZE']*2] > self.state['convolve_max'] * 1.2 or conv[self.state['WINDOW_SIZE']*2] < self.state['convolve_min'] * 0.8: if conv[self.state['WINDOW_SIZE']*2] > self.state['convolve_max'] * 1.2 or conv[self.state['WINDOW_SIZE']*2] < self.state['convolve_min'] * 0.8:
delete_list.append(segment) delete_list.append(segment)
if max(conv) < self.state['conv_del_max'] * 1.02 and max(conv) > self.state['conv_del_min'] * 0.98: if max(conv) < self.state['conv_del_max'] * 1.02 and max(conv) > self.state['conv_del_min'] * 0.98:
delete_list.append(segment) delete_list.append(segment)
else: else:
delete_list.append(segment) delete_list.append(segment)

2
server/package.json

@ -38,7 +38,7 @@
"es6-promise": "^4.2.4", "es6-promise": "^4.2.4",
"event-stream": "^3.3.4", "event-stream": "^3.3.4",
"file-loader": "^1.1.11", "file-loader": "^1.1.11",
"grafana-datasource-kit": "^0.0.3", "grafana-datasource-kit": "^0.0.7",
"jest": "^23.1.1", "jest": "^23.1.1",
"koa": "^2.0.46", "koa": "^2.0.46",
"koa-bodyparser": "^4.2.0", "koa-bodyparser": "^4.2.0",

6
server/src/models/analytic_unit_model.ts

@ -1,6 +1,6 @@
import { Collection, makeDBQ } from '../services/data_service'; import { Collection, makeDBQ } from '../services/data_service';
import { GrafanaMetric } from 'grafana-datasource-kit'; import { Metric } from 'grafana-datasource-kit';
let db = makeDBQ(Collection.ANALYTIC_UNITS); let db = makeDBQ(Collection.ANALYTIC_UNITS);
@ -20,7 +20,7 @@ export class AnalyticUnit {
public name: string, public name: string,
public panelUrl: string, public panelUrl: string,
public type: string, public type: string,
public metric: GrafanaMetric, public metric: Metric,
public id?: AnalyticUnitId, public id?: AnalyticUnitId,
public lastPredictionTime?: number, public lastPredictionTime?: number,
public status?: AnalyticUnitStatus, public status?: AnalyticUnitStatus,
@ -61,7 +61,7 @@ export class AnalyticUnit {
obj.name, obj.name,
obj.panelUrl, obj.panelUrl,
obj.type, obj.type,
GrafanaMetric.fromObject(obj.metric), Metric.fromObject(obj.metric),
obj._id, obj._id,
obj.lastPredictionTime, obj.lastPredictionTime,
obj.status as AnalyticUnitStatus, obj.status as AnalyticUnitStatus,

Loading…
Cancel
Save