123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- function [result, msg] = ConditionCheck(check)
- result = 0;
- msg = '';
- if check.fdb.Length < 2
- msg = 'Not enough data to verify condition';
- return;
- end
- if check.tolerance <= 0
- msg = 'Invalid tolerance setting';
- return;
- end
- if check.ref.Time(1) > 0
- check.ref = addsample(check.ref, 'Data', 0, 'Time', 0);
- end
- if check.ref.Time(end) < check.fdb.Time(end)
- check.ref = addsample(check.ref, 'Data', check.ref.Data(end), 'Time', check.fdb.Time(end));
- end
- if check.preprocess == 0
- % 不需要对数据进行预处理
- if isa(check.time, 'double') || isa(check.time, 'char')
- if isa(check.time, 'char')
- test_time = check.fdb.Time(end);
- else
- test_time = check.time;
- end
-
- if max(test_time) > check.fdb.Time(end)
- msg = 'Check time out of range';
- return;
- end
- if check.refIntp
- check.ref_cmp = resample(check.ref, test_time);
- else
- check.ref_cmp = resample(check.ref, test_time, 'zoh');
- end
- if check.fdbIntp
- check.fdb_cmp = resample(check.fdb, test_time);
- else
- check.fdb_cmp = resample(check.fdb, test_time, 'zoh');
- end
- res = check.condition.Test(check.ref_cmp.Data, check.fdb_cmp.Data, check.tolerance);
- if all(res)
- result = 1;
- msg = sprintf('[%s]: [%s] [%s] check passed', check.tag, check.fdb_name, check.condition.Name);
- return;
- else
- fail = not(res);
- fail_index = find(fail);
- result = 0;
- 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)));
- return;
- end
- else
- result = 0;
- msg = 'Invalid check time setting';
- return;
- end
- else
- % 需要对数据进行预处理,即检查时间段内的情况
- test_time = check.fdb.time(find(and(check.fdb.Time > check.time(1), check.fdb.Time > check.time(1))));
- if check.refIntp
- check.ref_cmp = resample(check.ref, test_time);
- else
- check.ref_cmp = resample(check.ref, test_time, 'zoh');
- end
- if check.fdbIntp
- check.fdb_cmp = resample(check.fdb, test_time);
- else
- check.fdb_cmp = resample(check.fdb, test_time, 'zoh');
- end
- switch (check.adv)
- case {'A', 'Always'}
- res = check.condition.Test(check.ref_cmp.Data, check.fdb_cmp.Data, check.tolerance);
- case {'R', 'RMS'}
- case {'M', 'Mean'}
- res = check.condition.Test(mean(check.ref_cmp), mean(check.fdb_cmp), check.tolerance);
- case {'P', 'Peak2Peak'}
- res = check.condition.Test(check.ref_cmp.Data(1), max(check.fdb_cmp) - min(check.fdb_cmp), check.tolerance);
- end
- if all(res)
- result = 1;
- msg = sprintf('[%s]: [%s] [%s] check passed', check.tag, check.fdb_name, check.condition.Name);
- return;
- else
- fail = not(res);
- fail_index = find(fail);
- result = 0;
- 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))));
- return;
- end
- end
- end
|