Verified Commit 5126bc2c authored by Löscher Mario's avatar Löscher Mario
Browse files

update to support sorting by couchdb

parent b965a909
......@@ -68,11 +68,14 @@ class rest
public static function post($uri, $json = null)
{
$data_string = json_encode(self::getJsonInput($json));
switch ($uri[0]) {
case 'find':
$data_string = json_encode(self::getJsonInput($json));
$value = curl::executeCouch("/_find", $data_string);
break;
case 'special':
$value = curl::executeCouch("/_index", $data_string);
break;
default:
$value = self::getError(400);
}
......
......@@ -22,14 +22,14 @@
<form>
Starttime: <input type="text" ng-model="st"><br>
Endtime: <input type="text" ng-model="et"><br>
<button type="button" ng-click="two(st, et)">Show</button>
<button type="button" ng-click="two()">Show</button>
</form>
</td>
<td>
<form>
Starttime: <input type="text" ng-model="st"><br>
Endtime: <input type="text" ng-model="et"><br>
<button type="button" ng-click="three(st, et)">Show</button>
<button type="button" ng-click="three()">Show</button>
</form>
</td>
</tr>
......@@ -51,5 +51,7 @@
<td align="right">{{point.value}}</td>
</tr>
</table>
<button type="button" ng-click="index()">Create index</button>
</body>
</html>
\ No newline at end of file
......@@ -34,6 +34,7 @@ temperature.controller('MainController', function ($scope, $route, $routeParams,
let executeSearch =function (data) {
$http.post("https://distributed.mein-server.at/api/rest.php/find", data).then(
function (response) {
console.log(response);
arrayIFyCouchJson(response);
})
};
......@@ -50,37 +51,63 @@ temperature.controller('MainController', function ($scope, $route, $routeParams,
lower = parseFloat(lower);
higher = parseFloat(higher);
let data = JSON.stringify({
"selector": {"_id": {"$gt": null}, "$or": [{"value": {"$lt" : lower}}, {"value": {"$gt": higher}}]},
"selector": {"$or": [{"value": {"$lt" : lower}}, {"value": {"$gt": higher}}]},
"fields": ["_id", "producer", "timestamp", "value", "consumer"],
"sort": ["value"],
});
executeSearch(data);
};
$scope.two = function (startTime, endTime) {
//Updates start and endtime in order to be able to work with directly
let startEndHelp = function() {
//parse numbers as otherwise input from html will not work correctly
startTime = parseFloat(startTime);
endTime = parseFloat(endTime);
(isNaN(parseInt($scope.st))) ? $scope.st = 0 : $scope.st = parseInt($scope.st);
(isNaN(parseInt($scope.et))) ? $scope.et = 9999999999999 : $scope.et = parseInt($scope.et);
//exchange start- and endTime if necessary
if (endTime < startTime) {
let buf = endTime;
endTime = startTime;
startTime = buf;
if ($scope.et < $scope.st) {
let buf = $scope.et;
$scope.et = $scope.st;
$scope.st = buf;
}
};
$scope.two = function () {
startEndHelp();
let data = JSON.stringify({
"selector": {"producer": {"$eq": 0},
"consumer": {"$eq": 1},
"timestamp": {"$gte": startTime,"$lte": endTime}},
"timestamp": {"$gte": $scope.st,"$lte": $scope.et}},
"fields": ["_id", "producer", "timestamp", "value", "consumer"],
"execution_stats": false,
// "sort": ["timestamp"],
"sort": ["timestamp"],
});
executeSearch(data);
};
$scope.three = function (startTime, endTime) {
console.log("I'm a dummy function at the moment");
}
$scope.three = function () {
startEndHelp();
let data = JSON.stringify({
"selector": {"timestamp": {"$gte": $scope.st,"$lte": $scope.et}},
"fields": ["_id", "producer", "timestamp", "value", "consumer"],
"sort": ["value"],
// "aggregator": {"operation": "count", "of": ["value"], "group": ["value"]}
});
executeSearch(data);
};
//Creates the index for value and timestamp
$scope.index = function () {
let data = JSON.stringify({
"index": {"fields": ["value", "timestamp"]},
"name": "value_index",
"type": "json"
});
$http.post("https://distributed.mein-server.at/api/rest.php/special", data).then(
function (response) {
console.log(response.status);
})
};
//$scope.one(0,35);
// $scope.two(1541511001222, 1541508600949);
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment