use of it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral in project SEPA by arces-wot.
the class ObservationSimulator method simulate.
public void simulate() {
value += 5;
if (value > 45)
value = 15;
bindings.addBinding("value", new RDFTermLiteral(String.format("%d", value)));
update(bindings);
}
use of it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral 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.RDFTermLiteral in project SEPA by arces-wot.
the class MeanCalculator method start.
public boolean start() {
Response ret;
ret = subscribe(null);
if (ret.isError())
return false;
mean = 0;
counter = 0;
// Update!
forcedBindings.addBinding("counter", new RDFTermLiteral(String.format("%d", counter)));
forcedBindings.addBinding("value", new RDFTermLiteral(String.format("%.3f", mean)));
update(forcedBindings);
return true;
}
use of it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral 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.RDFTermLiteral 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