Example #1
0
        private string CreateFutureComputationUi(DataCurveTriggerSettings triggerSettings)
        {
            var timePicker            = CreateTimePicker(triggerSettings.FutureComputationTimeSpan, triggerSettings.UidString, triggerSettings.UniqueControllerId, Constants.FutureTimeSpanKey);
            var thresholdValueTextbox = CreateJqTextBox(Constants.ThresholdValueKey, "", triggerSettings, 5);

            return($"<tr><td>and the computed value reaches the threshold {thresholdValueTextbox} within {timePicker}</td></tr>");
        }
        //Summary of format info on collapsed trigger/condition
        public string TriggerFormatUi(IPlugInAPI.strTrigActInfo actionInfo)
        {
            var infoInHeader = string.Empty;

            if (!_isCondition)
            {
                return("This can never be a trigger, only a condition");
            }
            if (!ChangeValueTrigger(actionInfo.evRef))
            {
                infoInHeader =
                    "The initial trigger needs to be of type 'This device just had its value set or changed' or 'This device has a value that just changed:' to collect data properly<br/>";
            }
            _triggerSettings = GetSettingsFromTriggerInfo(actionInfo);
            var deviceInfo     = GetDeviceInfoString();
            var ascDescCurve   = GetAscendingDescendingCurveInfoString();
            var timespan       = GetTimespanInfoString(_triggerSettings.TimeSpanChosen, "the last");
            var futureSettings = string.Empty;

            if (_triggerSettings.UseFutureComputation && _triggerSettings.FutureThresholdValue.HasValue &&
                _triggerSettings.FutureComputationTimeSpan.HasValue)
            {
                var futureTimeSpan = GetTimespanInfoString(_triggerSettings.FutureComputationTimeSpan);
                futureSettings = $"and the computed value reaches {_triggerSettings.FutureThresholdValue.Value.ToString(CultureInfo.CreateSpecificCulture("en-US"))} within {futureTimeSpan}";
            }
            return($"{infoInHeader}A data curve of device values for the device <font class=\"event_Txt_Option\">{deviceInfo}</font> has had {ascDescCurve} curve for {timespan} {futureSettings}");
        }
Example #3
0
        public string Build(DataCurveTriggerSettings triggerSettings, IHomeSeerHandler homeSeerHandler = null)
        {
            var sb = new StringBuilder();

            sb.AppendLine("<table>");

            var floorDropDown = CreateFloorDropdown(triggerSettings.FloorChosen, triggerSettings.UidString, triggerSettings.UniqueControllerId);
            var roomDropdown  = CreateRoomDropdown(triggerSettings.RoomChosen, triggerSettings.UidString, triggerSettings.UniqueControllerId);

            if (!_floorsRomsAndDevices.RoomExists(triggerSettings.RoomChosen))
            {
                triggerSettings.RoomChosen = "";
            }
            if (!_floorsRomsAndDevices.FloorExists(triggerSettings.FloorChosen))
            {
                triggerSettings.FloorChosen = "";
            }
            var deviceDropdown = CreateDeviceDropdown(triggerSettings.FloorChosen, triggerSettings.RoomChosen, triggerSettings.DeviceIdChosen, triggerSettings.UidString, triggerSettings.UniqueControllerId);
            var timePicker     = CreateTimePicker(triggerSettings.TimeSpanChosen, triggerSettings.UidString, triggerSettings.UniqueControllerId, Constants.TimeSpanKey);
            var ascendingDescendingDropdown = CreateAscendingDescendingDropdown(triggerSettings.AscendingOrDescending, triggerSettings.UidString, triggerSettings.UniqueControllerId);

            sb.AppendLine($"<tr><td>A data curve of device values for the device {floorDropDown} {roomDropdown}  {deviceDropdown} has had {ascendingDescendingDropdown} curve for the last {timePicker}</td></tr>");
            //Future computation ui
            sb.AppendLine(CreateChoicesForFutureComputation(triggerSettings));
            sb.AppendLine("</table>");
            return(sb.ToString());
        }
 public bool GetTriggerConfigured(IPlugInAPI.strTrigActInfo actionInfo)
 {
     _triggerSettings = GetSettingsFromTriggerInfo(actionInfo);
     if (_triggerSettings.DeviceIdChosen.HasValue && _triggerSettings.DeviceIdChosen.Value > -1)
     {
         OnDeviceIdSet(_triggerSettings.DeviceIdChosen.Value);
     }
     return(_triggerSettings.GetTriggerConfigured());
 }
Example #5
0
        private string CreateJqTextBox(string parameter, string defaultText, DataCurveTriggerSettings triggerSettings, int defaultsize = 10)
        {
            var textBox = new clsJQuery.jqTextBox(
                parameter + triggerSettings.UID + triggerSettings.UniqueControllerId, "text", defaultText, Constants.EventsPage, defaultsize, true);

            if (triggerSettings.FutureThresholdValue.HasValue)
            {
                textBox.defaultText = triggerSettings.FutureThresholdValue.Value.ToString(CultureInfo.CreateSpecificCulture("en-US"));
            }
            return(textBox.Build());
        }
        //Trigger settings
        public string TriggerBuildUi(string uniqueControlId, IPlugInAPI.strTrigActInfo triggerInfo)
        {
            var uid = triggerInfo.UID.ToString();

            _triggerSettings = GetSettingsFromTriggerInfo(triggerInfo);

            if (!_isCondition)
            {
                return("This can never be a trigger, only a condition");
            }
            _triggerSettings.UidString = triggerInfo.UID.ToString();

            _triggerSettings.UniqueControllerId = uniqueControlId;
            return(_dataCurveUi.Build(_triggerSettings));
        }
        public bool TriggerTrue(IPlugInAPI.strTrigActInfo actionInfo, IStorageHandler storageHandler)
        {
            _triggerSettings = GetSettingsFromTriggerInfo(actionInfo);
            if (_triggerSettings != null && _triggerSettings.GetTriggerConfigured())
            {
                var fromDate   = SystemDateTime.Now().AddHours(_triggerSettings.TimeSpanChosen.Value.TotalHours * -1);
                var dataPoints = storageHandler.GetValuesForDevice(_triggerSettings.DeviceIdChosen.Value, fromDate,
                                                                   SystemDateTime.Now());

                //_logging.LogDebug($"calling trigger for computation _dataCurveComputationHandler==null={_dataCurveComputationHandler==null}");

                if (_triggerSettings.UseFutureComputation && _triggerSettings.GetTriggerConfigured())
                {
                    return(_dataCurveComputationHandler.TriggerTrue(dataPoints, _triggerSettings.AscendingOrDescending, _triggerSettings.FutureThresholdValue, _triggerSettings.FutureComputationTimeSpan));
                }

                return(_dataCurveComputationHandler.TriggerTrue(dataPoints, _triggerSettings.AscendingOrDescending));
            }
            return(false);
        }
Example #8
0
        private string CreateChoicesForFutureComputation(DataCurveTriggerSettings triggerSettings)
        {
            var sb = new StringBuilder();
            var checkDoFutureComputation = new clsJQuery.jqCheckBox(Constants.CheckIfUseFutureComputationKey + triggerSettings.UID + triggerSettings.UniqueControllerId, "", Constants.EventsPage, true, true);

            checkDoFutureComputation.@checked = triggerSettings.UseFutureComputation;
            checkDoFutureComputation.toolTip  =
                "Try to estimate the future value";

            if (!triggerSettings.UseFutureComputation)
            {
                var fontType = "class='not_mapped_style' style='font-style: italic'";
                sb.AppendLine("<tr><th class='not_mapped_style' style='text-align:left'>Future computation:</th></tr>");

                sb.AppendLine($"<tr><td {fontType} colspan='7'>{checkDoFutureComputation.Build()} No future computation </td></tr>");
            }
            else
            {
                sb.AppendLine(CreateUiForFutureComputation(checkDoFutureComputation, triggerSettings));
            }

            return(sb.ToString());
        }
Example #9
0
        private string CreateUiForFutureComputation(clsJQuery.jqCheckBox checkDoFutureComputation, DataCurveTriggerSettings triggerSettings)
        {
            var sb = new StringBuilder();

            sb.AppendLine(
                "<tr><th class='not_mapped_style' style='text-align:left' colspan='6'>Future computation:</th></tr>");
            sb.AppendLine($"<tr><td colspan='7'>{checkDoFutureComputation.Build()} Use future computation</td></tr>");
            sb.AppendLine(CreateFutureComputationUi(triggerSettings));
            return(sb.ToString());
        }
        private DataCurveTriggerSettings GetSettingsFromTriggerInfo(IPlugInAPI.strTrigActInfo triggerInfo)
        {
            _triggerInfo = triggerInfo;
            var formattedAction = _collectionFactory.GetActionsIfPossible(triggerInfo);

            if (formattedAction != null)             //&& formattedAction.Keys.Count > 0)
            {
                var uidAndEvRef = $"{triggerInfo.UID.ToString()}_{triggerInfo.evRef.ToString()}_";

                formattedAction = _reformatCopiedAction.Run(formattedAction, triggerInfo.UID, triggerInfo.evRef);
                var triggerSettings = new DataCurveTriggerSettings();
                triggerSettings.UID   = triggerInfo.UID;
                triggerSettings.EvRef = triggerInfo.evRef;
                foreach (var dataKey in formattedAction.Keys)
                {
                    //if (dataKey.Contains(Constants.EvRef))
                    //{
                    //	triggerSettings.EvRef =
                    //		ParameterExtraction.GetIntOrMinusOneFromObject(formattedAction[dataKey]);
                    //}

                    //if (dataKey.Contains(Constants.Uid))
                    //{
                    //	triggerSettings.UID =
                    //		ParameterExtraction.GetIntOrMinusOneFromObject(formattedAction[dataKey]);
                    //}

                    if (dataKey.Contains(Constants.DeviceDropdownKey))
                    {
                        triggerSettings.DeviceIdChosen =
                            ParameterExtraction.GetIntOrNullFromObject(formattedAction[dataKey]);
                    }

                    if (dataKey.Contains(Constants.RoomKey))
                    {
                        triggerSettings.RoomChosen = (string)(formattedAction[dataKey]);
                    }

                    if (dataKey.Contains(Constants.FloorKey))
                    {
                        triggerSettings.FloorChosen = (string)(formattedAction[dataKey]);
                    }

                    if (dataKey.Contains(Constants.IsConditionKey))
                    {
                        triggerSettings.IsCondition = ParameterExtraction.GetBoolFromObject(formattedAction[dataKey]);
                    }

                    if (dataKey.Contains(Constants.TimeSpanKey))
                    {
                        triggerSettings.TimeSpanChosen = ParameterExtraction.GetTimeSpanFromObject(formattedAction[dataKey]);
                    }

                    if (dataKey.Contains(Constants.AscDescKey))
                    {
                        triggerSettings.AscendingOrDescending = ParameterExtraction.GetAscDescEnumFromObject(formattedAction[dataKey]);
                    }
                    if (dataKey.Contains(Constants.CheckIfUseFutureComputationKey))
                    {
                        triggerSettings.UseFutureComputation = ParameterExtraction.GetBoolFromObject(formattedAction[dataKey]);
                    }
                    if (dataKey.Contains(Constants.FutureTimeSpanKey))
                    {
                        triggerSettings.FutureComputationTimeSpan = ParameterExtraction.GetTimeSpanFromObject(formattedAction[dataKey]);
                    }
                    if (dataKey.Contains(Constants.ThresholdValueKey))
                    {
                        triggerSettings.FutureThresholdValue = ParameterExtraction.GetDoubleOrNull(formattedAction[dataKey]);
                    }
                }

                _triggerSettings = triggerSettings;

                return(triggerSettings);
            }

            return(null);
        }