Skip to content

Commit

Permalink
Use a global grouping sequence for analytics display
Browse files Browse the repository at this point in the history
Also regenerated database procs.
  • Loading branch information
randywoods1 committed Nov 19, 2024
1 parent c8ba83a commit 1bc696c
Show file tree
Hide file tree
Showing 18 changed files with 720 additions and 32 deletions.
3 changes: 1 addition & 2 deletions CSETWebNg/src/assets/settings/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
"port": "5000",
"apiIdentifier": "api"
},
"csetAnalyticsUrlAAAAAAAAAAA": "http://csetac:5210/api/analytics/maturity?",
"csetAnalyticsUrl": "http://localhost:5002/api/analytics/maturitynew?",
"csetAnalyticsUrl": "http://localhost:5002/api/analytics/maturity/bars?",
"csetGithubApiUrl": "https://api.github.com/repos/cisagov/cset/releases/latest",
"helpContactEmail": "[email protected]",
"helpContactPhone": "",
Expand Down
6 changes: 5 additions & 1 deletion Database Scripts/Functions/func_MQ.func.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

-- =============================================
-- Author: Randy Woods
-- Create date: 10-OCT-2023
Expand Down Expand Up @@ -34,7 +35,10 @@ RETURNS
[Scope] [nvarchar](250) NULL,
[Recommend_Action] [nvarchar](max) NULL,
[Risk_Addressed] [nvarchar](max) NULL,
[Services] [nvarchar](max) NULL
[Services] [nvarchar](max) NULL,
[Outcome] nvarchar(max) null,
[Security_Practice] nvarchar(max) null,
[Implementation_Guides] nvarchar(max) null
)
AS
BEGIN
Expand Down
19 changes: 19 additions & 0 deletions Database Scripts/Stored Procedures/FillAll.proc.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[FillAll]
-- Add the parameters for the stored procedure here
@Assessment_Id int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
exec FillEmptyMaturityQuestionsForAnalysis @assessment_id
exec FillEmptyQuestionsForAnalysis @assessment_id
END
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

-- =============================================
-- Author: Randy Woods
-- Create date: 09/10/2024
-- Description: Create empty data for questions that have not been filled out.
-- This version of the proc is designed for deliberately fleshing out SSG questions
-- because their relevance is not determined by AVAILABLE_MATURITY_MODELS.
-- =============================================
CREATE PROCEDURE [dbo].[FillEmptyMaturityQuestionsForModel]
@Assessment_Id int,
@Model_Id int
AS
BEGIN
DECLARE @result int;
begin
BEGIN TRANSACTION;
EXEC @result = sp_getapplock @Resource = '[Answer]', @LockMode = 'Exclusive';
INSERT INTO [dbo].[ANSWER] ([Question_Or_Requirement_Id],[Answer_Text],[Question_Type],[Assessment_Id])
select mq.Mat_Question_Id,Answer_Text = 'U', Question_Type='Maturity', Assessment_Id = @Assessment_Id
from [dbo].[MATURITY_QUESTIONS] mq
where Maturity_Model_Id = @Model_Id
and Mat_Question_Id not in
(select Question_Or_Requirement_Id from [dbo].[ANSWER]
where Assessment_Id = @Assessment_Id and Maturity_Model_Id = @Model_Id)
IF @result = -3
BEGIN
ROLLBACK TRANSACTION;
END
ELSE
BEGIN
EXEC sp_releaseapplock @Resource = '[Answer]';
COMMIT TRANSACTION;
END
end

END
/****** Object: StoredProcedure [dbo].[FillEmptyQuestionsForAnalysis] Script Date: 12/16/2020 11:01:33 AM ******/
SET ANSI_NULLS ON
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

-- =============================================
-- Author: WOODRK
-- Create date: 8/29/2024
-- Description: Generically return answer counts for all groupings in
-- an assessment's maturity model
-- =============================================
CREATE PROCEDURE [dbo].[GetAnswerCountsForGroupings]
@assessmentId int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

exec [FillEmptyMaturityQuestionsForAnalysis] @assessmentId

select Title, Sequence, Grouping_Id, Parent_Id, Answer_Text, count(*) as AnsCount
from (
select mg.Title, mg.Sequence, mg.grouping_id, mg.Parent_Id, a.Answer_Text
from answer a
left join maturity_questions mq on a.Question_Or_Requirement_Id = mq.Mat_Question_Id and a.Question_Type = 'maturity'
left join maturity_groupings mg on mq.Grouping_Id = mg.Grouping_Id
where assessment_id = @assessmentId
) b
group by title, sequence, grouping_id, parent_id, answer_text
order by sequence, answer_text
END
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

-- =============================================
-- Author: Randy Woods
-- Create date: 15 November 2022
Expand All @@ -7,14 +8,22 @@
-- specific grouping? g.Parent_Id = X
-- =============================================
CREATE PROCEDURE [dbo].[GetAnswerDistribGroupings]
@assessmentId int
@assessmentId int,
@modelId int = null
AS
BEGIN
SET NOCOUNT ON;
exec FillEmptyMaturityQuestionsForAnalysis @assessmentId

-- get the main model ID for the assessment
declare @maturityModelId int = (select model_id from AVAILABLE_MATURITY_MODELS where Assessment_Id = @assessmentId)

-- if the caller specified a model ID, use that instead
if @modelId is not null
BEGIN
select @maturityModelId = @modelId
END

select [grouping_id], [title], [answer_text], count(answer_text) as [answer_count]
from (
select g.grouping_id, g.title, g.sequence, a.Answer_Text
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

-- =============================================
-- Author: WOODRK
-- Create date: 8/29/2024
-- Description:
-- =============================================
CREATE PROCEDURE [dbo].[GetMaturityComparisonBestToWorst]
@assessment_id int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;


SELECT Assessment_Id,
AssessmentName = Alias,
Name = Title,
*
--AlternateCount = [I],
--AlternateValue = Round(((cast(([I]) as float)/isnull(nullif(Total,0),1)))*100,2),
--NaCount = [S],
--NaValue = Round(((cast(([S]) as float)/isnull(nullif(Total,0),1)))*100,2),
--NoCount = [N],
--NoValue = Round(((cast(([N]) as float)/isnull(nullif(Total,0),1)))*100,2),
--TotalCount = Total,
--TotalValue = Total,
--UnansweredCount = [U],
--UnansweredValue = Round(cast([U] as float)/Total*100,2),
--YesCount = [Y],
--YesValue = Round((cast(([Y]) as float)/isnull(nullif(Total,0),1))*100,2),
--Value = Round(((cast(([Y]+ isnull([I],0)) as float)/isnull(nullif((Total-[S]),0),1)))*100,2)
FROM
(
select b.Assessment_Id, f.Alias, b.Title, b.Answer_Text, isnull(c.Value,0) as Value,
Total = sum(c.Value) over(partition by b.Assessment_Id, b.Title)
from
(select distinct a.[Assessment_Id], g.Title, l.answer_Text
from answer_lookup l, (select * from Answer_Maturity where assessment_id = @assessment_id) a
join [MATURITY_QUESTIONS] q on a.Question_Or_Requirement_Id = q.Mat_Question_Id
join MATURITY_GROUPINGS g on q.Grouping_Id = g.Grouping_Id
) b left join
(select a.Assessment_Id, g.Title, a.Answer_Text, count(a.answer_text) as Value
from (select * from Answer_Maturity where assessment_id = @assessment_id) a
join [MATURITY_QUESTIONS] q on a.Question_Or_Requirement_Id = q.Mat_Question_Id
join MATURITY_GROUPINGS g on q.Grouping_Id = g.Grouping_Id
group by Assessment_Id, g.Title, a.Answer_Text) c
on b.Assessment_Id = c.Assessment_Id and b.Title = c.Title and b.Answer_Text = c.Answer_Text
join ASSESSMENTS f on b.Assessment_Id = f.Assessment_Id
) p


PIVOT
(
sum(value)
FOR answer_text IN ( [Y],[I],[S],[N],[U] )
) AS pvt
END
Loading

0 comments on commit 1bc696c

Please sign in to comment.