Browse Source

upperase literals + server start bugfix

pull/1/head
Alexey Velikiy 6 years ago
parent
commit
1c473d129d
  1. 6
      analytics/analytic_unit_worker.py
  2. 8
      analytics/detectors/pattern_detector.py
  3. 21
      analytics/server.py
  4. 4
      server/src/controllers/analytics_controller.ts
  5. 6
      server/src/services/analytics_service.ts

6
analytics/analytic_unit_worker.py

@ -18,11 +18,11 @@ class AnalyticUnitWorker(object):
try:
type = task['type']
analytic_unit_id = task['analyticUnitId']
if type == "predict":
if type == "PREDICT":
last_prediction_time = task['lastPredictionTime']
pattern = task['pattern']
result = await self.do_predict(analytic_unit_id, last_prediction_time, pattern)
elif type == "learn":
elif type == "LEARN":
segments = task['segments']
pattern = task['pattern']
result = await self.do_learn(analytic_unit_id, segments, pattern)
@ -38,7 +38,7 @@ class AnalyticUnitWorker(object):
# TODO: move result to a class which renders to json for messaging to analytics
result = {
'task': type,
'status': "failed",
'status': "FAILED",
'analyticUnitId': analytic_unit_id,
'error': str(e)
}

8
analytics/detectors/pattern_detector.py

@ -17,13 +17,13 @@ logger = logging.getLogger('analytic_toolset')
def resolve_model_by_pattern(pattern: str) -> models.Model:
if pattern == 'peak':
if pattern == 'PEAK':
return models.PeaksModel()
if pattern == 'drop':
if pattern == 'DROP':
return models.StepModel()
if pattern == 'jump':
if pattern == 'JUMP':
return models.JumpModel()
if pattern == 'custom':
if pattern == 'CUSTOM':
return models.CustomModel()
raise ValueError('Unknown pattern "%s"' % pattern)

21
analytics/server.py

@ -28,24 +28,24 @@ logging_handler.setFormatter(logging_formatter)
root.addHandler(logging_handler)
async def handle_task(payload: str):
async def handle_task(task: object):
try:
task = json.loads(payload)
logger.info("Command is OK")
response_task_payload = json.dumps({
response_task_payload = {
'_taskId': task['_taskId'],
'task': task['type'],
'analyticUnitId': task['analyticUnitId'],
'status': "in progress"
})
'status': "IN_PROGRESS"
}
message = services.server_service.ServerMessage('TASK_RESULT', response_task_payload)
await server_service.send_message(message)
res = await worker.do_task(task)
res['_taskId'] = task['_taskId']
await server_service.send_message(json.dumps(res))
except Exception as e:
@ -53,10 +53,9 @@ async def handle_task(payload: str):
async def handle_message(message: services.ServerMessage):
payload = None
if message.payload is not None:
payload = json.loads(message.payload)
if message.method == 'task':
await handle_task(payload)
if message.method == 'TASK':
await handle_task(message.payload)
def init_services():
logger.info("Starting services...")
@ -70,7 +69,7 @@ def init_services():
return server_service, data_service
async def app_loop():
server_service.handle_loop()
await server_service.handle_loop()
# await asyncio.gather(server_service.handle_loop(), test_file_save())

4
server/src/controllers/analytics_controller.ts

@ -36,7 +36,7 @@ async function onMessage(message: AnalyticsMessage) {
let resolvedMethod = false;
if(message.method === 'TASK_RESULT') {
onTaskResult(JSON.parse(message.payload));
onTaskResult(message.payload);
resolvedMethod = true;
}
@ -85,7 +85,7 @@ async function runTask(task): Promise<any> {
export async function runLearning(id: AnalyticUnit.AnalyticUnitId) {
let segments = getLabeledSegments(id);
AnalyticUnit.setStatus(id, 'learning');
AnalyticUnit.setStatus(id, 'LEARNING');
let unit = AnalyticUnit.findById(id);
let pattern = unit.type;
let task = {

6
server/src/services/analytics_service.ts

@ -38,13 +38,13 @@ export class AnalyticsService {
this._init();
}
public async sendTask(msgObj: any): Promise<void> {
public async sendTask(taskObj: any): Promise<void> {
if(!this._ready) {
return Promise.reject("Analytics is not ready");
}
let message = {
method: 'task',
payload: JSON.stringify(msgObj)
method: 'TASK',
payload: taskObj
}
return this.sendMessage(message);
}

Loading…
Cancel
Save