Search in sources :

Example 1 with InfoCollector

use of il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector in project Smartcity-Smarthouse by TechnionYP5777.

the class AcuGui method onLoad.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication#onLoad(
     * )
     */
/**
 * [[SuppressWarningsSpartan]]
 */
@Override
public void onLoad() throws Exception {
    final GuiBinderObject<Integer> currentTemp = new GuiBinderObject<>(20);
    final GuiBinderObject<Integer> wantedTemp = new GuiBinderObject<>(18);
    final GuiBinderObject<String> AcuState = new GuiBinderObject<>(OFF);
    final SensorApi<ACUSensor> sensor = super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class);
    sensor.subscribe(data -> {
        // update GUI
        currentTemp.setData(data.getTemp());
        AcuState.setData(data.isOn() ? ON : OFF);
        // instruct sensor
        Integer want = wantedTemp.getData(100), have = currentTemp.getData(0);
        AcuAction nextAction = (have < want) ? AcuAction.HOTTER : (have > want) ? AcuAction.COLDER : AcuAction.STOP;
        sensor.instruct(nextAction + "", setStatePath);
    });
    wantedTemp.addOnDataChangedListener(desiredT -> desiredT.getDataAsOptional().ifPresent(t -> sensor.instruct(t + 0.2 + "", setTempPath)));
    getAppBuilder().getStatusRegionBuilder().addStatusField("Current temperature in controlled location:", currentTemp).addStatusField("The air conditioner in controlled location is", AcuState);
    getAppBuilder().getConfigurationsRegionBuilder().addIntegerInputField("Desired Temperature:", wantedTemp).addSensorAliasSelectionField("The Controlled location:", sensor, (oldA, newA) -> {
        super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class, oldA).instruct(AcuAction.STOP + "", setStatePath);
        wantedTemp.getDataAsOptional().ifPresent(t -> super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class, newA).instruct(t + 0.3 + "", setTempPath));
    });
    simulation.getAliases().forEach(alias -> {
        SensorApi<ACUSensor> currSensor = super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor(Simulation.commname, ACUSensor.class, alias);
        getAppBuilder().getWidgetsRegionBuilder().addWidget(WidgetType.PROGRESS_LINE_GRAPH, new InfoCollector().addInfoEntry(getTempPath, "temperature").setTitle(alias), currSensor, acu -> {
            Map<String, Object> data = new HashMap<>();
            data.put(getTempPath, acu.getTemp());
            return data;
        });
    });
}
Also used : Collection(java.util.Collection) ServiceType(il.ac.technion.cs.smarthouse.system.services.ServiceType) SystemPath(il.ac.technion.cs.smarthouse.system.services.sensors_service.SystemPath) HashMap(java.util.HashMap) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject) SensorsService(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService) InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) AcuAction(il.ac.technion.cs.simulation.Simulation.AcuAction) SmarthouseApplication(il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication) SensorApi(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi) GenericSensor(il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor) SensorData(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorData) Map(java.util.Map) Simulation(il.ac.technion.cs.simulation.Simulation) PathType(il.ac.technion.cs.smarthouse.sensors.PathType) Simulatable(il.ac.technion.cs.smarthouse.sensors.Simulatable) WidgetType(il.ac.technion.cs.smarthouse.system.dashboard.WidgetType) InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) HashMap(java.util.HashMap) AcuAction(il.ac.technion.cs.simulation.Simulation.AcuAction) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject) SensorsService(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)

Example 2 with InfoCollector

use of il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector in project Smartcity-Smarthouse by TechnionYP5777.

the class ConfigConsumer method getCollectedInfo.

private InfoCollector getCollectedInfo() {
    final InfoCollector c = new InfoCollector();
    if (!titlefDefaultText.equals(titleField.getText()))
        c.setTitle(titleField.getText());
    if (!unitfDefaultText.equals(unitField.getText()))
        c.setUnit(unitField.getText());
    final List<String> badNames = Arrays.asList(namefDefaultText, "", null);
    if (tableData.isEmpty())
        return null;
    tableData.forEach(namedPath -> {
        if (!pathscbDefaultText.equals(namedPath.getPath())) {
            final String actualname = badNames.contains(namedPath.getName()) ? null : namedPath.getName();
            c.addInfoEntry(namedPath.getPath(), actualname);
        }
    });
    return c;
}
Also used : InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector)

Example 3 with InfoCollector

use of il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector in project Smartcity-Smarthouse by TechnionYP5777.

the class ConfigConsumer method initWidgets.

// ------------------ private helper methods ------------------------------
private Map<String, List<BasicWidget>> initWidgets() {
    final Map<String, List<BasicWidget>> allWidgets = new HashMap<>();
    final InfoCollector info = new InfoCollector().addInfoEntry("path.to.foo", "foo").addInfoEntry("path.to.bar", "bar").setUnit("m/s");
    final Double tileSize = 150.0;
    Stream.of(WidgetType.values()).forEach(type -> {
        final Optional<BasicWidget> nullableWidget = Optional.ofNullable(type.createWidget(tileSize, info));
        nullableWidget.ifPresent(widget -> {
            final List<BasicWidget> newlist = allWidgets.getOrDefault(widget.getTitle(), new ArrayList<>());
            newlist.add(widget);
            allWidgets.put(widget.getTitle(), newlist);
            addWidgetTimer(widget);
            setWidgetColorListeners(widget);
        });
    });
    return allWidgets;
}
Also used : InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) BasicWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget)

Example 4 with InfoCollector

use of il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector in project Smartcity-Smarthouse by TechnionYP5777.

the class WidgetsRegionBuilderImpl method addWidget.

/*
     * (non-Javadoc)
     * 
     * @see il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * WidgetsRegionBuilder#addWidget(il.ac.technion.cs.smarthouse.system.
     * dashboard.WidgetType,
     * il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector,
     * il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi,
     * java.util.function.Function)
     */
@Override
public <T extends SensorData> WidgetsRegionBuilder addWidget(final WidgetType t, final InfoCollector c, final SensorApi<T> a, final Function<T, Map<String, Object>> sensorProcessor) {
    if (!canAdd())
        return this;
    BasicWidget bw = t.createWidget(tileSize, c);
    a.subscribe(data -> sensorProcessor.apply(data).forEach((path, val) -> bw.update(val, path)));
    widgetsHbox.getChildren().add(core.createWidget(bw).get());
    return this;
}
Also used : HBox(javafx.scene.layout.HBox) Function(java.util.function.Function) InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) DashboardCore(il.ac.technion.cs.smarthouse.system.dashboard.DashboardCore) WidgetsRegionBuilder(il.ac.technion.cs.smarthouse.developers_api.application_builder.WidgetsRegionBuilder) SensorApi(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi) Insets(javafx.geometry.Insets) ScrollPane(javafx.scene.control.ScrollPane) SensorData(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorData) ScrollBarPolicy(javafx.scene.control.ScrollPane.ScrollBarPolicy) BasicWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget) Map(java.util.Map) WidgetType(il.ac.technion.cs.smarthouse.system.dashboard.WidgetType) BasicWidget(il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget)

Example 5 with InfoCollector

use of il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector in project Smartcity-Smarthouse by TechnionYP5777.

the class StoveModuleGui method onLoad.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication#onLoad(
     * )
     */
@Override
public void onLoad() throws Exception {
    final GuiBinderObject<Double> alertAfterSecs = new GuiBinderObject<>(15.0);
    final GuiBinderObject<Integer> alertAboveDegs = new GuiBinderObject<>(120), temps = new GuiBinderObject<>(0);
    final GuiBinderObject<Boolean> isStoveOn = new GuiBinderObject<>(false);
    final GuiBinderObject<Double> timer = new GuiBinderObject<>();
    getAppBuilder().getConfigurationsRegionBuilder().addDoubleInputField("Alert after (seconds):", alertAfterSecs).addIntegerInputField("Alert at (degrees celsius):", alertAboveDegs);
    getAppBuilder().getStatusRegionBuilder().addStatusField("Current temperature:", temps, new ColorRange<Integer>().addRange(alertAboveDegs, Color.RED)).addTimerStatusField("Stove running timer:", isStoveOn, timer, new ColorRange<Double>().addRange(alertAfterSecs, Color.RED));
    super.<SensorsService>getService(ServiceType.SENSORS_SERVICE).getSensor("iStoves", StoveSensor.class).subscribe(stove -> {
        final String t = "Stove is " + (stove.isOn() ? "" : "Not ") + "On at " + stove.getTemperture() + " degrees";
        isStoveOn.setData(stove.isOn());
        temps.setData(!stove.isOn() ? 0 : stove.getTemperture());
        log.debug("App msg (from function subscibed to stove sensor): " + t + " | Sensor is located at: " + stove.getSensorLocation());
    });
    Runnable c = () -> {
        synchronized (alertCalled) {
            if (timer.getData(0.0) <= alertAfterSecs.getData(0.0) && temps.getData(0) <= alertAboveDegs.getData(0))
                alertCalled = false;
            else if (!alertCalled) {
                ((AlertsManager) getService(ServiceType.ALERTS_SERVICE)).sendAlert(getApplicationName(), "Stove is running too long", EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
                alertCalled = true;
            }
        }
    };
    timer.addOnDataChangedListener(c);
    temps.addOnDataChangedListener(c);
    getAppBuilder().getWidgetsRegionBuilder().addWidget(WidgetType.BASIC_DASHBOARD, new InfoCollector().setUnit("C").addInfoEntry("stove.temperature", "temper")).addWidget(WidgetType.LINES_GRAPH, new InfoCollector().setUnit("C").addInfoEntry("stove.temperature", "temper")).addWidget(WidgetType.SWITCH, new InfoCollector().setUnit("Boolean").addInfoEntry("stove.is_on", "isOn"));
}
Also used : InfoCollector(il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector) AlertsManager(il.ac.technion.cs.smarthouse.system.services.alerts_service.AlertsManager) ColorRange(il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange) SensorsService(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)

Aggregations

InfoCollector (il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector)5 GuiBinderObject (il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)2 WidgetType (il.ac.technion.cs.smarthouse.system.dashboard.WidgetType)2 BasicWidget (il.ac.technion.cs.smarthouse.system.dashboard.widget.BasicWidget)2 SensorApi (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi)2 SensorData (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorData)2 SensorsService (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Simulation (il.ac.technion.cs.simulation.Simulation)1 AcuAction (il.ac.technion.cs.simulation.Simulation.AcuAction)1 SmarthouseApplication (il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication)1 ColorRange (il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange)1 WidgetsRegionBuilder (il.ac.technion.cs.smarthouse.developers_api.application_builder.WidgetsRegionBuilder)1 PathType (il.ac.technion.cs.smarthouse.sensors.PathType)1 Simulatable (il.ac.technion.cs.smarthouse.sensors.Simulatable)1 GenericSensor (il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor)1 DashboardCore (il.ac.technion.cs.smarthouse.system.dashboard.DashboardCore)1 ServiceType (il.ac.technion.cs.smarthouse.system.services.ServiceType)1 AlertsManager (il.ac.technion.cs.smarthouse.system.services.alerts_service.AlertsManager)1