-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BIA-1301]: Update fn_GetStudentGradesSummary to use descriptor const…
…ant (#228)
- Loading branch information
Showing
5 changed files
with
348 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...AnalyticsMiddleTier.DataStandard31/Equity/MSSQL/0014-fn_GetStudentGradesSummary-Alter.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
IF EXISTS ( | ||
SELECT 1 | ||
FROM INFORMATION_SCHEMA.ROUTINES | ||
WHERE ROUTINE_SCHEMA = 'analytics' | ||
AND ROUTINE_NAME = 'fn_GetStudentGradesSummary' | ||
) | ||
BEGIN | ||
DROP FUNCTION analytics.fn_GetStudentGradesSummary | ||
END | ||
GO | ||
|
||
CREATE OR ALTER FUNCTION analytics.fn_GetStudentGradesSummary ( | ||
@StudentKey VARCHAR(8000) | ||
,@SchoolKey VARCHAR(8000) | ||
) | ||
RETURNS VARCHAR(8000) | ||
AS | ||
BEGIN | ||
DECLARE @val VARCHAR(8000) | ||
|
||
SELECT @val = COALESCE(@VAL, '') + ( | ||
CAST(CONCAT ( | ||
', ' | ||
,CHAR(10) | ||
,course.CourseTitle | ||
,': ' | ||
,gradeFact.NumericGradeEarned | ||
) AS VARCHAR(8000)) | ||
) | ||
FROM edfi.Student | ||
INNER JOIN edfi.Grade gradeFact | ||
ON gradeFact.StudentUSI = Student.StudentUSI | ||
INNER JOIN edfi.CourseOffering | ||
ON CourseOffering.SchoolId = gradeFact.SchoolId | ||
AND CourseOffering.LocalCourseCode = gradeFact.LocalCourseCode | ||
AND CourseOffering.SchoolYear = gradeFact.SchoolYear | ||
AND CourseOffering.SessionName = gradeFact.SessionName | ||
INNER JOIN edfi.Course | ||
ON Course.CourseCode = CourseOffering.CourseCode | ||
AND Course.EducationOrganizationId = CourseOffering.EducationOrganizationId | ||
INNER JOIN edfi.Descriptor | ||
ON GradeTypeDescriptorId = Descriptor.DescriptorId | ||
INNER JOIN edfi.GradingPeriod | ||
ON gradeFact.GradingPeriodDescriptorId = GradingPeriod.GradingPeriodDescriptorId | ||
AND gradeFact.GradingPeriodSequence = GradingPeriod.PeriodSequence | ||
AND gradeFact.SchoolId = GradingPeriod.SchoolId | ||
AND gradeFact.GradingPeriodSchoolYear = GradingPeriod.SchoolYear | ||
INNER JOIN analytics_config.DescriptorMap | ||
ON DescriptorMap.DescriptorId = GradeTypeDescriptorId | ||
INNER JOIN analytics_config.DescriptorConstant | ||
ON DescriptorConstant.DescriptorConstantId = DescriptorMap.DescriptorConstantId | ||
WHERE DescriptorConstant.ConstantName IN ('GradeType.Semester') | ||
AND Student.StudentUniqueId = @StudentKey | ||
AND gradeFact.SchoolId = @SchoolKey | ||
ORDER BY gradeFact.GradingPeriodDescriptorId DESC | ||
,gradeFact.SchoolId DESC | ||
,GradingPeriod.BeginDate DESC; | ||
|
||
RETURN COALESCE(STUFF(COALESCE(@val, ''), 1, 3, ''),''); | ||
END |
64 changes: 64 additions & 0 deletions
64
...AnalyticsMiddleTier.DataStandard32/Equity/MSSQL/0014-fn_GetStudentGradesSummary-Alter.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
IF EXISTS ( | ||
SELECT 1 | ||
FROM INFORMATION_SCHEMA.ROUTINES | ||
WHERE ROUTINE_SCHEMA = 'analytics' | ||
AND ROUTINE_NAME = 'fn_GetStudentGradesSummary' | ||
) | ||
BEGIN | ||
DROP FUNCTION analytics.fn_GetStudentGradesSummary | ||
END | ||
GO | ||
|
||
CREATE OR ALTER FUNCTION analytics.fn_GetStudentGradesSummary ( | ||
@StudentKey VARCHAR(8000) | ||
,@SchoolKey VARCHAR(8000) | ||
) | ||
RETURNS VARCHAR(8000) | ||
AS | ||
BEGIN | ||
DECLARE @val VARCHAR(8000) | ||
|
||
SELECT @val = COALESCE(@VAL, '') + ( | ||
CAST(CONCAT ( | ||
', ' | ||
,CHAR(10) | ||
,course.CourseTitle | ||
,': ' | ||
,gradeFact.NumericGradeEarned | ||
) AS VARCHAR(8000)) | ||
) | ||
FROM edfi.Student | ||
INNER JOIN edfi.Grade gradeFact | ||
ON gradeFact.StudentUSI = Student.StudentUSI | ||
INNER JOIN edfi.CourseOffering | ||
ON CourseOffering.SchoolId = gradeFact.SchoolId | ||
AND CourseOffering.LocalCourseCode = gradeFact.LocalCourseCode | ||
AND CourseOffering.SchoolYear = gradeFact.SchoolYear | ||
AND CourseOffering.SessionName = gradeFact.SessionName | ||
INNER JOIN edfi.Course | ||
ON Course.CourseCode = CourseOffering.CourseCode | ||
AND Course.EducationOrganizationId = CourseOffering.EducationOrganizationId | ||
INNER JOIN edfi.Descriptor | ||
ON GradeTypeDescriptorId = Descriptor.DescriptorId | ||
INNER JOIN edfi.GradingPeriod | ||
ON gradeFact.GradingPeriodDescriptorId = GradingPeriod.GradingPeriodDescriptorId | ||
AND gradeFact.GradingPeriodSequence = GradingPeriod.PeriodSequence | ||
AND gradeFact.SchoolId = GradingPeriod.SchoolId | ||
AND gradeFact.GradingPeriodSchoolYear = GradingPeriod.SchoolYear | ||
INNER JOIN analytics_config.DescriptorMap | ||
ON DescriptorMap.DescriptorId = GradeTypeDescriptorId | ||
INNER JOIN analytics_config.DescriptorConstant | ||
ON DescriptorConstant.DescriptorConstantId = DescriptorMap.DescriptorConstantId | ||
WHERE DescriptorConstant.ConstantName IN ('GradeType.Semester') | ||
AND Student.StudentUniqueId = @StudentKey | ||
AND gradeFact.SchoolId = @SchoolKey | ||
ORDER BY gradeFact.GradingPeriodDescriptorId DESC | ||
,gradeFact.SchoolId DESC | ||
,GradingPeriod.BeginDate DESC; | ||
|
||
RETURN COALESCE(STUFF(COALESCE(@val, ''), 1, 3, ''),''); | ||
END |
78 changes: 78 additions & 0 deletions
78
...nalyticsMiddleTier.DataStandard32/Equity/PostgreSQL/0010-View-StudentHistoryDim-Alter.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
DROP VIEW IF EXISTS analytics.equity_StudentHistoryDim; | ||
|
||
CREATE | ||
OR REPLACE VIEW analytics.equity_StudentHistoryDim AS | ||
WITH AttendanceHist AS ( | ||
SELECT StudentSchoolKey | ||
,COUNT(1) AS DaysEnrolled | ||
,SUM(ReportedAsAbsentFromHomeRoom) AS DaysAbsent | ||
FROM analytics.chrab_ChronicAbsenteeismAttendanceFact | ||
GROUP BY StudentSchoolKey | ||
) | ||
,GradeList AS ( | ||
SELECT CONCAT ( | ||
studentSectionDim.StudentKey | ||
,'-' | ||
,studentSectionDim.SchoolKey | ||
) AS StudentSchoolKey | ||
,studentSectionDim.LastModifiedDate | ||
,STRING_AGG(CAST(CONCAT ( | ||
studentSectionDim.CourseTitle | ||
,': ' | ||
,gradeFact.NumericGradeEarned | ||
) AS VARCHAR(8000)), CONCAT(', ','') | ||
ORDER BY gradeFact.GradingPeriodKey DESC) AS GradeSummary | ||
FROM analytics.ews_StudentSectionGradeFact gradeFact | ||
INNER JOIN analytics.StudentSectionDim studentSectionDim | ||
ON gradeFact.StudentSectionKey = studentSectionDim.StudentSectionKey | ||
AND gradeFact.SectionKey = studentSectionDim.SectionKey | ||
INNER JOIN edfi.descriptor | ||
ON descriptor.codevalue = gradeFact.GradeType | ||
INNER JOIN analytics_config.DescriptorMap | ||
ON DescriptorMap.DescriptorId = descriptor.DescriptorId | ||
INNER JOIN analytics_config.DescriptorConstant | ||
ON DescriptorConstant.DescriptorConstantId = DescriptorMap.DescriptorConstantId | ||
WHERE DescriptorConstant.ConstantName IN ('GradeType.Semester') | ||
GROUP BY studentSectionDim.StudentKey | ||
,studentSectionDim.SchoolKey | ||
,studentSectionDim.LastModifiedDate | ||
) | ||
|
||
SELECT DISTINCT studentSchoolDim.StudentKey | ||
,studentSchoolDim.StudentSchoolKey | ||
,COALESCE(gradeFact.GradeSummary,'') AS GradeSummary | ||
,studentSchoolDim.SchoolKey AS CurrentSchoolKey | ||
,COALESCE((CAST((DaysEnrolled - DaysAbsent) AS DECIMAL) / CAST(DaysEnrolled AS DECIMAL) * 100), 100.00) AS AttendanceRate | ||
,( | ||
SELECT COUNT(1) | ||
FROM analytics.equity_StudentDisciplineActionDim discipline | ||
WHERE discipline.StudentSchoolKey = studentSchoolDim.StudentSchoolKey | ||
) AS ReferralsAndSuspensions | ||
,( | ||
SELECT STRING_AGG(CONCAT ( | ||
SchoolName | ||
,CASE WHEN(ssd.ExitWithdrawDate is not null) then ' ' else '' END | ||
,COALESCE(CAST(ssd.ExitWithdrawDate AS VARCHAR(10)), '') | ||
), CONCAT(', ',(CHR(10))) ORDER BY COALESCE(ssd.ExitWithdrawDate,'2200-01-01') DESC) | ||
FROM edfi.StudentSchoolAssociation ssd | ||
INNER JOIN edfi.Student st | ||
ON st.StudentUSI = ssd.StudentUSI | ||
INNER JOIN analytics.SchoolDim school | ||
ON school.SchoolKey = CAST(ssd.SchoolId AS VARCHAR) | ||
WHERE st.StudentUniqueId = studentSchoolDim.StudentKey | ||
) AS EnrollmentHistory | ||
,( | ||
SELECT MAX(MaxLastModifiedDate) | ||
FROM ( | ||
VALUES (studentSchoolDim.LastModifiedDate) | ||
) AS VALUE(MaxLastModifiedDate) | ||
) AS LastModifiedDate | ||
FROM analytics.StudentSchoolDim studentSchoolDim | ||
LEFT JOIN GradeList gradeFact | ||
ON gradeFact.StudentSchoolKey = studentSchoolDim.StudentSchoolKey | ||
LEFT OUTER JOIN AttendanceHist ah | ||
ON ah.StudentSchoolKey = studentSchoolDim.StudentSchoolKey; |
64 changes: 64 additions & 0 deletions
64
...AnalyticsMiddleTier.DataStandard33/Equity/MSSQL/0008-fn_GetStudentGradesSummary-Alter.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
IF EXISTS ( | ||
SELECT 1 | ||
FROM INFORMATION_SCHEMA.ROUTINES | ||
WHERE ROUTINE_SCHEMA = 'analytics' | ||
AND ROUTINE_NAME = 'fn_GetStudentGradesSummary' | ||
) | ||
BEGIN | ||
DROP FUNCTION analytics.fn_GetStudentGradesSummary | ||
END | ||
GO | ||
|
||
CREATE FUNCTION analytics.fn_GetStudentGradesSummary ( | ||
@StudentKey VARCHAR(8000) | ||
,@SchoolKey VARCHAR(8000) | ||
) | ||
RETURNS VARCHAR(8000) | ||
AS | ||
BEGIN | ||
DECLARE @val VARCHAR(8000) | ||
|
||
SELECT @val = COALESCE(@VAL, '') + ( | ||
CAST(CONCAT ( | ||
', ' | ||
,CHAR(10) | ||
,course.CourseTitle | ||
,': ' | ||
,gradeFact.NumericGradeEarned | ||
) AS VARCHAR(8000)) | ||
) | ||
FROM edfi.Student | ||
INNER JOIN edfi.Grade gradeFact | ||
ON gradeFact.StudentUSI = Student.StudentUSI | ||
INNER JOIN edfi.CourseOffering | ||
ON CourseOffering.SchoolId = gradeFact.SchoolId | ||
AND CourseOffering.LocalCourseCode = gradeFact.LocalCourseCode | ||
AND CourseOffering.SchoolYear = gradeFact.SchoolYear | ||
AND CourseOffering.SessionName = gradeFact.SessionName | ||
INNER JOIN edfi.Course | ||
ON Course.CourseCode = CourseOffering.CourseCode | ||
AND Course.EducationOrganizationId = CourseOffering.EducationOrganizationId | ||
INNER JOIN edfi.Descriptor | ||
ON GradeTypeDescriptorId = Descriptor.DescriptorId | ||
INNER JOIN edfi.GradingPeriod | ||
ON gradeFact.GradingPeriodDescriptorId = GradingPeriod.GradingPeriodDescriptorId | ||
AND gradeFact.GradingPeriodSequence = GradingPeriod.PeriodSequence | ||
AND gradeFact.SchoolId = GradingPeriod.SchoolId | ||
AND gradeFact.GradingPeriodSchoolYear = GradingPeriod.SchoolYear | ||
INNER JOIN analytics_config.DescriptorMap | ||
ON DescriptorMap.DescriptorId = GradeTypeDescriptorId | ||
INNER JOIN analytics_config.DescriptorConstant | ||
ON DescriptorConstant.DescriptorConstantId = DescriptorMap.DescriptorConstantId | ||
WHERE DescriptorConstant.ConstantName IN ('GradeType.Semester') | ||
AND Student.StudentUniqueId = @StudentKey | ||
AND gradeFact.SchoolId = @SchoolKey | ||
ORDER BY gradeFact.GradingPeriodDescriptorId DESC | ||
,gradeFact.SchoolId DESC | ||
,GradingPeriod.BeginDate DESC; | ||
|
||
RETURN COALESCE(STUFF(COALESCE(@val, ''), 1, 3, ''),''); | ||
END |
78 changes: 78 additions & 0 deletions
78
...nalyticsMiddleTier.DataStandard33/Equity/PostgreSQL/0006-View-StudentHistoryDim-Alter.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
DROP VIEW IF EXISTS analytics.equity_StudentHistoryDim; | ||
|
||
CREATE | ||
OR REPLACE VIEW analytics.equity_StudentHistoryDim AS | ||
WITH AttendanceHist AS ( | ||
SELECT StudentSchoolKey | ||
,COUNT(1) AS DaysEnrolled | ||
,SUM(ReportedAsAbsentFromHomeRoom) AS DaysAbsent | ||
FROM analytics.chrab_ChronicAbsenteeismAttendanceFact | ||
GROUP BY StudentSchoolKey | ||
) | ||
,GradeList AS ( | ||
SELECT CONCAT ( | ||
studentSectionDim.StudentKey | ||
,'-' | ||
,studentSectionDim.SchoolKey | ||
) AS StudentSchoolKey | ||
,studentSectionDim.LastModifiedDate | ||
,STRING_AGG(CAST(CONCAT ( | ||
studentSectionDim.CourseTitle | ||
,': ' | ||
,gradeFact.NumericGradeEarned | ||
) AS VARCHAR(8000)), CONCAT(', ','') | ||
ORDER BY gradeFact.GradingPeriodKey DESC) AS GradeSummary | ||
FROM analytics.ews_StudentSectionGradeFact gradeFact | ||
INNER JOIN analytics.StudentSectionDim studentSectionDim | ||
ON gradeFact.StudentSectionKey = studentSectionDim.StudentSectionKey | ||
AND gradeFact.SectionKey = studentSectionDim.SectionKey | ||
INNER JOIN edfi.descriptor | ||
ON descriptor.codevalue = gradeFact.GradeType | ||
INNER JOIN analytics_config.DescriptorMap | ||
ON DescriptorMap.DescriptorId = descriptor.DescriptorId | ||
INNER JOIN analytics_config.DescriptorConstant | ||
ON DescriptorConstant.DescriptorConstantId = DescriptorMap.DescriptorConstantId | ||
WHERE DescriptorConstant.ConstantName IN ('GradeType.Semester') | ||
GROUP BY studentSectionDim.StudentKey | ||
,studentSectionDim.SchoolKey | ||
,studentSectionDim.LastModifiedDate | ||
) | ||
|
||
SELECT DISTINCT studentSchoolDim.StudentKey | ||
,studentSchoolDim.StudentSchoolKey | ||
,COALESCE(gradeFact.GradeSummary,'') AS GradeSummary | ||
,studentSchoolDim.SchoolKey AS CurrentSchoolKey | ||
,COALESCE((CAST((DaysEnrolled - DaysAbsent) AS DECIMAL) / CAST(DaysEnrolled AS DECIMAL) * 100), 100.00) AS AttendanceRate | ||
,( | ||
SELECT COUNT(1) | ||
FROM analytics.equity_StudentDisciplineActionDim discipline | ||
WHERE discipline.StudentSchoolKey = studentSchoolDim.StudentSchoolKey | ||
) AS ReferralsAndSuspensions | ||
,( | ||
SELECT STRING_AGG(CONCAT ( | ||
SchoolName | ||
,CASE WHEN(ssd.ExitWithdrawDate is not null) then ' ' else '' END | ||
,COALESCE(CAST(ssd.ExitWithdrawDate AS VARCHAR(10)), '') | ||
), CONCAT(', ',(CHR(10))) ORDER BY COALESCE(ssd.ExitWithdrawDate,'2200-01-01') DESC) | ||
FROM edfi.StudentSchoolAssociation ssd | ||
INNER JOIN edfi.Student st | ||
ON st.StudentUSI = ssd.StudentUSI | ||
INNER JOIN analytics.SchoolDim school | ||
ON school.SchoolKey = CAST(ssd.SchoolId AS VARCHAR) | ||
WHERE st.StudentUniqueId = studentSchoolDim.StudentKey | ||
) AS EnrollmentHistory | ||
,( | ||
SELECT MAX(MaxLastModifiedDate) | ||
FROM ( | ||
VALUES (studentSchoolDim.LastModifiedDate) | ||
) AS VALUE(MaxLastModifiedDate) | ||
) AS LastModifiedDate | ||
FROM analytics.StudentSchoolDim studentSchoolDim | ||
LEFT JOIN GradeList gradeFact | ||
ON gradeFact.StudentSchoolKey = studentSchoolDim.StudentSchoolKey | ||
LEFT OUTER JOIN AttendanceHist ah | ||
ON ah.StudentSchoolKey = studentSchoolDim.StudentSchoolKey; |