Skip to content

Commit

Permalink
Merge pull request #34 from WyattBest/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
WyattBest authored Apr 20, 2021
2 parents 81cda57 + 0100e24 commit 6cb4ef1
Show file tree
Hide file tree
Showing 11 changed files with 1,387 additions and 945 deletions.
44 changes: 18 additions & 26 deletions SQL/[custom].[PS_updAcademicAppInfo].sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ GO
-- If @AppDecision is an accepted decision, admit fields will be populated. Admit date will be @AdmitdDate.
-- 2021-04-03 Wyatt Best: Fix missing PDC filters in some update statements. Could have caused multiple records to be affected if student had multiple applications in same YTS.
-- Change primary flag logic to be more conservative. Rewrote some statements for efficiency.
-- 2021-04-05 Wyatt Best: Added switch to control whether @Population will overwrite existing values. Used by MCNY.
-- =============================================
CREATE PROCEDURE [custom].[PS_updAcademicAppInfo] @PCID NVARCHAR(10)
,@Year NVARCHAR(4)
Expand Down Expand Up @@ -61,6 +62,7 @@ BEGIN

DECLARE @Today DATETIME = dbo.fnMakeDate(GETDATE())
,@Now DATETIME = dbo.fnMakeTime(GETDATE())
,@OverwritePopulation BIT = 1

--Setup for Matric and Admit field groups
IF @Matriculated = 1
Expand Down Expand Up @@ -330,9 +332,20 @@ BEGIN
AND DEGREE = @Degree
AND CURRICULUM = @Curriculum
AND APPLICATION_FLAG = 'Y'
AND @Population IS NOT NULL
AND (
[POPULATION] <> @Population
OR [POPULATION] IS NULL
@OverwritePopulation = 0
AND (
[POPULATION] IS NULL
OR [POPULATION] = ''
)
OR (
@OverwritePopulation = 1
AND (
[POPULATION] <> @Population
OR [POPULATION] IS NULL
)
)
)

--Update ADMIT fields if needed
Expand All @@ -349,7 +362,7 @@ BEGIN
END
,ADMIT_SESSION = CASE @Admitted
WHEN 1
THEN @Term
THEN @Session
ELSE NULL
END
,ADMIT_DATE = CASE @Admitted
Expand Down Expand Up @@ -409,7 +422,7 @@ BEGIN
END
,MATRIC_SESSION = CASE @Matriculated
WHEN 1
THEN @Term
THEN @Session
ELSE NULL
END
,MATRIC_DATE = CASE @Matriculated
Expand All @@ -431,7 +444,7 @@ BEGIN
@Matriculated = 1
AND (
COALESCE(MATRIC, '') <> 'Y'
AND MATRIC_DATE <> @MatricDate
OR MATRIC_DATE <> @MatricDate
OR MATRIC_DATE IS NULL
OR MATRIC_YEAR <> @Year
OR MATRIC_YEAR IS NULL
Expand All @@ -453,27 +466,6 @@ BEGIN
)
)

--AND (
-- (
-- CASE MATRIC
-- WHEN 'Y'
-- THEN 1
-- WHEN 'N'
-- THEN 0
-- ELSE NULL
-- END <> @Matriculated
-- )
-- OR (
-- (
-- MATRIC_YEAR <> @Year
-- AND MATRIC_TERM <> @Term
-- AND MATRIC_SESSION <> @Session
-- AND MATRIC_DATE <> @MatricDate
-- )
-- AND @Matriculated = 1
-- )
-- )
--AND @Matriculated IS NOT NULL
--Update COUNSELOR if needed
UPDATE ACADEMIC
SET COUNSELOR = @Counselor
Expand Down
85 changes: 62 additions & 23 deletions Tools/Mapper Generate AcademicProgram XML.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,24 @@ USE PowerCampusMapper
-- If you pass values from Slate in PDC format, like DEGREE/CURRICULUM or similar, you can automatically generate
-- the XML for recruiterMapping.xml without having to use the GUI tool.
--
-- === List of Output Sections
-- 1. Programs likely missing from Datatel_academicprogramExtensionBase. See Control Switch.
-- 2. XML to paste into AcademicProgram section of recruiterMapping.xml
-- 3. Programs for which XML couldn't be generated. Likely exists in Datatel_academicprogramExtensionBase but not ProgramOfStudy.
--
-- === Control Switch
-- Should this script automatically insert new items from ProgramOfStudy into Datatel_academicprogramExtensionBase?
-- Default is 0 (off).
DECLARE @PopulateDatatel_academicprogramExtensionBase BIT = 0

SELECT distinct --CP.LONG_DESC [CP.LONG_DESC]
SELECT DISTINCT --CP.LONG_DESC [CP.LONG_DESC]
CD.LONG_DESC [CD.LONG_DESC]
,CC.LONG_DESC [CC.LONG_DESC]
--,CP.CODE_VALUE_KEY [CP.CODE_VALUE_KEY]
,CD.CODE_VALUE_KEY [CD.CODE_VALUE_KEY]
,CC.CODE_VALUE_KEY [CC.CODE_VALUE_KEY]
,CC.LONG_DESC [CC.LONG_DESC] --Can be used to populate Datatel_academicprogramExtensionBase.Datatel_name
--,CP.CODE_VALUE_KEY [PROGRAM]
,CD.CODE_VALUE_KEY [DEGREE]
,CC.CODE_VALUE_KEY [CURRICULUM]
--,ProgramOfStudyId
,CD.CODE_VALUE_KEY + '/' + CC.CODE_VALUE_KEY [Datatel_abbreviation] --Can be used to populate Datatel_academicprogramExtensionBase.Datatel_abbreviation
INTO #POS
FROM Campus6.dbo.ProgramOfStudy POS
--LEFT JOIN Campus6.dbo.CODE_PROGRAM CP
Expand All @@ -20,56 +30,85 @@ LEFT JOIN Campus6.dbo.CODE_DEGREE CD
ON CD.DegreeId = POS.Degree
LEFT JOIN Campus6.dbo.CODE_CURRICULUM CC
ON CC.CurriculumId = POS.Curriculum
--WHERE CP.CODE_VALUE <> 'UNDER2'

--SELECT *
--FROM #POS
--Programs likely missing from Datatel_academicprogramExtensionBase
SELECT *
FROM #POS
WHERE Datatel_abbreviation NOT IN (
SELECT Datatel_abbreviation
FROM Datatel_academicprogramExtensionBase
)

IF @PopulateDatatel_academicprogramExtensionBase = 1
BEGIN
INSERT INTO [dbo].[Datatel_academicprogramExtensionBase] (
[Datatel_abbreviation]
,[Datatel_name]
)
SELECT POS.Datatel_abbreviation
,POS.[CC.LONG_DESC]
FROM #POS POS
WHERE Datatel_abbreviation NOT IN (
SELECT Datatel_abbreviation
FROM Datatel_academicprogramExtensionBase
)
END

SELECT *
,'<row RCCodeValue="' + Datatel_abbreviation + '" RCDesc="' + Datatel_name + '" PCDegreeCodeValue="' + (
SELECT [CD.CODE_VALUE_KEY]
SELECT [DEGREE]
FROM #POS
WHERE [CD.CODE_VALUE_KEY] = (
WHERE [DEGREE] = (
SELECT value
FROM string_split(Datatel_abbreviation, '/')
FROM string_split(D.Datatel_abbreviation, '/')
ORDER BY @@rowcount offset 0 rows FETCH NEXT 1 rows ONLY
)
AND [CC.CODE_VALUE_KEY] = (
AND [CURRICULUM] = (
SELECT value
FROM string_split(Datatel_abbreviation, '/')
FROM string_split(D.Datatel_abbreviation, '/')
ORDER BY @@rowcount offset 1 rows FETCH NEXT 1 rows ONLY
)
) + '" PCDegreeDesc="' + (
SELECT [CD.LONG_DESC]
FROM #POS
WHERE [CD.CODE_VALUE_KEY] = (
WHERE [DEGREE] = (
SELECT value
FROM string_split(Datatel_abbreviation, '/')
FROM string_split(D.Datatel_abbreviation, '/')
ORDER BY @@rowcount offset 0 rows FETCH NEXT 1 rows ONLY
)
AND [CC.CODE_VALUE_KEY] = (
AND [CURRICULUM] = (
SELECT value
FROM string_split(Datatel_abbreviation, '/')
FROM string_split(D.Datatel_abbreviation, '/')
ORDER BY @@rowcount offset 1 rows FETCH NEXT 1 rows ONLY
)
) + '" PCCurriculumCodeValue="' + (
SELECT value
FROM string_split(Datatel_abbreviation, '/')
FROM string_split(D.Datatel_abbreviation, '/')
ORDER BY @@rowcount offset 1 rows FETCH NEXT 1 rows ONLY
) + '" PCCurriculumDesc="' + (
SELECT [CC.LONG_DESC]
FROM #POS
WHERE [CD.CODE_VALUE_KEY] = (
WHERE [DEGREE] = (
SELECT value
FROM string_split(Datatel_abbreviation, '/')
FROM string_split(D.Datatel_abbreviation, '/')
ORDER BY @@rowcount offset 0 rows FETCH NEXT 1 rows ONLY
)
AND [CC.CODE_VALUE_KEY] = (
AND [CURRICULUM] = (
SELECT value
FROM string_split(Datatel_abbreviation, '/')
FROM string_split(D.Datatel_abbreviation, '/')
ORDER BY @@rowcount offset 1 rows FETCH NEXT 1 rows ONLY
)
) + '" />' [xml]
FROM Datatel_academicprogramExtensionBase
INTO #XML
FROM Datatel_academicprogramExtensionBase D

SELECT [xml]
FROM #XML
WHERE [xml] IS NOT NULL

SELECT *
FROM #XML
WHERE [xml] IS NULL

DROP TABLE #POS
,#XML
153 changes: 153 additions & 0 deletions generate fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import pprint
# This was a quick script used to refactor a bunch of separate lists into one big dict.
# Delete after everything is running smoothly.

def merge(current, new):
'''Union nested dicts one level deep.'''
for k, v in new.items():
if k in current:
current[k] = current[k] | new[k]
else:
current[k] = new[k]
return current


fields_null = ['Prefix',
'MiddleName',
'LastNamePrefix',
'Suffix',
'Nickname',
'GovernmentId',
'LegalName',
'Visa',
'CitizenshipStatus',
'PrimaryCitizenship',
'SecondaryCitizenship',
'DemographicsEthnicity',
'MaritalStatus',
'ProposedDecision',
'AppStatus', 'AppStatusDate',
'AppDecision',
'AppDecisionDate',
'Religion',
'FormerLastName',
'FormerFirstName',
'PrimaryLanguage',
'CountryOfBirth',
'Disabilities',
'CollegeAttendStatus',
'Commitment',
'Status',
'Veteran',
'Counselor',
'Department',
'Nontraditional',
'Population',
'Matriculated',
'AdmitDate',
'Extracurricular']

fields_bool = ['RaceAmericanIndian',
'RaceAsian',
'RaceAfricanAmerican',
'RaceNativeHawaiian',
'RaceWhite',
'IsInterestedInCampusHousing',
'IsInterestedInFinancialAid',
'Matriculated',
'Extracurricular']
fields_int = ['Ethnicity',
'Gender',
'SMSOptIn']

fields_api_verbatim = ['FirstName',
'LastName',
'Email',
'Campus',
'BirthDate',
'CreateDateTime',
'Prefix',
'MiddleName',
'LastNamePrefix',
'Suffix',
'Nickname',
'GovernmentId',
'LegalName',
'Visa',
'CitizenshipStatus',
'PrimaryCitizenship',
'SecondaryCitizenship',
'MaritalStatus',
'ProposedDecision',
'Religion',
'FormerLastName',
'FormerFirstName',
'PrimaryLanguage',
'CountryOfBirth',
'Disabilities',
'CollegeAttendStatus',
'Commitment', 'Status',
'RaceAmericanIndian',
'RaceAsian',
'RaceAfricanAmerican',
'RaceNativeHawaiian',
'RaceWhite',
'IsInterestedInCampusHousing',
'IsInterestedInFinancialAid',
'PrimaryLanguage',
'Ethnicity',
'Gender',
'YearTerm']
fields_sql_verbatim = ['aid',
'PEOPLE_CODE_ID',
'GovernmentId',
'RaceAmericanIndian',
'RaceAsian',
'RaceAfricanAmerican',
'RaceNativeHawaiian',
'RaceWhite',
'IsInterestedInCampusHousing',
'IsInterestedInFinancialAid',
'RaceWhite',
'Ethnicity',
'DemographicsEthnicity',
'AdmitDate',
'AppStatus',
'AppStatusDate',
'AppDecision',
'AppDecisionDate',
'Counselor',
'CreateDateTime',
'SMSOptIn',
'Department',
'Extracurricular',
'Nontraditional',
'Population',
'Matriculated']

fields = {k: {"supply": True} for k in fields_null}

new = {k: {"type": bool} for k in fields_bool}
fields = merge(fields, new)

new = {k: {"type": int} for k in fields_int}
fields = merge(fields, new)

new = {k: {"api_verbatim": True} for k in fields_api_verbatim}
fields = merge(fields, new)

new = {k: {"sql_verbatim": True} for k in fields_sql_verbatim}
fields = merge(fields, new)

for f in fields:
if 'supply' not in fields[f]:
fields[f]['supply'] = False
if 'type' not in fields[f]:
fields[f]['type'] = str
if 'api_verbatim' not in fields[f]:
fields[f]['api_verbatim'] = False
if 'sql_verbatim' not in fields[f]:
fields[f]['sql_verbatim'] = False

pp = pprint.PrettyPrinter(indent=4)
pp.pprint(fields)
Loading

0 comments on commit 6cb4ef1

Please sign in to comment.