ConditionCheck.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function [result, msg] = ConditionCheck(check)
  2. result = 0;
  3. msg = '';
  4. if check.fdb.Length < 2
  5. msg = 'Not enough data to verify condition';
  6. return;
  7. end
  8. if check.tolerance <= 0
  9. msg = 'Invalid tolerance setting';
  10. return;
  11. end
  12. if check.ref.Time(1) > 0
  13. check.ref = addsample(check.ref, 'Data', 0, 'Time', 0);
  14. end
  15. if check.ref.Time(end) < check.fdb.Time(end)
  16. check.ref = addsample(check.ref, 'Data', check.ref.Data(end), 'Time', check.fdb.Time(end));
  17. end
  18. if check.preprocess == 0
  19. % 不需要对数据进行预处理
  20. if isa(check.time, 'double') || isa(check.time, 'char')
  21. if isa(check.time, 'char')
  22. test_time = check.fdb.Time(end);
  23. else
  24. test_time = check.time;
  25. end
  26. if max(test_time) > check.fdb.Time(end)
  27. msg = 'Check time out of range';
  28. return;
  29. end
  30. if check.refIntp
  31. check.ref_cmp = resample(check.ref, test_time);
  32. else
  33. check.ref_cmp = resample(check.ref, test_time, 'zoh');
  34. end
  35. if check.fdbIntp
  36. check.fdb_cmp = resample(check.fdb, test_time);
  37. else
  38. check.fdb_cmp = resample(check.fdb, test_time, 'zoh');
  39. end
  40. res = check.condition.Test(check.ref_cmp.Data, check.fdb_cmp.Data, check.tolerance);
  41. if all(res)
  42. result = 1;
  43. msg = sprintf('[%s]: [%s] [%s] check passed', check.tag, check.fdb_name, check.condition.Name);
  44. return;
  45. else
  46. fail = not(res);
  47. fail_index = find(fail);
  48. result = 0;
  49. msg = sprintf('[%s]: [%s] [%s] check failed at time {%s}: Expected {%s}; Get {%s}', check.tag, check.fdb_name, check.condition.Name, mat2str(test_time(fail_index)), mat2str(check.ref_cmp.Data(fail_index)), mat2str(check.fdb_cmp.Data(fail_index)));
  50. return;
  51. end
  52. else
  53. result = 0;
  54. msg = 'Invalid check time setting';
  55. return;
  56. end
  57. else
  58. % 需要对数据进行预处理,即检查时间段内的情况
  59. test_time = check.fdb.time(find(and(check.fdb.Time > check.time(1), check.fdb.Time > check.time(1))));
  60. if check.refIntp
  61. check.ref_cmp = resample(check.ref, test_time);
  62. else
  63. check.ref_cmp = resample(check.ref, test_time, 'zoh');
  64. end
  65. if check.fdbIntp
  66. check.fdb_cmp = resample(check.fdb, test_time);
  67. else
  68. check.fdb_cmp = resample(check.fdb, test_time, 'zoh');
  69. end
  70. switch (check.adv)
  71. case {'A', 'Always'}
  72. res = check.condition.Test(check.ref_cmp.Data, check.fdb_cmp.Data, check.tolerance);
  73. case {'R', 'RMS'}
  74. case {'M', 'Mean'}
  75. res = check.condition.Test(mean(check.ref_cmp), mean(check.fdb_cmp), check.tolerance);
  76. case {'P', 'Peak2Peak'}
  77. res = check.condition.Test(check.ref_cmp.Data(1), max(check.fdb_cmp) - min(check.fdb_cmp), check.tolerance);
  78. end
  79. if all(res)
  80. result = 1;
  81. msg = sprintf('[%s]: [%s] [%s] check passed', check.tag, check.fdb_name, check.condition.Name);
  82. return;
  83. else
  84. fail = not(res);
  85. fail_index = find(fail);
  86. result = 0;
  87. msg = sprintf('[%s]: [%s] [%s-%s] check failed in duration {%s}: Expected {%s}; Get {%s}', check.tag, check.fdb_name, check.adv, check.condition.Name, mat2str(check.time), mat2str(check.ref_cmp.Data(fail_index(1))), mat2str(check.fdb_cmp.Data(fail_index(1))));
  88. return;
  89. end
  90. end
  91. end