crtTotalThreatScore function

Future crtTotalThreatScore(
  1. dynamic type
)

Calculate total risk score

Implementation

Future crtTotalThreatScore(var type) async {
  var sumNumerator = 0.0;
  var sumDenominator = 0.0;
  var threatScore = {};

  ///check type to select device metric or user metric
  type == Types.devices
      ? threatScore = CoreValues.deviceThreatScore
      : threatScore = CoreValues.userThreatScore;

  logger.d('deviceThreatScore => ${CoreValues.deviceThreatScore}');
  logger.d('userThreatScore => ${CoreValues.userThreatScore}');


  ///loop based on unique geiger threat uuid (12)
  for (String threatUUID in CoreValues.geigerThreatUUID) {

    ///Get threat metric about company type
    var rpts = await riskMetrics(threatUUID);
    logger.d('rpts => $rpts');
    ///Calculate rpt (threat metric about company type) * threat score
    for (var rpt in rpts) {
      logger.d('indiC crtTotalThreatScore_threatScore[threatUUID] $threatScore[threatUUID]');
      logger.d('indiC-crtTotalThreatScore_rpt $rpt');
      sumNumerator += threatScore[threatUUID] * rpt;
      sumDenominator += rpt;
    }
  }
  logger.d('indiC crtTotalThreatScore_sumNumerator $sumNumerator');
  logger.d('indiC crtTotalThreatScore_sumDenominator $sumDenominator');
  var gspUser = sumNumerator / sumDenominator;

  ///the metrics data is something wrong, it can be occurred.
  if(gspUser.isNaN) {
    logger.e('*******Wrong Factor******, Please check data');
    gspUser = 0.0;
  }


  return gspUser.toString();
}