Skip to content

Commit

Permalink
Merge pull request #3555 from cisagov/refactor/acet-to-own-manager
Browse files Browse the repository at this point in the history
Refactor/acet to own manager
  • Loading branch information
randywoods authored Oct 3, 2023
2 parents c9ae1cb + b2553ec commit 541af1b
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 127 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
using CSETWebCore.Business.Acet;
using CSETWebCore.DataLayer.Manual;
using CSETWebCore.DataLayer.Model;
using CSETWebCore.Interfaces.AdminTab;
using CSETWebCore.Interfaces.Helpers;
using CSETWebCore.Model.Maturity;
using CSETWebCore.Model.Question;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSETWebCore.Business.Maturity
{
public class ACETMaturityBusiness : MaturityBusiness
{
private CSETContext _context;
public ACETMaturityBusiness(CSETContext context, IAssessmentUtil assessmentUtil, IAdminTabBusiness adminTabBusiness) : base(context, assessmentUtil, adminTabBusiness)
{
this._context = context;
}

public AVAILABLE_MATURITY_MODELS ProcessModelDefaults(int assessmentId, string installationMode)
{
//if the available maturity model is not selected and the application is CSET
//the default is EDM
//if the application is ACET the default is ACET

return base.ProcessModelDefaults(assessmentId, installationMode, 1);
}

// --

public MaturityResponse GetMaturityQuestions(int assessmentId, string installationMode, bool fill, int groupingId, bool spanishFlag = false)
{
var response = new MaturityResponse();
var myModel = ProcessModelDefaults(assessmentId, installationMode, 1);

var myModelDefinition = _context.MATURITY_MODELS.Where(x => x.Maturity_Model_Id == myModel.model_id).FirstOrDefault();

if (myModelDefinition == null)
{
return response;
}

response.ModelId = myModelDefinition.Maturity_Model_Id;
response.ModelName = myModelDefinition.Model_Name;

if (response.ModelName == "ACET")
{
response.OverallIRP = GetOverallIrpNumber(assessmentId);
response.MaturityTargetLevel = response.OverallIRP;
}

response = base.GetMaturityQuestions(assessmentId, installationMode, fill, groupingId, spanishFlag);

return response;
}



/// <summary>
/// Returns the percentage of maturity questions that have been answered for the
/// current maturity level (IRP).
/// </summary>
/// <param name="assessmentId"></param>
/// <returns></returns>
public double GetAnswerCompletionRate(int assessmentId)
{
var irp = GetOverallIrpNumber(assessmentId);

// get the highest maturity level for the risk level (use the stairstep model)
var topMatLevel = GetTopMatLevelForRisk(irp);

var answerDistribution = _context.AcetAnswerDistribution(assessmentId, topMatLevel).ToList();

var answeredCount = 0;
var totalCount = 0;
foreach (var d in answerDistribution)
{
if (d.Answer_Text != "U")
{
answeredCount += d.Count;
}
totalCount += d.Count;
}

return ((double)answeredCount / (double)totalCount) * 100d;
}


/// <summary>
/// Returns the percentage of maturity questions that have been answered for the
/// current maturity level (IRP).
/// </summary>
/// <param name="assessmentId"></param>
/// <returns></returns>
public double GetIseAnswerCompletionRate(int assessmentId)
{
var irp = GetOverallIseIrpNumber(assessmentId);

// get the highest maturity level for the risk level (use the stairstep model)
var topMatLevel = GetIseTopMatLevelForRisk(irp);

var answerDistribution = _context.IseAnswerDistribution(assessmentId, topMatLevel).ToList();

var answeredCount = 0;
var totalCount = 0;
foreach (var d in answerDistribution)
{
if (d.Answer_Text != "U")
{
answeredCount += d.Count;
}
totalCount += d.Count;
}

return ((double)answeredCount / (double)totalCount) * 100d;
}



/// <summary>
/// Using the 'stairstep' model, determines the highest maturity level
/// that corresponds to the specified IRP/risk.
///
/// This stairstep model must match the stairstep defined in the UI -- getStairstepRequired(),
/// though this method only returns the top level.
/// </summary>
/// <param name="irp"></param>
/// <returns></returns>
private int GetTopMatLevelForRisk(int irp)
{
switch (irp)
{
case 1:
case 2:
return 1; // Baseline
case 3:
return 2; // Evolving
case 4:
return 3; // Intermediate
case 5:
return 4; // Advanced
}

return 0;
}


/// <summary>
/// Using the 'stairstep' model, determines the highest maturity level
/// that corresponds to the specified IRP/risk.
///
/// This stairstep model must match the stairstep defined in the UI -- getStairstepRequired(),
/// though this method only returns the top level.
/// </summary>
/// <param name="irp"></param>
/// <returns></returns>
private int GetIseTopMatLevelForRisk(int irp)
{
switch (irp)
{
case 1:
return 1; // SCUEP
case 2:
return 2; // CORE
case 3:
return 3; // CORE+
}

return 0;
}



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,12 @@ public void PersistMaturityLevel(int assessmentId, int level)
}


public AVAILABLE_MATURITY_MODELS ProcessModelDefaults(int assessmentId, string installationMode)
public AVAILABLE_MATURITY_MODELS ProcessModelDefaults(int assessmentId, string installationMode, int maturityModelId = 3)
{
//if the available maturity model is not selected and the application is CSET
//the default is EDM
//if the application is ACET the default is ACET
//see ACETMaturityBusiness implementation

var myModel = _context.AVAILABLE_MATURITY_MODELS
.Include(x => x.model)
Expand All @@ -632,7 +633,7 @@ public AVAILABLE_MATURITY_MODELS ProcessModelDefaults(int assessmentId, string i
myModel = new AVAILABLE_MATURITY_MODELS()
{
Assessment_Id = assessmentId,
model_id = (installationMode == "ACET") ? 1 : 3,
model_id = maturityModelId,
Selected = true
};
_context.AVAILABLE_MATURITY_MODELS.Add(myModel);
Expand Down Expand Up @@ -814,7 +815,11 @@ private LevelScore GetLevelScoreQuestions(Model.Nested.Grouping group, string le
public MaturityResponse GetMaturityQuestions(int assessmentId, string installationMode, bool fill, int groupingId, bool spanishFlag = false)
{
var response = new MaturityResponse();
return GetMaturityQuestions(assessmentId, installationMode, fill, groupingId, response, spanishFlag);
}

public MaturityResponse GetMaturityQuestions(int assessmentId, string installationMode, bool fill, int groupingId, MaturityResponse response, bool spanishFlag = false)
{
if (fill)
{
_context.FillEmptyMaturityQuestionsForAnalysis(assessmentId);
Expand Down Expand Up @@ -846,13 +851,6 @@ public MaturityResponse GetMaturityQuestions(int assessmentId, string installati

response.MaturityTargetLevel = GetMaturityTargetLevel(assessmentId);

if (response.ModelName == "ACET")
{
response.OverallIRP = GetOverallIrpNumber(assessmentId);
response.MaturityTargetLevel = response.OverallIRP;
}


// get the levels and their display names for this model
response.Levels = GetMaturityLevelsForModel(myModel.model_id, response.MaturityTargetLevel);

Expand Down Expand Up @@ -1170,119 +1168,6 @@ public int StoreAnswer(int assessmentId, Answer answer)
}


/// <summary>
/// Returns the percentage of maturity questions that have been answered for the
/// current maturity level (IRP).
/// </summary>
/// <param name="assessmentId"></param>
/// <returns></returns>
public double GetAnswerCompletionRate(int assessmentId)
{
var irp = GetOverallIrpNumber(assessmentId);

// get the highest maturity level for the risk level (use the stairstep model)
var topMatLevel = GetTopMatLevelForRisk(irp);

var answerDistribution = _context.AcetAnswerDistribution(assessmentId, topMatLevel).ToList();

var answeredCount = 0;
var totalCount = 0;
foreach (var d in answerDistribution)
{
if (d.Answer_Text != "U")
{
answeredCount += d.Count;
}
totalCount += d.Count;
}

return ((double)answeredCount / (double)totalCount) * 100d;
}


/// <summary>
/// Returns the percentage of maturity questions that have been answered for the
/// current maturity level (IRP).
/// </summary>
/// <param name="assessmentId"></param>
/// <returns></returns>
public double GetIseAnswerCompletionRate(int assessmentId)
{
var irp = GetOverallIseIrpNumber(assessmentId);

// get the highest maturity level for the risk level (use the stairstep model)
var topMatLevel = GetIseTopMatLevelForRisk(irp);

var answerDistribution = _context.IseAnswerDistribution(assessmentId, topMatLevel).ToList();

var answeredCount = 0;
var totalCount = 0;
foreach (var d in answerDistribution)
{
if (d.Answer_Text != "U")
{
answeredCount += d.Count;
}
totalCount += d.Count;
}

return ((double)answeredCount / (double)totalCount) * 100d;
}


/// <summary>
/// Using the 'stairstep' model, determines the highest maturity level
/// that corresponds to the specified IRP/risk.
///
/// This stairstep model must match the stairstep defined in the UI -- getStairstepRequired(),
/// though this method only returns the top level.
/// </summary>
/// <param name="irp"></param>
/// <returns></returns>
private int GetTopMatLevelForRisk(int irp)
{
switch (irp)
{
case 1:
case 2:
return 1; // Baseline
case 3:
return 2; // Evolving
case 4:
return 3; // Intermediate
case 5:
return 4; // Advanced
}

return 0;
}


/// <summary>
/// Using the 'stairstep' model, determines the highest maturity level
/// that corresponds to the specified IRP/risk.
///
/// This stairstep model must match the stairstep defined in the UI -- getStairstepRequired(),
/// though this method only returns the top level.
/// </summary>
/// <param name="irp"></param>
/// <returns></returns>
private int GetIseTopMatLevelForRisk(int irp)
{
switch (irp)
{
case 1:
return 1; // SCUEP
case 2:
return 2; // CORE
case 3:
return 3; // CORE+
}

return 0;
}


// The methods that follow were originally built for NCUA/ACET.
// It is hoped that they will eventually be refactored to fit a more
// 'generic' approach to maturity models.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public interface IMaturityBusiness
void PersistSelectedMaturityModel(int assessmentId, string modelName);
void ClearMaturityModel(int assessmentId);
void PersistMaturityLevel(int assessmentId, int level);
AVAILABLE_MATURITY_MODELS ProcessModelDefaults(int assessmentId, string installationMode);
object GetEdmPercentScores(int assessmentId);
MaturityResponse GetMaturityQuestions(int assessmentId, string installationMode, bool fill, int groupingId, bool spanishFlag);

Expand All @@ -33,7 +32,6 @@ void BuildSubGroupings(MaturityGrouping g, int? parentID,
List<FullAnswer> answers);

int StoreAnswer(int assessmentId, Answer answer);
double GetAnswerCompletionRate(int assessmentId);
List<MaturityDomain> GetMaturityAnswers(int assessmentId, bool spanishFlag = false);
bool GetTargetBandOnly(int assessmentId);
void SetTargetBandOnly(int assessmentId, bool value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ public IActionResult SetMaturityLevel([FromBody] int level)
public IActionResult GetQuestions([FromQuery] string installationMode, bool fill, int groupingId = 0, bool spanishFlag = false)
{
int assessmentId = _tokenManager.AssessmentForUser();

if (installationMode == "ACET")
{
return Ok(new ACETMaturityBusiness(_context, _assessmentUtil, _adminTabBusiness).GetMaturityQuestions(assessmentId, installationMode, fill, groupingId, spanishFlag));
}
return Ok(new MaturityBusiness(_context, _assessmentUtil, _adminTabBusiness).GetMaturityQuestions(assessmentId, installationMode, fill, groupingId, spanishFlag));
}

Expand Down Expand Up @@ -481,7 +484,7 @@ public IActionResult GetAnswerCompletionRate()
{
int assessmentId = _tokenManager.AssessmentForUser();

return Ok(new MaturityBusiness(_context, _assessmentUtil, _adminTabBusiness).GetAnswerCompletionRate(assessmentId));
return Ok(new ACETMaturityBusiness(_context, _assessmentUtil, _adminTabBusiness).GetAnswerCompletionRate(assessmentId));
}


Expand All @@ -495,7 +498,7 @@ public IActionResult GetIseAnswerCompletionRate()
{
int assessmentId = _tokenManager.AssessmentForUser();

return Ok(new MaturityBusiness(_context, _assessmentUtil, _adminTabBusiness).GetIseAnswerCompletionRate(assessmentId));
return Ok(new ACETMaturityBusiness(_context, _assessmentUtil, _adminTabBusiness).GetIseAnswerCompletionRate(assessmentId));
}


Expand Down

0 comments on commit 541af1b

Please sign in to comment.