主要内容

本页采用了机器翻译。点击此处可查看英文原文。

slmetric.metric.ResultClassification 类

命名空间: slmetric.metric

(待删除)访问度量数据阈值结果

以后的版本中将会删除度量仪表板用户界面、metricdashboard 函数、slmetric 包 API 以及相应的自定义项。有关详细信息,请参阅从度量盘迁移到模型可维护性仪表盘

描述

对于 slmetric.metric.Result 对象的 ValueAggregatedValue 属性,访问 slmetric.metric.ResultClassification 类的属性,以确定与 CompliantNonCompliantWarning 类别对应的度量数据范围。从 slmetric.metric.ResultClassification 对象中,确定您的度量数据属于以下三个类别中的哪一个。

构造

slmetric.metric.Result 对象的 Classifications 属性的值是 slmetric.metric.ResultClassification 对象。

属性

全部展开

访问此属性以确定模型度量和具有阈值的 slmetric.metric.Result 属性。

度量数据值分为以下四类之一:

  • Compliant - 在可接受范围内的度量数据。

  • Warning - 需要审核的度量数据。

  • Noncompliant - 需要您修改模型的度量数据。

  • 未分类 - 未设置阈值的度量数据。

如果至少有一个组件是 NonCompliant,则此属性返回 NonCompliant。如果至少有一个组件是 Warning 且没有组件是 NonCompliant,则此属性返回 Warning。如果所有组件都是 Compliant,则此类别返回 Compliant

此属性是只读的。

示例

全部折叠

对于 mathworks.metric.SimulinkBlockCount 度量,定义与 CompliantNonCompliantWarning 类别对应的 slmetric.metric.Result 值。对于 sldemo_mdl_ref 模型,运行度量引擎并对该度量的结果进行分类。

打开模型。

openExample('sldemo_mdlref_basic'); 

创建一个 slmetric.config.Configuration 对象。

CONF = slmetric.config.Configuration.new('name', 'Config');

获取 CONF 中的默认 slmetric.config.ThresholdConfiguration 对象。

TC = getThresholdConfigurations(CONF);

slmetric.config.Threshold 对象添加到 slmetric.config.ThresholdConfiguration 对象。此阈值用于 slmetric.metric.Results 对象的 mathworks.metrics.SimulinkBlockCount 度量和 Value 属性。

T = addThreshold(TC, 'mathworks.metrics.SimulinkBlockCount', 'Value');

slmetric.config.Threshold 对象包含与 Compliant 类别对应的默认 slmetric.config.Classification 对象。使用 slmetric.metric.MetricRange 类为 CompliantNonCompliantWarning 度量范围指定度量值。

C = getClassifications(T); % default classification is Compliant
C.Range.Start = 5;
C.Range.IncludeStart = 0;
C.Range.End = 100;
C.Range.IncludeEnd = 0;

C = addClassification(T,'Warning');
C.Range.Start = -inf;
C.Range.IncludeStart = 0;
C.Range.End = 5;
C.Range.IncludeEnd = 1

C = addClassification(T,'NonCompliant');
C.Range.Start = 100;
C.Range.IncludeStart = 1;
C.Range.End = inf;
C.Range.IncludeEnd = 0;

使用 validate 方法验证与 slmetric.config.ThresholdConfiguration 对象中的阈值对应的度量范围。

validate(T)

如果范围无效,您会收到一条错误消息。在此示例中,该范围有效。

保存对配置文件的更改。使用 slmetric.config.setActiveConfiguration 函数激活此配置以便度量引擎使用。

configName = 'Config.xml';
save(CONF,'FileName', configName);
slmetric.config.setActiveConfiguration(fullfile(pwd, configName));

创建一个 slmetric.Engine 对象,设置模型中的根以进行分析,并收集 mathworks.metrics.SimulinkBlockCount 度量的数据。

metric_engine = slmetric.Engine();
setAnalysisRoot(metric_engine, 'Root',  'sldemo_mdlref_basic');
execute(metric_engine, 'mathworks.metrics.SimulinkBlockCount');

获取返回一个 slmetric.metric.ResultCollection 对象数组 res_col 的模型度量数据。

res_col = getMetrics(metric_engine, 'mathworks.metrics.SimulinkBlockCount');

显示 mathworks.metrics.SimulinkBlockCount 度量的结果。

for n=1:length(res_col)
    if res_col(n).Status == 0
        result = res_col(n).Results;
        
        for m=1:length(result)
            disp(['MetricID: ',result(m).MetricID]);
            disp(['  ComponentPath: ', result(m).ComponentPath]);
            disp(['  Value: ', num2str(result(m).Value)]);
            disp(['  Classifications: ', result(m).Classifications.Classification.Category]);
            disp(['  Measures: ', num2str(result(m).Measures)]);
            disp(['  AggregatedMeasures: ', num2str(result(m).AggregatedMeasures)]);
        end
    else
        disp(['No results for:', result(n).MetricID]);
    end
    disp(' ');
end
MetricID: mathworks.metrics.SimulinkBlockCount
  ComponentPath: sldemo_mdlref_basic
  Value: 12
  Classifications: Compliant
  Measures: 
  AggregatedMeasures: 
MetricID: mathworks.metrics.SimulinkBlockCount
  ComponentPath: sldemo_mdlref_basic/More Info
  Value: 0
  Classifications: Warning
  Measures: 
  AggregatedMeasures: 
MetricID: mathworks.metrics.SimulinkBlockCount
  ComponentPath: sldemo_mdlref_counter
  Value: 18
  Classifications: Compliant
  Measures: 
  AggregatedMeasures:

对于 ComponentPath: sldemo_mdlref_basicComponentPath: sldemo_mdlref_counter,结果分别为 Compliant,因为它们的值分别为 1218。对于 ComponentPath: sldemo_mdlref_basic/More Info,由于 0 值,结果属于 Warning 类别。

版本历史记录

在 R2018b 中推出

全部折叠