Search in sources :

Example 16 with RDFTermLiteral

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);
}
Also used : RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Example 17 with RDFTermLiteral

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);
}
Also used : Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)

Example 18 with RDFTermLiteral

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;
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Example 19 with RDFTermLiteral

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");
    }
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) ErrorResponse(it.unibo.arces.wot.sepa.commons.response.ErrorResponse) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Example 20 with RDFTermLiteral

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;
}
Also used : JsonElement(com.google.gson.JsonElement) RDFTermURI(it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI) JsonObject(com.google.gson.JsonObject) RDFTerm(it.unibo.arces.wot.sepa.commons.sparql.RDFTerm) Bindings(it.unibo.arces.wot.sepa.commons.sparql.Bindings) RDFTermLiteral(it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)

Aggregations

RDFTermLiteral (it.unibo.arces.wot.sepa.commons.sparql.RDFTermLiteral)22 Bindings (it.unibo.arces.wot.sepa.commons.sparql.Bindings)19 RDFTermURI (it.unibo.arces.wot.sepa.commons.sparql.RDFTermURI)15 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)7 Response (it.unibo.arces.wot.sepa.commons.response.Response)7 SubscribeResponse (it.unibo.arces.wot.sepa.commons.response.SubscribeResponse)5 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 RDFTerm (it.unibo.arces.wot.sepa.commons.sparql.RDFTerm)2 Producer (it.unibo.arces.wot.sepa.pattern.Producer)2 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)1 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)1 ARBindingsResults (it.unibo.arces.wot.sepa.commons.sparql.ARBindingsResults)1 BindingsResults (it.unibo.arces.wot.sepa.commons.sparql.BindingsResults)1 ApplicationProfile (it.unibo.arces.wot.sepa.pattern.ApplicationProfile)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1