Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
User expired
2018s-advanced-distributed-systems
Commits
5126bc2c
Verified
Commit
5126bc2c
authored
Nov 07, 2018
by
Löscher Mario
Browse files
update to support sorting by couchdb
parent
b965a909
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
16 deletions
+48
-16
webapp/htdocs/api/rest.php
webapp/htdocs/api/rest.php
+4
-1
webapp/htdocs/index.html
webapp/htdocs/index.html
+4
-2
webapp/htdocs/javascript/mainController.js
webapp/htdocs/javascript/mainController.js
+40
-13
No files found.
webapp/htdocs/api/rest.php
View file @
5126bc2c
...
...
@@ -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
);
}
...
...
webapp/htdocs/index.html
View file @
5126bc2c
...
...
@@ -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
webapp/htdocs/javascript/mainController.js
View file @
5126bc2c
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment