Skip to content

Commit

Permalink
Deprecated old MemoryValuesStore, replaced by DbValuesStore
Browse files Browse the repository at this point in the history
Added story error on html
Added values filtering
  • Loading branch information
dutoitc committed Sep 30, 2017
1 parent bb5e201 commit 3c1ca68
Show file tree
Hide file tree
Showing 7 changed files with 228 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/main/java/ch/mno/copper/data/InstantValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package ch.mno.copper.data;

import java.time.Instant;

/**
* Created by xsicdt on 25/08/17.
*/
public class InstantValue {

protected long id;
protected String key;
protected String value;
protected Instant timestamp;

public String getValue() {
return value;
}

public long getId() {
return id;
}

public String getKey() {
return key;
}

public Instant getTimestamp() {
return timestamp;
}


public InstantValue(long id, String key, String value, Instant timestamp) {
this.id = id;
this.key = key;
this.value = value;
this.timestamp = timestamp;
}

@Override
public String toString() {
return "StoreValue{" +
"key='" + key + '\'' +
", value='" + value + '\'' +
", timestamp=" + timestamp +
'}';
}
}
34 changes: 34 additions & 0 deletions src/main/java/ch/mno/copper/data/InstantValues.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package ch.mno.copper.data;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

/**
* Created by dutoitc on 30.09.2017.
*/
public class InstantValues {

protected Instant timestamp;
protected Map<String, InstantValue> values = new HashMap<>();



public void put(String key, InstantValue value) {
values.put(key, value);
}


public Instant getTimestamp() {
return timestamp;
}

public void setTimestamp(Instant timestamp) {
this.timestamp = timestamp;
}

public Map<String, InstantValue> getValues() {
return values;
}

}
85 changes: 85 additions & 0 deletions src/main/resources/WEB-INF/app/controllers/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict';

angular.module('copperApp.history', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/history', {
templateUrl: 'app/views/history.html',
controller: 'historyCtrl'
});
}])

.controller('historyCtrl', ['$http', '$scope', '$routeParams', function($http, $scope, $routeParams) {
var scope = $scope;
var self=this;
var key = $routeParams.key;

$scope.labels = [];
$scope.series = [];
$scope.data = [];
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
$scope.datasetOverride = [{ yAxisID: 'y-axis-1' }, { yAxisID: 'y-axis-2' }];
$scope.options = {
scales: {
yAxes: [
{
id: 'y-axis-1',
type: 'linear',
display: true,
position: 'left'
},
{
id: 'y-axis-2',
type: 'linear',
display: true,
position: 'right'
}
]
}
};

$http.get('ws/instants/query?columns='+key+'&from=2017-09-30T00:00&intervalSeconds=300')
.then(function(response) {
$scope.history=[];

// series
var spl = key.split(",");
for (var i=0; i<spl.length; i++) {
$scope.series.push(spl[i]);
$scope.data.push([]);
}

for (var i=0; i<response.data.length;i++) {
var iv = response.data[i]
$scope.labels.push($scope.toHumanDate(iv.timestamp.seconds));
for (var j=0; j<$scope.series.length; j++) {
var iv2 = iv.values[$scope.series[j]];
$scope.data[j].push(iv2.value);
$scope.history.push(iv2);
}
}
});


$scope.toHumanDate = function(ts) {
//var d = new Date(ts*1000);
return moment(ts).format('DD.MM.YYYY, HH:mm:ss');
};

$scope.filter = function(object, field, filter) {
if (!object) return {};
if (!filter) return object;

var filteredObject = {};
Object.keys(object).forEach(function(key) {
if (object[key][field].includes(filter)) {
filteredObject[key] = object[key];
}
});

return filteredObject;
};


}]);
34 changes: 34 additions & 0 deletions src/main/resources/WEB-INF/app/views/history.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<h1>History</h1>
<div class="row">

<canvas id="line" class="chart chart-line" chart-data="data"
chart-labels="labels" chart-series="series" chart-options="options"
chart-dataset-override="datasetOverride" chart-click="onClick">
</canvas>
(Access from 'values' menu)


<br/>
<br/>

<div ng-show="history.length>0">
values

<label>Search: <input ng-model="searchText"></label>
<table class="table-striped" style="width: 80%; margin: auto; border: 1px outset silver">
<thead>
<th style="text-align:right;padding: 5px">Timestamp</th>
<th style="text-align:right;padding: 5px">Key</th>
<th style="text-align:left; padding-left: 10px">Value</th>
</thead>
<tbody>
<tr ng-repeat="v in history | filter:searchText | orderBy:'-timestamp.seconds'">
<td style="text-align:center;width: 150px">{{v.timestamp.seconds*1000 | date : 'yyyy-MM-dd HH:mm:ss'}}</td>
<td style="text-align:right;padding: 5px;font-weight:bold">{{v.key}}</td>
<td style="text-align:left; padding-left: 10px">{{v.value}}</td>
</tr>
</tbody>
</table>
</div>

</div>
10 changes: 10 additions & 0 deletions src/main/resources/WEB-INF/lib/Chart.bundle.min.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/main/resources/WEB-INF/lib/angular-chart.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/main/resources/WEB-INF/lib/moment.min.js

Large diffs are not rendered by default.

0 comments on commit 3c1ca68

Please sign in to comment.