public void Test_DefaultThresholdSettings() { var thresholdRepository = new Mock <IThresholdRepository>(); thresholdRepository.Setup(m => m.GetAll()).Returns(new List <IThresholdData>()); ThresholdModel model = new ThresholdModel(new ThermometerModel(), thresholdRepository.Object); List <IThresholdData> target = model.ThresholdSettings; // Assert Assert.AreEqual(2, target.Count); IThresholdData data = target[0]; Assert.AreEqual(1, data.Id); Assert.AreEqual("Freezing", data.Name); Assert.AreEqual(0.0, data.Temperature); Assert.AreEqual(ThresholdGoDirection.None, data.Direction); Assert.AreEqual(true, data.IgnoreHalfUnit); data = target[1]; Assert.AreEqual(2, data.Id); Assert.AreEqual("Boiling", data.Name); Assert.AreEqual(100.0, data.Temperature); Assert.AreEqual(ThresholdGoDirection.None, data.Direction); Assert.AreEqual(true, data.IgnoreHalfUnit); }
public void Test_AlertTrigger_DataFromSameToSameOnTrigger() { var thresholdRepository = new Mock <IThresholdRepository>(); thresholdRepository.Setup(m => m.GetAll()).Returns(new List <IThresholdData>()); ThresholdModel model = new ThresholdModel(new ThermometerModel(), thresholdRepository.Object); Assert.IsFalse(model.TriggerThresholdAlert(0.0, 0.0)); }
public void Test_AlertTrigger_DataFromBelowToAboveTrigger() { var thresholdRepository = new Mock <IThresholdRepository>(); thresholdRepository.Setup(m => m.GetAll()).Returns(new List <IThresholdData>()); ThresholdModel model = new ThresholdModel(new ThermometerModel(), thresholdRepository.Object); Assert.IsTrue(model.TriggerThresholdAlert(-10.0, 10.0)); }
public String InsertThreshold(ThresholdSerializer thresholdSerializer) { ThresholdModel t = new ThresholdModel(); t.IndexId = thresholdSerializer.field; t.DeviceId = thresholdSerializer.deviceGroup; t.Operator = thresholdSerializer.Operator; t.ThresholdValue = int.Parse(thresholdSerializer.value); t.RuleName = thresholdSerializer.name; t.Description = thresholdSerializer.description; t.Severity = thresholdSerializer.severity; return(this._thresholdDao.Create(t)); }
public void Test_AlertTrigger_SettingFromAbove_DataFromAboveToBelow() { var thresholdRepository = new Mock <IThresholdRepository>(); thresholdRepository.Setup(m => m.GetAll()).Returns(new List <IThresholdData>()); ThresholdModel model = new ThresholdModel(new ThermometerModel(), thresholdRepository.Object); IThresholdData setting = model.ThresholdSettings[0]; setting.Direction = ThresholdGoDirection.Above; Assert.IsTrue(model.TriggerThresholdAlert(1.0, -1.0)); }
public String UpdateThreshold(int id, ThresholdSerializer thresholdSerializer) { ThresholdModel t = new ThresholdModel(); t.IndexId = thresholdSerializer.field; t.DeviceId = thresholdSerializer.deviceGroup; t.Operator = thresholdSerializer.Operator; t.ThresholdValue = double.Parse(thresholdSerializer.value); t.RuleName = thresholdSerializer.name; t.Description = thresholdSerializer.description; t.Severity = thresholdSerializer.severity; t.UpdateTime = DateTime.Now; return(this._thresholdDao.Update(id, t)); }
public async Task <IActionResult> SetThreshold([FromRoute] string id, [FromBody] ThresholdModel thresholdModel) { Common.ConfigModel.SkynetTerminal.VATHLimitDto limit = new Common.ConfigModel.SkynetTerminal.VATHLimitDto() { UpperV = thresholdModel.Upper_V, LowerV = thresholdModel.Lower_V, UpperA = thresholdModel.Upper_A, LowerA = thresholdModel.Lower_A, UpperT = thresholdModel.Upper_T, LowerT = thresholdModel.Lower_T, UpperH = Convert.ToInt32(thresholdModel.Upper_H) }; return(await ExecFunction(id, device => _skynetTerminalClient.WdVATHLimit(limit, device.EquipNum), "threshold")); }
public ThresholdSerializer(ThresholdModel thresholdModel) { this.id = thresholdModel.Id; this.field = thresholdModel.IndexId; this.deviceGroup = thresholdModel.DeviceId; this.Operator = thresholdModel.Operator; this.value = thresholdModel.ThresholdValue.ToString(); this.createTime = thresholdModel.CreateTime .ToString(Constant.getDateFormatString()); this.updateTime = thresholdModel.UpdateTime .ToString(Constant.getDateFormatString()); this.name = thresholdModel.RuleName; this.description = thresholdModel.Description; this.severity = thresholdModel.Severity; }
public void Test_AlertTrigger_DataFromAboveToBelow_WithinHalf() { var thresholdRepository = new Mock <IThresholdRepository>(); thresholdRepository.Setup(m => m.GetAll()).Returns(new List <IThresholdData>()); ThermometerModel thermoModel = new ThermometerModel(); ThresholdModel model = new ThresholdModel(thermoModel, thresholdRepository.Object); Assert.IsTrue(model.TriggerThresholdAlert(0.0, -0.5)); // Now, alert has been shown once. So, set thermometer model accordingly to be triggered. thermoModel.Triggered = true; Assert.IsFalse(model.TriggerThresholdAlert(-0.5, 0.0)); // doing again will not trigger alert: Assert.IsFalse(model.TriggerThresholdAlert(0.0, 0.5)); }
public ThresholdSerializerDisplay(ThresholdModel thresholdModel) { Dictionary <String, String> op = new Dictionary <string, string>(); op.Add("less", "<"); op.Add("greater", ">"); op.Add("equal", "="); this.id = thresholdModel.Id; this.deviceGroup = thresholdModel.DeviceId; this.conditionString = thresholdModel.IndexId + " " + op[thresholdModel.Operator] + " " + thresholdModel.ThresholdValue.ToString(); this.createTime = DateTime.Parse(thresholdModel.CreateTime.ToString()) .ToLocalTime().ToString(Constant.getDateFormatString()); this.updateTime = DateTime.Parse(thresholdModel.UpdateTime.ToString()) .ToLocalTime().ToString(Constant.getDateFormatString()); this.name = thresholdModel.RuleName; this.description = thresholdModel.Description; this.severity = thresholdModel.Severity; }
public ThermometerThresholdUI(ThresholdModel model, int selectedIndex) { InitializeComponent(); _model = model; _currThresholdData = model.ThresholdSettings[selectedIndex]; // Update UI _tbx_Name.Text = CurrentData.Name; _tbx_Name.Enabled = CurrentData.Id != 1 && CurrentData.Id != 2; _tbx_Temperature.Text = CurrentData.Temperature.ToString("F1"); _cbx_FromDirection.Items.Add(new ComboBox_Direction(ThresholdGoDirection.None.ToString(), ThresholdGoDirection.None)); _cbx_FromDirection.Items.Add(new ComboBox_Direction(ThresholdGoDirection.Above.ToString(), ThresholdGoDirection.Above)); _cbx_FromDirection.Items.Add(new ComboBox_Direction(ThresholdGoDirection.Below.ToString(), ThresholdGoDirection.Below)); _cbx_FromDirection.SelectedIndex = (int)CurrentData.Direction; _ckBx_IgnoreHalfUnit.Checked = CurrentData.IgnoreHalfUnit; _ckBx_IgnoreHalfUnit.AutoCheck = true; }
public String Create(ThresholdModel thresholdModel) { using (var connection = new SqlConnection(Constant.getDatabaseConnectionString())) { SeverityModel severity = connection .Query <SeverityModel>("select * from severity where severityName=@sn", new { sn = thresholdModel.Severity }).FirstOrDefault(); int rows = connection.Execute( "insert into threshold(indexId, deviceId, operator, thresholdValue, ruleName, description, severity) values(@iid, @did, @o, @tv, @rn, @d, @sid)", new { iid = thresholdModel.IndexId, did = thresholdModel.DeviceId, o = thresholdModel.Operator, tv = thresholdModel.ThresholdValue, rn = thresholdModel.RuleName, d = thresholdModel.Description, sid = severity.Id }); return(rows == 1 ? "success" : "error"); } }
[InlineData("PRESSURE", "0001", ">", 100, null, null, "通知")] // 暂时无可用测试样例 public async Task PostSuccess(String IndexId, String DeviceId, String Operator, Double ThresholdValue, String RuleName, String Description, String Severity) { var data = new ThresholdModel { IndexId = IndexId, DeviceId = DeviceId, Operator = Operator, ThresholdValue = ThresholdValue, RuleName = RuleName, Description = Description, Severity = Severity }; var content = new StringContent(data.ToJson(), Encoding.UTF8, "text/json"); var response = await this._httpClient.PostAsync("api/threshold", content); var result = response.Content.ReadAsStringAsync().Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Contains("\"c\":200,\"m\":\"success\",\"d\":\"success\"", result); }
public AlarmInfoModel AlarmInfoGenerator(DeviceDataModel deviceData, ThresholdModel threshold) { AlarmInfoModel alarmInfo = new AlarmInfoModel { AlarmInfo = threshold.Description, DeviceId = deviceData.DeviceId, IndexId = deviceData.IndexId, IndexName = deviceData.IndexName, IndexValue = deviceData.IndexValue, ThresholdValue = threshold.ThresholdValue, Timestamp = DateTime.Now, Severity = threshold.Severity, Processed = "No" }; if (threshold.Operator == "equal") { if (deviceData.IndexValue != threshold.ThresholdValue) { return(alarmInfo); } } else if (threshold.Operator == "less") { if (deviceData.IndexValue > threshold.ThresholdValue) { return(alarmInfo); } } else { if (deviceData.IndexValue < threshold.ThresholdValue) { return(alarmInfo); } } return(null); }
public String Update(int id, ThresholdModel thresholdModel) { using (var connection = new MySqlConnection(Constant.getDatabaseConnectionString())) { SeverityModel severity = connection .Query <SeverityModel>("select * from severity where severityName=@sn", new { sn = thresholdModel.Severity }).FirstOrDefault(); int rows = connection.Execute( "update threshold set indexId=@iid, deviceId=@did, operator=@o, thresholdValue=@tv, ruleName=@rn, description=@d, severity=@sid where id=@i", new { i = id, iid = thresholdModel.IndexId, did = thresholdModel.DeviceId, o = thresholdModel.Operator, tv = thresholdModel.ThresholdValue, rn = thresholdModel.RuleName, d = thresholdModel.Description, sid = severity.Id }); return(rows == 1 ? "success" : "error"); } }
public void Test_UnitPopulationToSettings_UsingSameSettingArgument() { var thresholdRepository = new Mock <IThresholdRepository>(); thresholdRepository.Setup(m => m.GetAll()).Returns(new List <IThresholdData>()); ThresholdModel model = new ThresholdModel(new ThermometerModel(), thresholdRepository.Object); // initial Assert.AreEqual(TemperatureUnit.Celsius, model.CurrentTemperatureUnit); IThresholdData setting = model.ThresholdSettings[0]; Assert.AreEqual(0.0, setting.Temperature); setting = model.ThresholdSettings[1]; Assert.AreEqual(100.0, setting.Temperature); // act model.PopulateTempUnitToSettings(TemperatureUnit.Celsius); Assert.AreEqual(TemperatureUnit.Celsius, model.CurrentTemperatureUnit); setting = model.ThresholdSettings[0]; Assert.AreEqual(0.0, setting.Temperature); setting = model.ThresholdSettings[1]; Assert.AreEqual(100.0, setting.Temperature); }
public Task <IActionResult> SetThresholdBatch([FromBody] ThresholdModel thresholdModel) { return(null); }