use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.
the class MeanCalculator method onRemovedResults.
@Override
public void onRemovedResults(BindingsResults results) {
for (Bindings result : results.getBindings()) {
logger.debug(result);
if (result.getBindingValue("value") == null) {
logger.warn("Value is null");
continue;
}
float value;
try {
value = Float.parseFloat(result.getBindingValue("value").replace(",", "."));
} catch (Exception e) {
logger.error(e.getMessage());
continue;
}
counter++;
mean = ((mean * (counter - 1)) + value) / counter;
logger.info(" mean: " + meanURI + " value: " + mean + " counter: " + counter);
}
// Update!
forcedBindings.addBinding("counter", new RDFTermLiteral(String.format("%d", counter)));
forcedBindings.addBinding("value", new RDFTermLiteral(String.format("%.3f", mean)));
update(forcedBindings);
}
use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.
the class StatusMonitor method onAddedResults.
@Override
public void onAddedResults(BindingsResults results) {
for (Bindings bindings : results.getBindings()) {
String thing = bindings.getBindingValue("thing");
logger.info("Ping received by Web Thing: " + thing);
synchronized (pings) {
pings.put(thing, true);
}
if (discoverables.contains(thing))
if (!discoverables.get(thing)) {
logger.info("Make Web Thing: " + thing + " discoverable again");
switchStatus(thing, true);
}
}
}
use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.
the class StatusMonitor method switchStatus.
private void switchStatus(String thing, boolean status) {
// Update
Bindings bindings = new Bindings();
if (status)
bindings.addBinding("value", new RDFTermLiteral("true"));
else
bindings.addBinding("value", new RDFTermLiteral("false"));
bindings.addBinding("thing", new RDFTermURI(thing));
Response ret = update(bindings);
if (ret.isUpdateResponse()) {
discoverables.put(thing, status);
if (status)
logger.warn("Web Thing: " + thing + " turned ON");
else
logger.warn("Web Thing: " + thing + " turned OFF");
}
}
use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.
the class EventPublisher method post.
public void post(String eventURI) {
Bindings bind = new Bindings();
bind.addBinding("event", new RDFTermURI(eventURI));
bind.addBinding("thing", new RDFTermURI(thing));
publisherWithoutOutput.update(bind);
}
use of it.unibo.arces.wot.sepa.commons.sparql.Bindings in project SEPA by arces-wot.
the class ApplicationProfile method subscribeBindings.
public Bindings subscribeBindings(String selectedValue) {
JsonElement elem;
Bindings ret = new Bindings();
if ((elem = doc.get("queries")) != null)
if ((elem = elem.getAsJsonObject().get(selectedValue)) != null)
if ((elem = elem.getAsJsonObject().get("forcedBindings")) != null) {
for (Entry<String, JsonElement> binding : elem.getAsJsonObject().entrySet()) {
JsonObject value = binding.getValue().getAsJsonObject();
RDFTerm bindingValue = null;
if (value.get("type") != null) {
if (value.get("type").getAsString().equals("uri")) {
bindingValue = new RDFTermURI(value.get("value").getAsString());
} else {
bindingValue = new RDFTermLiteral(value.get("value").getAsString());
}
}
ret.addBinding(binding.getKey(), bindingValue);
}
}
return ret;
}
Aggregations