Search in sources :

Example 1 with GuiBinderObject

use of il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject in project Smartcity-Smarthouse by TechnionYP5777.

the class StatusRegionBuilderImpl method addTimerStatusField.

/*
     * (non-Javadoc)
     * 
     * @see il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * StatusRegionBuilder#addTimerStatusField(java.lang.String,
     * il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * GuiBinderObject,
     * il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * GuiBinderObject,
     * il.ac.technion.cs.smarthouse.developers_api.application_builder.
     * ColorRange)
     */
@Override
public StatusRegionBuilderImpl addTimerStatusField(String title, GuiBinderObject<Boolean> timerToggle, GuiBinderObject<Double> timerDuration, ColorRange<Double> d) {
    final Label timeLabel = createStatusLabel("");
    final Timeline timeline;
    final GuiBinderObject<Duration> time = new GuiBinderObject<>(Duration.ZERO);
    timeLabel.setText(0.0 + " [sec]");
    timeline = new Timeline(new KeyFrame(Duration.millis(100), ¢ -> {
        time.setData(time.getData().add(((KeyFrame) ¢.getSource()).getTime()));
        timerDuration.setData(time.getData().toSeconds());
        timeLabel.setText(timerDuration.getData() + " [sec]");
    }));
    timerToggle.addOnDataChangedListener(v -> {
        if (v.getData()) {
            timeline.setCycleCount(Animation.INDEFINITE);
            timeline.play();
        } else {
            timeline.stop();
            time.setData(Duration.ZERO);
            timerDuration.setData(time.getData().toSeconds());
            timeLabel.setText(timerDuration.getData() + " [sec]");
        }
    });
    if (d != null)
        timerDuration.addOnDataChangedListener(v -> setColor(v, d, timeLabel));
    addAppBuilderItem(new AppBuilderItem(title, timeLabel));
    return this;
}
Also used : ColorRange(il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration) Label(javafx.scene.control.Label) Font(javafx.scene.text.Font) Timeline(javafx.animation.Timeline) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject) StatusRegionBuilder(il.ac.technion.cs.smarthouse.developers_api.application_builder.StatusRegionBuilder) Animation(javafx.animation.Animation) Timeline(javafx.animation.Timeline) Label(javafx.scene.control.Label) KeyFrame(javafx.animation.KeyFrame) Duration(javafx.util.Duration) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)

Example 2 with GuiBinderObject

use of il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject in project Smartcity-Smarthouse by TechnionYP5777.

the class VitalsApp method onLoad.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication#onLoad(
     * )
     */
@Override
public void onLoad() throws Exception {
    log.debug("App starting - in onLoad");
    SensorsService sensorsManager = (SensorsService) super.getService(ServiceType.SENSORS_SERVICE);
    AlertsManager alertsManager = (AlertsManager) super.getService(ServiceType.ALERTS_SERVICE);
    sensorsManager.getSensor("iVitals", VitalsSensor.class).subscribe(vitals -> {
        final int pulse = vitals.getPulse(), systolicBP = vitals.getSystolicBP(), diastolicBP = vitals.getDiastolicBP();
        final String t = "Client has pulse of " + pulse + " and blood pressure of " + systolicBP + "/" + diastolicBP + " mmHg";
        controller.updateChart(vitals.getPulse(), vitals.getSystolicBP(), vitals.getDiastolicBP());
        log.debug("App msg (from function subscibed to vitals sensor): " + t + " | Sensor is located at: " + vitals.getSensorLocation());
        // Major alerts
        if (pulse < 45 && !lowPulseAlert) {
            lowPulseAlert = true;
            alertsManager.sendAlert(getApplicationName(), "Client has an extremely low pulse.", EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
        }
        if (pulse >= 45 && lowPulseAlert)
            lowPulseAlert = false;
        if (pulse > 115 && !highPulseAlert) {
            highPulseAlert = true;
            alertsManager.sendAlert(getApplicationName(), "Client has an extremely high pulse.", EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
        }
        if (pulse <= 115 && highPulseAlert)
            highPulseAlert = false;
        if ((systolicBP < 80 || diastolicBP < 50) && !lowBPAlert) {
            lowBPAlert = true;
            alertsManager.sendAlert(getApplicationName(), "Client suffers from hypotension.", EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
        }
        if (systolicBP >= 80 && diastolicBP >= 50 && lowBPAlert)
            lowBPAlert = false;
        if ((systolicBP > 190 || diastolicBP > 120) && highBPAlert < 2) {
            highBPAlert = 2;
            alertsManager.sendAlert(getApplicationName(), "Client suffers from hypertensive emergency.", EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
        } else if ((systolicBP > 160 && systolicBP <= 190 || diastolicBP > 100 && diastolicBP <= 120) && highBPAlert < 1) {
            highBPAlert = 1;
            alertsManager.sendAlert(getApplicationName(), "Client suffers from hypertension.", EmergencyLevel.EMAIL_EMERGENCY_CONTACT);
        }
        if (systolicBP <= 160 && diastolicBP <= 100)
            highBPAlert = 0;
    });
    GuiBinderObject<Controller> c = new GuiBinderObject<>();
    getAppBuilder().getCustomRegionBuilder().add("vitals_app_ui.fxml", c);
    controller = c.getData();
}
Also used : AlertsManager(il.ac.technion.cs.smarthouse.system.services.alerts_service.AlertsManager) SensorsService(il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService) GuiBinderObject(il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)

Example 3 with GuiBinderObject

use of il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject 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 4 with GuiBinderObject

use of il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject 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

GuiBinderObject (il.ac.technion.cs.smarthouse.developers_api.application_builder.GuiBinderObject)4 SensorsService (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorsService)3 ColorRange (il.ac.technion.cs.smarthouse.developers_api.application_builder.ColorRange)2 InfoCollector (il.ac.technion.cs.smarthouse.system.dashboard.InfoCollector)2 AlertsManager (il.ac.technion.cs.smarthouse.system.services.alerts_service.AlertsManager)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 StatusRegionBuilder (il.ac.technion.cs.smarthouse.developers_api.application_builder.StatusRegionBuilder)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 WidgetType (il.ac.technion.cs.smarthouse.system.dashboard.WidgetType)1 ServiceType (il.ac.technion.cs.smarthouse.system.services.ServiceType)1 SensorApi (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorApi)1 SensorData (il.ac.technion.cs.smarthouse.system.services.sensors_service.SensorData)1 SystemPath (il.ac.technion.cs.smarthouse.system.services.sensors_service.SystemPath)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1