crtThreatScore function

Future crtThreatScore(
  1. dynamic type
)

Implementation

Future crtThreatScore(var type) async {
  var positiveMetrics = 0.0;
  var negativeMetrics = 0.0;
  var implementedRecommendations = 0.0;
  var gspt = 0.0;
  var treatsScores = '';
  var threatScoreValues = <dynamic>[];

  for (String threatUUID in CoreValues.uuidThreats) {
    if (type == Types.devices) {
      positiveMetrics = await pnMetrics(CoreValues.devicePositive, threatUUID);
      negativeMetrics = await pnMetrics(CoreValues.deviceNegative, threatUUID);

      implementedRecommendations =
          await recoMetrics(CoreValues.deviceRecommendation, threatUUID);
    } else if (type == Types.users) {
      positiveMetrics = await pnMetrics(CoreValues.userPositive, threatUUID);
      negativeMetrics = await pnMetrics(CoreValues.userNegative, threatUUID);
      implementedRecommendations =
          await recoMetrics(CoreValues.userRecommendation, threatUUID);
    }

    gspt = 50 +
        (50 * negativeMetrics) -
        (25 * (positiveMetrics + implementedRecommendations));

    var threatValues = <dynamic, dynamic>{};

    threatValues['threatId'] = threatUUID;
    threatValues['name'] = CoreValues.uuidName[threatUUID].toString().trim();

    var threat = <dynamic, dynamic>{};

    threat['threat'] = threatValues;
    threat['score'] = gspt;

    threatScoreValues.add(threat);

    treatsScores += '$threatUUID,$gspt;';

    type == Types.devices
        ? CoreValues.deviceThreatScore[threatUUID] = gspt
        : CoreValues.userThreatScore[threatUUID] = gspt;
  }

  //print(treats_scores);

  // jsonObject.threatScores['threatScores'] = threatScoreValues;
  JsonObject.threatScoreValues = threatScoreValues;

  return treatsScores;
}