//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"); } _triggerSettings = GetSettingsFromTriggerInfo(actionInfo); var deviceInfo = GetDeviceInfoString(); var ascDescCurve = GetAscendingDescendingCurveInfoString(); var thresholdValue = ""; if (_triggerSettings.ThresholdValue.HasValue) { thresholdValue = _triggerSettings.ThresholdValue.Value.ToString(); } var numberOfLastMeasurements = ""; if (_triggerSettings.NumberOfLastMeasurements.HasValue) { numberOfLastMeasurements = _triggerSettings.NumberOfLastMeasurements.Value.ToString(); } return($" The threshold value of {thresholdValue} has been reached for the device <font class=\"event_Txt_Option\">{deviceInfo}</font> " + $"and it has had {ascDescCurve} slope for the {numberOfLastMeasurements} last measurements"); }
private string CreateJqTextBox(string parameter, string defaultText, DataCurveTriggerBSettings triggerSettings, int defaultsize = 10) { var textBox = new clsJQuery.jqTextBox( parameter + triggerSettings.UID + triggerSettings.UniqueControllerId, "text", defaultText, Constants.EventsPage, defaultsize, true); textBox.left = 1; return(textBox.Build()); }
public bool GetTriggerConfigured(IPlugInAPI.strTrigActInfo actionInfo) { _triggerSettings = GetSettingsFromTriggerInfo(actionInfo); if (_triggerSettings.DeviceIdChosen.HasValue && _triggerSettings.DeviceIdChosen.Value > -1) { OnDeviceIdSet(_triggerSettings.DeviceIdChosen.Value); } return(_triggerSettings.GetTriggerConfigured()); }
//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 thresholdValue = _triggerSettings.ThresholdValue; var numberOfLastMeasurements = _triggerSettings.NumberOfLastMeasurements ?? 10; var dataPoints = storageHandler.GetLastValuesForDevice(_triggerSettings.DeviceIdChosen.Value, numberOfLastMeasurements); var lastValue = dataPoints.Last(); if (!ThresholdReached(lastValue.Value, thresholdValue, _triggerSettings.AscendingOrDescending)) { return(false); } return(_dataCurveComputationHandler.TriggerTrue(dataPoints, _triggerSettings.AscendingOrDescending, thresholdValue.Value, numberOfLastMeasurements)); } return(false); }
public string Build(DataCurveTriggerBSettings 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 (!_floorsRoomsAndDevices.RoomExists(triggerSettings.RoomChosen)) { triggerSettings.RoomChosen = ""; } if (!_floorsRoomsAndDevices.FloorExists(triggerSettings.FloorChosen)) { triggerSettings.FloorChosen = ""; } var deviceDropdown = CreateDeviceDropdown(triggerSettings.FloorChosen, triggerSettings.RoomChosen, triggerSettings.DeviceIdChosen, triggerSettings.UidString, triggerSettings.UniqueControllerId); var ascendingDescendingDropdown = CreateAscendingDescendingDropdown(triggerSettings.AscendingOrDescending, triggerSettings.UidString, triggerSettings.UniqueControllerId); var thresholdDefaultText = ""; if (triggerSettings.ThresholdValue.HasValue) { thresholdDefaultText = triggerSettings.ThresholdValue.Value.ToString(CultureInfo.CreateSpecificCulture("en-US")); } var thresholdValueTextbox = CreateJqTextBox(Constants.ThresholdValueKey, thresholdDefaultText, triggerSettings, 3); var numberOfLastDataPointsText = ""; if (triggerSettings.NumberOfLastMeasurements.HasValue) { numberOfLastDataPointsText = triggerSettings.NumberOfLastMeasurements.Value.ToString(CultureInfo.CreateSpecificCulture("en-US")); } var numberOfMeasurementsTextBox = CreateJqTextBox(Constants.NumberOfLastMeasurementsKey, numberOfLastDataPointsText, triggerSettings, 3); sb.AppendLine($"<tr><td>The threshold value of {thresholdValueTextbox } has been reached for the device {floorDropDown} {roomDropdown} {deviceDropdown} and it has had {ascendingDescendingDropdown} curve for the {numberOfMeasurementsTextBox} last measurements</td></tr>"); sb.AppendLine("</table>"); return(sb.ToString()); }
private DataCurveTriggerBSettings 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 DataCurveTriggerBSettings(); triggerSettings.UID = triggerInfo.UID; triggerSettings.EvRef = triggerInfo.evRef; foreach (var dataKey in formattedAction.Keys) { 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.AscDescKey)) { triggerSettings.AscendingOrDescending = ParameterExtraction.GetAscDescEnumFromObject(formattedAction[dataKey]); } if (dataKey.Contains(Constants.ThresholdValueKey)) { triggerSettings.ThresholdValue = ParameterExtraction.GetDoubleOrNull(formattedAction[dataKey]); } if (dataKey.Contains(Constants.NumberOfLastMeasurementsKey)) { var numberOfLastMeasurements = ParameterExtraction.GetIntOrNullFromObject(formattedAction[dataKey]); if (numberOfLastMeasurements >= 2) { triggerSettings.NumberOfLastMeasurements = numberOfLastMeasurements; } } } _triggerSettings = triggerSettings; return(triggerSettings); } return(null); }