You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by eb...@apache.org on 2020/05/13 10:37:25 UTC

[incubator-streampipes] branch timeseries-labeling created (now f672e44)

This is an automated email from the ASF dual-hosted git repository.

ebi pushed a change to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git.


      at f672e44  Add updating labels in database after leaving labeling mode

This branch includes the following new commits:

     new 215163e  Add endpoint for updating labels in database
     new 00f4c86  Add update method of labels in database to new endpoint
     new 539ac10  Add label update request to DataLake-REST-Service
     new b70b3a5  Add label column to data keys
     new ae20daa  Add label information to data result
     new 98d95b7  Add measure name to data result
     new f645dc9  Add (if existing) labels obtained from database to line chart
     new 0ace997  Refactor method to add coloured shapes to line chart based on label
     new f672e44  Add updating labels in database after leaving labeling mode

The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-streampipes] 03/09: Add label update request to DataLake-REST-Service

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 539ac1090b5074dcbabce143783816e0b433ca22
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 10:28:24 2020 +0200

    Add label update request to DataLake-REST-Service
---
 .../app/core-services/datalake/datalake-rest.service.ts  | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/ui/src/app/core-services/datalake/datalake-rest.service.ts b/ui/src/app/core-services/datalake/datalake-rest.service.ts
index 5a5e960..59caebb 100644
--- a/ui/src/app/core-services/datalake/datalake-rest.service.ts
+++ b/ui/src/app/core-services/datalake/datalake-rest.service.ts
@@ -73,7 +73,7 @@ export class DatalakeRestService {
     }
 
     getGroupedDataAutoAggergation(index, startDate, endDate, groupingTag) {
-            return this.http.get<GroupedDataResult>(this.dataLakeUrlV3 + '/data/' + index + '/' + startDate + '/' + endDate + '/grouping/' + groupingTag);
+        return this.http.get<GroupedDataResult>(this.dataLakeUrlV3 + '/data/' + index + '/' + startDate + '/' + endDate + '/grouping/' + groupingTag);
     }
 
 
@@ -81,7 +81,7 @@ export class DatalakeRestService {
         @deprecate
      */
     getFile(index, format) {
-        const request = new HttpRequest('GET', this.dataLakeUrlV3 + '/data/' + index + "?format=" + format,  {
+        const request = new HttpRequest('GET', this.dataLakeUrlV3 + '/data/' + index + "?format=" + format, {
             reportProgress: true,
             responseType: 'text'
         });
@@ -89,7 +89,7 @@ export class DatalakeRestService {
     }
 
     downloadRowData(index, format) {
-        const request = new HttpRequest('GET', this.dataLakeUrlV3 + '/data/' + index + "/download?format=" + format,  {
+        const request = new HttpRequest('GET', this.dataLakeUrlV3 + '/data/' + index + "/download?format=" + format, {
             reportProgress: true,
             responseType: 'text'
         });
@@ -105,4 +105,12 @@ export class DatalakeRestService {
         return this.http.request(request)
     }
 
-}
\ No newline at end of file
+    saveLabelsInDatabase(index, startDate, endDate, label) {
+        const request = new HttpRequest('POST', this.dataLakeUrlV3 + '/data/' + index + '/labeling/' + startDate + '/' +
+            endDate + '/' + label,  {}, {
+            reportProgress: true,
+            responseType: 'text'
+        });
+        return this.http.request(request);
+    }
+}


[incubator-streampipes] 08/09: Refactor method to add coloured shapes to line chart based on label

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 0ace997e5de062b4e3c68d0e5a5e9be81af133a3
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 11:06:49 2020 +0200

    Refactor method to add coloured shapes to line chart based on label
---
 .../app/core-ui/linechart/lineChart.component.ts   | 92 +++++++++++++++-------
 1 file changed, 62 insertions(+), 30 deletions(-)

diff --git a/ui/src/app/core-ui/linechart/lineChart.component.ts b/ui/src/app/core-ui/linechart/lineChart.component.ts
index dc34750..c966b5c 100644
--- a/ui/src/app/core-ui/linechart/lineChart.component.ts
+++ b/ui/src/app/core-ui/linechart/lineChart.component.ts
@@ -160,7 +160,11 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
                 });
             });
             this.dataToDisplay = tmp;
+            this.dataToDisplay['labels'] = transformedData.labels;
 
+            if (this.dataToDisplay['labels'] !== undefined && this.dataToDisplay['labels'].length > 0) {
+                this.addInitialColouredShapesToGraph();
+            }
 
         } else {
             this.dataToDisplay = undefined;
@@ -348,36 +352,7 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
                         }
 
                         // adding coloured shape (based on selected label) to graph (equals selected time interval)
-                        const color = this.colorService.getColor(result);
-                        const shape = {
-                            // shape: rectangle
-                            type: 'rect',
-
-                            // x-reference is assigned to the x-values
-                            xref: 'x',
-
-                            // y-reference is assigned to the plot paper [0,1]
-                            yref: 'paper',
-                            y0: 0,
-                            y1: 1,
-
-                            // start x: left side of selected time interval
-                            x0: this.selectedStartX,
-                            // end x: right side of selected time interval
-                            x1: this.selectedEndX,
-
-                            // adding color
-                            fillcolor: color,
-
-                            // opacity of 20%
-                            opacity: 0.2,
-
-                            line: {
-                                width: 0
-                            }
-                        };
-
-                        this.graph.layout.shapes.push(shape);
+                        this.addShapeToGraph(this.selectedStartX, this.selectedEndX, this.colorService.getColor(result));
 
                         // remain in selection dragmode if labeling mode is still activated
                         if (this.labelingModeOn) {
@@ -468,4 +443,61 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
         // changing dragmode to 'zoom'
         this.graph.layout.dragmode = 'zoom';
     }
+
+    private addInitialColouredShapesToGraph() {
+        let selectedLabel = undefined;
+        let indices = [];
+        for (const label in this.dataToDisplay['labels']) {
+            if (selectedLabel !== this.dataToDisplay['labels'][label] && indices.length > 0) {
+                const startdate = new Date(this.dataToDisplay[0]['x'][indices[0]]).getTime();
+                const enddate = new Date(this.dataToDisplay[0]['x'][indices[indices.length - 1]]).getTime();
+                const color = this.colorService.getColor(selectedLabel);
+
+                this.addShapeToGraph(startdate, enddate, color);
+
+                selectedLabel = undefined;
+                indices = [];
+                indices.push(label);
+            } else {
+                indices.push(label);
+            }
+            selectedLabel = this.dataToDisplay['labels'][label];
+        }
+        const last_start = new Date(this.dataToDisplay[0]['x'][indices[0]]).getTime();
+        const last_end = new Date(this.dataToDisplay[0]['x'][indices[indices.length - 1]]).getTime();
+        const last_color = this.colorService.getColor(selectedLabel);
+
+        this.addShapeToGraph(last_start, last_end, last_color);
+    }
+
+    private addShapeToGraph(start, end, color) {
+        const shape = {
+        // shape: rectangle
+        type: 'rect',
+
+        // x-reference is assigned to the x-values
+        xref: 'x',
+
+        // y-reference is assigned to the plot paper [0,1]
+        yref: 'paper',
+        y0: 0,
+        y1: 1,
+
+        // start x: left side of selected time interval
+        x0: start,
+        // end x: right side of selected time interval
+        x1: end,
+
+        // adding color
+        fillcolor: color,
+
+        // opacity of 20%
+        opacity: 0.2,
+
+        line: {
+            width: 0
+        }
+        };
+        this.graph.layout.shapes.push(shape);
+    }
 }


[incubator-streampipes] 05/09: Add label information to data result

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit ae20daac95b0af18c84c3747facb79259e12abb2
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 10:45:42 2020 +0200

    Add label information to data result
---
 ui/src/app/core-model/datalake/DataResult.ts        |  3 ++-
 ui/src/app/core-ui/linechart/lineChart.component.ts | 11 ++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/ui/src/app/core-model/datalake/DataResult.ts b/ui/src/app/core-model/datalake/DataResult.ts
index 1b8096a..bf0c051 100644
--- a/ui/src/app/core-model/datalake/DataResult.ts
+++ b/ui/src/app/core-model/datalake/DataResult.ts
@@ -20,4 +20,5 @@ export class DataResult {
     total: number;
     headers: string[];
     rows: any[];
-}
\ No newline at end of file
+    labels: string[];
+}
diff --git a/ui/src/app/core-ui/linechart/lineChart.component.ts b/ui/src/app/core-ui/linechart/lineChart.component.ts
index 3f3f015..39cc377 100644
--- a/ui/src/app/core-ui/linechart/lineChart.component.ts
+++ b/ui/src/app/core-ui/linechart/lineChart.component.ts
@@ -155,6 +155,8 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
             });
             this.dataToDisplay = tmp;
 
+
+
             /**
              * TODO: fetching stored labels, filling this.labels and drawing related shapes
              */
@@ -189,20 +191,24 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
         }
     }
 
-    transformData(data: DataResult, xKey: String): DataResult {
+    transformData(data: DataResult, xKey: string): DataResult {
         const tmp: any[] = [];
 
         const dataKeys = [];
+        const label_column = [];
 
         data.rows.forEach(row => {
             data.headers.forEach((headerName, index) => {
                 if (!dataKeys.includes(index) && typeof row[index] == 'number') {
                     dataKeys.push(index);
+                } else if (!label_column.includes(index) && typeof  row[index] == 'string' && data.headers[index] == "sp_internal_label") {
+                    label_column.push(index);
                 }
             });
         });
 
         const indexXkey = data.headers.findIndex(headerName => headerName === this.xKey);
+        const labels = [];
 
         dataKeys.forEach(key => {
             const headerName = data.headers[key];
@@ -218,9 +224,12 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
                    } else {
                        tmp[index].y.push(null);
                    }
+               } else if (label_column.length > 0 && label_column.includes(index)) {
+                   labels.push(row[index]);
                }
            });
         });
+        data.labels = labels;
         data.rows = tmp;
 
         return data;


[incubator-streampipes] 09/09: Add updating labels in database after leaving labeling mode

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit f672e44cfdcc0562b95d356da679b3c971f136b1
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 11:10:58 2020 +0200

    Add updating labels in database after leaving labeling mode
---
 .../app/core-ui/linechart/lineChart.component.ts   | 58 +++++++++++++++++++---
 1 file changed, 52 insertions(+), 6 deletions(-)

diff --git a/ui/src/app/core-ui/linechart/lineChart.component.ts b/ui/src/app/core-ui/linechart/lineChart.component.ts
index c966b5c..49efcab 100644
--- a/ui/src/app/core-ui/linechart/lineChart.component.ts
+++ b/ui/src/app/core-ui/linechart/lineChart.component.ts
@@ -21,6 +21,7 @@ import { MatDialog } from '@angular/material/dialog';
 import { PlotlyService } from 'angular-plotly.js';
 import { DataResult } from '../../core-model/datalake/DataResult';
 import { GroupedDataResult } from '../../core-model/datalake/GroupedDataResult';
+import { DatalakeRestService } from '../../core-services/datalake/datalake-rest.service';
 import { BaseChartComponent } from '../chart/baseChart.component';
 import { ChangeChartmodeDialog } from './labeling-tool/dialogs/change-chartmode/change-chartmode.dialog';
 import { LabelingDialog } from './labeling-tool/dialogs/labeling/labeling.dialog';
@@ -37,7 +38,7 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
     @Output() zoomEvent =  new EventEmitter<[number, number]>();
 
     constructor(public dialog: MatDialog, public plotlyService: PlotlyService, public colorService: ColorService,
-                public renderer: Renderer2) {
+                public renderer: Renderer2, private restService: DatalakeRestService) {
         super();
     }
 
@@ -56,6 +57,9 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
     // indicator variable if labeling mode is activated
     private labelingModeOn = false;
 
+    // indicator variable if labels has been changed
+    private changedLabels = false;
+
     updatemenus = [
         {
             buttons: [
@@ -146,7 +150,7 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
                 transformedData.rows.forEach(serie => {
                     if (serie.name === key) {
                         tmp.push(serie);
-
+                       
                         // adding customdata property in order to store labels in graph
                         if (transformedData.labels !== undefined && transformedData.labels.length !== 0) {
                             serie['customdata'] = transformedData.labels;
@@ -345,11 +349,9 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
                             for (const point of series['selectedpoints']) {
                                 series['customdata'][point] = result;
                             }
-
-                            /**
-                             * TODO: saving labels persistently in database
-                             */
                         }
+                        this.dataToDisplay['labels'] = this.dataToDisplay[0]['customdata'];
+                        this.setChangedLabels(true);
 
                         // adding coloured shape (based on selected label) to graph (equals selected time interval)
                         this.addShapeToGraph(this.selectedStartX, this.selectedEndX, this.colorService.getColor(result));
@@ -442,6 +444,42 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
 
         // changing dragmode to 'zoom'
         this.graph.layout.dragmode = 'zoom';
+
+        // saving labels persistently
+        if (this.getChangedLabels()) {
+            this.saveLabelsInDatabase();
+        }
+    }
+
+    private saveLabelsInDatabase() {
+        let currentLabel = undefined;
+        let indices = [];
+        for (const label in this.dataToDisplay['labels']) {
+            if (currentLabel !== this.dataToDisplay['labels'][label] && indices.length > 0) {
+                const startdate = new Date(this.dataToDisplay[0]['x'][indices[0]]).getTime() - 1;
+                const enddate = new Date(this.dataToDisplay[0]['x'][indices[indices.length - 1]]).getTime() + 1;
+                this.restService.saveLabelsInDatabase(this.dataToDisplay['measureName'], startdate, enddate, currentLabel).subscribe(
+                res => {
+                 // console.log('Successfully wrote label ' + currentLabel + ' into database.');
+                }
+                );
+                currentLabel = undefined;
+                indices = [];
+                indices.push(label);
+            } else {
+                indices.push(label);
+            }
+
+            currentLabel = this.dataToDisplay['labels'][label];
+        }
+        const last_startdate = new Date(this.dataToDisplay[0]['x'][indices[0]]).getTime() - 1;
+        const last_enddate = new Date(this.dataToDisplay[0]['x'][indices[indices.length - 1]]).getTime() + 1;
+        this.restService.saveLabelsInDatabase(this.dataToDisplay['measureName'], last_startdate, last_enddate, currentLabel).subscribe(
+            res => {
+                 // console.log('Successfully wrote label ' + currentLabel + ' in last iterastion into database.');
+            });
+        this.setChangedLabels(false);
+
     }
 
     private addInitialColouredShapesToGraph() {
@@ -500,4 +538,12 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
         };
         this.graph.layout.shapes.push(shape);
     }
+
+    public setChangedLabels(state: boolean) {
+        this.changedLabels = state;
+    }
+
+    public getChangedLabels() {
+        return this.changedLabels;
+    }
 }


[incubator-streampipes] 01/09: Add endpoint for updating labels in database

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 215163efeffd730196059301f74302cdc78431f6
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 09:27:05 2020 +0200

    Add endpoint for updating labels in database
---
 .../rest/impl/datalake/DataLakeResourceV3.java     | 24 +++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java
index 2eb79f9..f845cbb 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java
@@ -26,16 +26,17 @@ import org.apache.streampipes.rest.impl.datalake.model.DataResult;
 import org.apache.streampipes.rest.impl.datalake.model.GroupedDataResult;
 import org.apache.streampipes.rest.impl.datalake.model.PageResult;
 import org.apache.streampipes.rest.shared.annotation.GsonWithIds;
+import org.influxdb.InfluxDB;
+import org.influxdb.dto.Point;
 
 import java.io.IOException;
 import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -156,6 +157,7 @@ public class DataLakeResourceV3 extends AbstractRestInterface {
     String aggregationValue = info.getQueryParameters().getFirst("aggregationValue");
 
     DataResult result;
+
     try {
       if (aggregationUnit != null && aggregationValue != null) {
           result = dataLakeManagement.getEvents(index, startdate, enddate, aggregationUnit,
@@ -208,4 +210,16 @@ public class DataLakeResourceV3 extends AbstractRestInterface {
             .build();
   }
 
+  @POST
+  @Produces(MediaType.TEXT_PLAIN)
+  @Path("/data/{index}/labeling/{startdate}/{enddate}/{label}")
+    public Response labelData(@PathParam("index") String index,
+                              @PathParam("startdate") long startdate,
+                              @PathParam("enddate") long enddate,
+                              @PathParam("label") String label) {
+    
+    return Response.ok("Successfully updated database.", MediaType.TEXT_PLAIN).build();
+  }
+
+
 }


[incubator-streampipes] 04/09: Add label column to data keys

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit b70b3a5518cc3900676a1d73154b9fc66d16245c
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 10:35:30 2020 +0200

    Add label column to data keys
---
 .../data-explorer/explorer/explorer.component.ts   | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/ui/src/app/data-explorer/explorer/explorer.component.ts b/ui/src/app/data-explorer/explorer/explorer.component.ts
index 8320614..20a01e5 100644
--- a/ui/src/app/data-explorer/explorer/explorer.component.ts
+++ b/ui/src/app/data-explorer/explorer/explorer.component.ts
@@ -225,7 +225,8 @@ export class ExplorerComponent implements OnInit {
     }
 
     processReceivedData(res) {
-        if(res.total > 0) {
+        if (res.total > 0) {
+            res.measureName = this.selectedInfoResult.measureName;
             this.data = res as DataResult;
             this.noDateFoundinTimeRange = false;
             if (this.yAxesKeys.length === 0) {
@@ -259,7 +260,7 @@ export class ExplorerComponent implements OnInit {
         this.selectedInfoResult = this._filter(index)[0];
         this.selectedInfoResult.eventSchema.eventProperties.forEach(property => {
 
-            //Check if property is Primitive (only primitives has a runtimeType
+            //Check if property is Primitive (only primitives has a runtimeType)
             if (property['runtimeType'] !== undefined) {
                 if (property['propertyScope'] !== undefined && property['propertyScope'] === 'DIMENSION_PROPERTY') {
                     this.dimensionProperties.push(property['runtimeName'])
@@ -271,6 +272,11 @@ export class ExplorerComponent implements OnInit {
 
                     this.dataKeys.push(property['runtimeName']);
                 }
+                else if (this.isLabelProperty(property) &&
+                    (property['domainProperties'] === undefined || (property.domainProperty !== 'http://schema.org/DateTime' &&
+                        property['domainProperties'][0] != 'http://schema.org/DateTime'))) {
+                    this.dataKeys.push(property['runtimeName']);
+                }
             } else {
                 //list and nested properties
                 this.dataKeys.push(property['runtimeName'])
@@ -402,6 +408,16 @@ export class ExplorerComponent implements OnInit {
         }
     }
 
+    isLabelProperty(prop) {
+        if (prop.runtimeType === 'http://www.w3.org/2001/XMLSchema#string' &&
+           prop.runtimeName === 'sp_internal_label') {
+
+            return true;
+        } else {
+            return false;
+        }
+    }
+
     zoomEventHandler(timeRange) {
       this.selectedTimeUnit = 'Custom';
       if (timeRange[0] !== undefined) {
@@ -409,4 +425,4 @@ export class ExplorerComponent implements OnInit {
       }
       this.loadData(true);
     }
-}
\ No newline at end of file
+}


[incubator-streampipes] 07/09: Add (if existing) labels obtained from database to line chart

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit f645dc950f0bde6200820a622e3dd73f6f087534
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 10:58:27 2020 +0200

    Add (if existing) labels obtained from database to line chart
---
 ui/src/app/core-ui/linechart/lineChart.component.ts | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/ui/src/app/core-ui/linechart/lineChart.component.ts b/ui/src/app/core-ui/linechart/lineChart.component.ts
index 39cc377..dc34750 100644
--- a/ui/src/app/core-ui/linechart/lineChart.component.ts
+++ b/ui/src/app/core-ui/linechart/lineChart.component.ts
@@ -141,13 +141,19 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
     displayData(transformedData: DataResult, yKeys: string[]) {
         if (this.yKeys.length > 0) {
             const tmp = [];
+            tmp['measureName'] = transformedData.measureName;
             this.yKeys.forEach(key => {
                 transformedData.rows.forEach(serie => {
                     if (serie.name === key) {
                         tmp.push(serie);
 
                         // adding customdata property in order to store labels in graph
-                        serie['customdata'] = Array(serie['x'].length).fill('');
+                        if (transformedData.labels !== undefined && transformedData.labels.length !== 0) {
+                            serie['customdata'] = transformedData.labels;
+                        }
+                        else {
+                            serie['customdata'] = Array(serie['x'].length).fill('');
+                        }
                         // adding custom hovertemplate in order to display labels in graph
                         serie['hovertemplate'] = 'y: %{y}<br>' + 'x: %{x}<br>' + 'label: %{customdata}';
                     }
@@ -156,14 +162,8 @@ export class LineChartComponent extends BaseChartComponent implements OnChanges
             this.dataToDisplay = tmp;
 
 
-
-            /**
-             * TODO: fetching stored labels, filling this.labels and drawing related shapes
-             */
-
         } else {
             this.dataToDisplay = undefined;
-
         }
     }
 


[incubator-streampipes] 06/09: Add measure name to data result

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 98d95b707b30ab3e5d1877d8db113a004ca31c89
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 10:56:18 2020 +0200

    Add measure name to data result
---
 ui/src/app/core-model/datalake/DataResult.ts | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ui/src/app/core-model/datalake/DataResult.ts b/ui/src/app/core-model/datalake/DataResult.ts
index bf0c051..1ef85b9 100644
--- a/ui/src/app/core-model/datalake/DataResult.ts
+++ b/ui/src/app/core-model/datalake/DataResult.ts
@@ -17,6 +17,7 @@
  */
 
 export class DataResult {
+    measureName: string;
     total: number;
     headers: string[];
     rows: any[];


[incubator-streampipes] 02/09: Add update method of labels in database to new endpoint

Posted by eb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ebi pushed a commit to branch timeseries-labeling
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git

commit 00f4c86dedc8c10a783f1cbe58d780dfcec91f71
Author: Daniel Ebi <eb...@fzi.de>
AuthorDate: Wed May 13 09:36:44 2020 +0200

    Add update method of labels in database to new endpoint
---
 .../rest/impl/datalake/DataLakeManagementV3.java   | 45 +++++++++++++++++++++-
 .../rest/impl/datalake/DataLakeResourceV3.java     |  4 +-
 2 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeManagementV3.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeManagementV3.java
index edcc375..c6ef4ac 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeManagementV3.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeManagementV3.java
@@ -22,6 +22,7 @@ import com.google.gson.Gson;
 import okhttp3.OkHttpClient;
 import org.influxdb.InfluxDB;
 import org.influxdb.InfluxDBFactory;
+import org.influxdb.dto.Point;
 import org.influxdb.dto.Query;
 import org.influxdb.dto.QueryResult;
 import org.apache.streampipes.config.backend.BackendConfig;
@@ -93,7 +94,6 @@ public class DataLakeManagementV3 {
 
     DataResult dataResult = convertResult(result);
     influxDB.close();
-
     return dataResult;
   }
 
@@ -521,4 +521,47 @@ public class DataLakeManagementV3 {
     }
   }
 
+  public void updateLabels(String index, long startdate, long enddate, String label) {
+    DataResult queryResult = getEvents(index, startdate, enddate);
+    Map<String, String> headerWithTypes = getHeadersWithTypes(index);
+    List<String> headers = queryResult.getHeaders();
+
+    InfluxDB influxDB = getInfluxDBClient();
+    influxDB.setDatabase(BackendConfig.INSTANCE.getInfluxDatabaseName());
+
+    for (List<Object> row : queryResult.getRows()) {
+      long timestampValue = Math.round((double) row.get(headers.indexOf("timestamp")));
+
+      Point.Builder p = Point.measurement(index).time(timestampValue, TimeUnit.MILLISECONDS);
+
+      for (int i = 1; i < row.size(); i++) {
+        String selected_header = headers.get(i);
+        if (!selected_header.equals("sp_internal_label")) {
+          if (headerWithTypes.get(selected_header).equals("integer")) {
+            p.addField(selected_header, Math.round((double) row.get(i)));
+          } else if (headerWithTypes.get(selected_header).equals("string")) {
+            p.addField(selected_header, row.get(i).toString());
+          }
+        } else {
+          p.addField(selected_header, label);
+        }
+      }
+      influxDB.write(p.build());
+    }
+    influxDB.close();
+  }
+
+  private Map<String, String> getHeadersWithTypes(String index) {
+      InfluxDB influxDB = getInfluxDBClient();
+      Query query = new Query("SHOW FIELD KEYS FROM " + index,
+              BackendConfig.INSTANCE.getInfluxDatabaseName());
+      QueryResult result = influxDB.query(query);
+      influxDB.close();
+
+      Map<String, String> headerTypes = new HashMap<String, String>();
+      for (List<Object> element : result.getResults().get(0).getSeries().get(0).getValues()) {
+        headerTypes.put(element.get(0).toString(), element.get(1).toString());
+      }
+      return headerTypes;
+    }
 }
diff --git a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java
index f845cbb..d4d61ac 100644
--- a/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java
+++ b/streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/datalake/DataLakeResourceV3.java
@@ -217,7 +217,9 @@ public class DataLakeResourceV3 extends AbstractRestInterface {
                               @PathParam("startdate") long startdate,
                               @PathParam("enddate") long enddate,
                               @PathParam("label") String label) {
-    
+
+    this.dataLakeManagement.updateLabels(index, startdate, enddate, label);
+
     return Response.ok("Successfully updated database.", MediaType.TEXT_PLAIN).build();
   }