Verified Commit 1cac412c authored by Löscher Mario's avatar Löscher Mario
Browse files

done part 3 manually within js instead of aggregation query combined with joins

parent 5126bc2c
......@@ -29,6 +29,45 @@ temperature.controller('MainController', function ($scope, $route, $routeParams,
current.consumer = tmp[4].split(":")[1].slice(0,1);
$scope.points.list.push(current);
}
countOccurrences();
};
//As I found no working way for the aggregate and join function for couchdb, removing manually here
let countOccurrences = function() {
//The first part counts the occurrences, assuming the given array is already sorted by value
if((typeof $scope.points === "undefined") || (typeof $scope.points.list === "undefined")) {
console.log("nothing to do");
return -1;
}
let overview = [];
let count = [];
let current = -1;
let pointer = -1;
for (let i = 0; i < $scope.points.list.length; i++) {
if ($scope.points.list[i].value !== current) {
overview.push($scope.points.list[i].value);
count.push(1);
pointer++;
current = $scope.points.list[i].value;
}
else {
count[pointer] += 1;
}
}
for (let i = 0; i < overview.length; i++) {
console.log("Value " + overview[i] + " found " + count[i] + " times");
}
//remove values here
let offset = 0;
for (let i = 0; i < overview.length; i++) {
if (count[i] > 2)
offset += count[i];
else
$scope.points.list.splice(offset, count[i]);
}
};
let executeSearch =function (data) {
......@@ -93,7 +132,6 @@ temperature.controller('MainController', function ($scope, $route, $routeParams,
// "aggregator": {"operation": "count", "of": ["value"], "group": ["value"]}
});
executeSearch(data);
};
//Creates the index for value and timestamp
......@@ -108,6 +146,4 @@ temperature.controller('MainController', function ($scope, $route, $routeParams,
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