getMetrics function

Future getMetrics(
  1. dynamic type,
  2. dynamic uuid
)

Implementation

Future getMetrics(var type, var uuid) async {
  for (var pluginsUUID in Storage.pluginUUIDs) {
    //  print(':$type:' + UUID+':'+pluginsUUID+':data:metrics');
    try {
      var metricNode = await Storage.controller!
          .get(':$type:' + uuid + ':' + pluginsUUID + ':data:metrics');

      var childrenNodes = await metricNode.getChildren();

      var metricNodeIterator = childrenNodes.entries.iterator;

      while (metricNodeIterator.moveNext()) {
        var normalizationValue = await normalization(metricNodeIterator);

        var threatsImpactNode =
            await metricNodeIterator.current.value.getValue('threatsImpact');

        var threatsImpacts = threatsImpactNode!.getValue('en')!.split(';');

        for (var list in threatsImpacts) {
          var threatsImpact = list.split(',');

          //  print(metricNodeIterator.current.value.getValue('flag')!.getValue('en'));
          var flagNode =
              await metricNodeIterator.current.value.getValue('flag');

          if (flagNode!.getValue('en') == '1') {
            Node impactNormal = NodeImpl('', '');
            await impactNormal
                .addValue(NodeValueImpl('impact', threatsImpact[1]));
            await impactNormal.addValue(
                NodeValueImpl('normal', normalizationValue.toString()));

            //type == types.Devices ? coreValues.devicePositive[threatsImpact[0]]!.add(impactNormal) : coreValues.userPositive[threatsImpact[0]]!.add(impactNormal);

            if (type == Types.devices) {
              try {
                CoreValues.devicePositive[threatsImpact[0]]!.add(impactNormal);
              } catch (e) {
                var temp = <Node>[];
                temp.add(impactNormal);
                CoreValues.devicePositive[threatsImpact[0]] = temp;
              }
            } else {
              try {
                CoreValues.userPositive[threatsImpact[0]]!.add(impactNormal);
              } catch (e) {
                var temp = <Node>[];
                temp.add(impactNormal);
                CoreValues.userPositive[threatsImpact[0]] = temp;
              }
            }
          } else {
            Node impactNormal = NodeImpl('', '');
            await impactNormal
                .addValue(NodeValueImpl('impact', threatsImpact[1]));
            await impactNormal.addValue(
                NodeValueImpl('normal', normalizationValue.toString()));
            //   type == types.Devices ? coreValues.deviceNegative[threatsImpact[0]]!.add(impactNormal) : coreValues.userNegative[threatsImpact[0]]!.add(impactNormal);

            if (type == Types.devices) {
              try {
                CoreValues.deviceNegative[threatsImpact[0]]!.add(impactNormal);
              } catch (e) {
                var temp = <Node>[];
                temp.add(impactNormal);
                CoreValues.deviceNegative[threatsImpact[0]] = temp;
              }
            } else {
              try {
                CoreValues.userNegative[threatsImpact[0]]!.add(impactNormal);
              } catch (e) {
                var temp = <Node>[];
                temp.add(impactNormal);
                CoreValues.userNegative[threatsImpact[0]] = temp;
              }
            }
          }
        }
      }
    } catch (e) {
      continue;
    }
  }
}