Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/db/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,5 @@ verification step is considered successful if it completes without any error.
imported:

```sql
SELECT * FROM Gradebook.getAttendance(2017, 'Spring', 'CS110', '5');
SELECT * FROM getAttendance(2017, 'Spring', 'CS110', '5');
```
28 changes: 14 additions & 14 deletions src/db/addAttendanceMgmt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ SET LOCAL client_min_messages TO WARNING;

--Drop function from M1 that has since been renamed or removed
-- remove the DROP statement after M2
DROP FUNCTION IF EXISTS Gradebook.datesFromSchedule(DATE, DATE, VARCHAR(7));
DROP FUNCTION IF EXISTS datesFromSchedule(DATE, DATE, VARCHAR(7));


--Function to generate a list of dates for a class schedule, within a date range
Expand All @@ -38,11 +38,11 @@ DROP FUNCTION IF EXISTS Gradebook.datesFromSchedule(DATE, DATE, VARCHAR(7));
--S = Saturday

--Example usage: get dates of Tuesdays and Thursdays b/w 2017-01-01 and 2017-05-01:
-- SELECT * FROM Gradebook.getScheduleDates('2017-01-01', '2017-05-01', 'TR');
-- SELECT * FROM getScheduleDates('2017-01-01', '2017-05-01', 'TR');

DROP FUNCTION IF EXISTS Gradebook.getScheduleDates(DATE, DATE, VARCHAR(7));
DROP FUNCTION IF EXISTS getScheduleDates(DATE, DATE, VARCHAR(7));

CREATE FUNCTION Gradebook.getScheduleDates(startDate DATE, endDate DATE,
CREATE FUNCTION getScheduleDates(startDate DATE, endDate DATE,
schedule VARCHAR(7)
)
RETURNS TABLE (ScheduleDate DATE)
Expand Down Expand Up @@ -76,9 +76,9 @@ $$ LANGUAGE sql


--Function to get attendance for a section ID
DROP FUNCTION IF EXISTS Gradebook.getAttendance(INT);
DROP FUNCTION IF EXISTS getAttendance(INT);

CREATE FUNCTION Gradebook.getAttendance(sectionID INT)
CREATE FUNCTION getAttendance(sectionID INT)
RETURNS TABLE(AttendanceCsvWithHeader TEXT) AS
$$

Expand All @@ -87,15 +87,15 @@ $$
SectionDate AS
(
SELECT ScheduleDate
FROM Gradebook.Section,
Gradebook.getScheduleDates(StartDate, EndDate, Schedule)
FROM Section,
getScheduleDates(StartDate, EndDate, Schedule)
WHERE ID = $1
),
--combine every student enrolled in section w/ each meeting date of section
Enrollee_Date AS
(
SELECT Student, ScheduleDate
FROM Gradebook.Enrollee, SectionDate
FROM Enrollee, SectionDate
WHERE Section = $1
),
--get the recorded attendance for each enrollee, marking as "Present" if
Expand All @@ -104,7 +104,7 @@ $$
(
SELECT ed.Student, ScheduleDate, COALESCE(ar.Status, 'P') c
FROM Enrollee_Date ed
LEFT OUTER JOIN Gradebook.AttendanceRecord ar
LEFT OUTER JOIN AttendanceRecord ar
ON ed.Student = ar.Student
AND ed.ScheduleDate = ar.Date
AND ar.Section = $1 --can't move test on section to WHERE clause
Expand All @@ -124,7 +124,7 @@ $$
SELECT concat_ws(',', st.LName, st.FName, COALESCE(st.MName, ''),
string_agg(c, ',' ORDER BY ScheduleDate)
)
FROM sdar JOIN Gradebook.Student st ON sdar.Student = st.ID
FROM sdar JOIN Student st ON sdar.Student = st.ID
GROUP BY st.ID
ORDER BY st.LName, st.FName, COALESCE(st.MName, '')
);
Expand All @@ -133,16 +133,16 @@ $$ LANGUAGE sql;


--Function to get attendance for a year-season-course-section# combo
DROP FUNCTION IF EXISTS Gradebook.getAttendance(NUMERIC(4,0), VARCHAR(20),
DROP FUNCTION IF EXISTS getAttendance(NUMERIC(4,0), VARCHAR(20),
VARCHAR(8), VARCHAR(3)
);

CREATE FUNCTION Gradebook.getAttendance(year NUMERIC(4,0),
CREATE FUNCTION getAttendance(year NUMERIC(4,0),
seasonIdentification VARCHAR(20),
course VARCHAR(8),
sectionNumber VARCHAR(3)
)
RETURNS TABLE(AttendanceCsvWithHeader TEXT) AS
$$
SELECT Gradebook.getAttendance(Gradebook.getSectionID($1, $2, $3, $4));
SELECT getAttendance(getSectionID($1, $2, $3, $4));
$$ LANGUAGE sql;
58 changes: 29 additions & 29 deletions src/db/addInstructorMgmt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@


--Function to get details of all known instructors
DROP FUNCTION IF EXISTS Gradebook.getInstructors();
DROP FUNCTION IF EXISTS getInstructors();

CREATE FUNCTION Gradebook.getInstructors()
CREATE FUNCTION getInstructors()
RETURNS TABLE
(
ID INT,
Expand All @@ -34,7 +34,7 @@ AS
$$

SELECT ID, FName, MName, LName, Department, Email
FROM Gradebook.Instructor;
FROM Instructor;

$$ LANGUAGE sql
STABLE; --no need for RETURN NULL ON... because the function takes no input
Expand All @@ -43,9 +43,9 @@ $$ LANGUAGE sql
--function to get details of the instructor with the given e-mail address
-- performs a case-insensitive match of email address;
-- returns 0 or 1 row: Instructor.Email is unique;
DROP FUNCTION IF EXISTS Gradebook.getInstructor(Gradebook.Instructor.Email%TYPE);
DROP FUNCTION IF EXISTS getInstructor(Gradebook.Instructor.Email%TYPE);

CREATE FUNCTION Gradebook.getInstructor(Email Gradebook.Instructor.Email%TYPE)
CREATE FUNCTION getInstructor(Email Instructor.Email%TYPE)
RETURNS TABLE
(
ID INT,
Expand All @@ -58,7 +58,7 @@ AS
$$

SELECT ID, FName, MName, LName, Department
FROM Gradebook.Instructor
FROM Instructor
WHERE LOWER(TRIM(Email)) = LOWER(TRIM($1));

$$ LANGUAGE sql
Expand All @@ -68,9 +68,9 @@ $$ LANGUAGE sql


--function to get details of the instructor with the given ID
DROP FUNCTION IF EXISTS Gradebook.getInstructor(INT);
DROP FUNCTION IF EXISTS getInstructor(INT);

CREATE FUNCTION Gradebook.getInstructor(instructorID INT)
CREATE FUNCTION getInstructor(instructorID INT)
RETURNS TABLE
(
FName VARCHAR(50),
Expand All @@ -83,7 +83,7 @@ AS
$$

SELECT FName, MName, LName, Department, Email
FROM Gradebook.Instructor
FROM Instructor
WHERE ID = $1;

$$ LANGUAGE sql
Expand All @@ -94,24 +94,24 @@ $$ LANGUAGE sql

--drop functions with older names due to names being revised
-- remove this block of code after milestone M1
DROP FUNCTION IF EXISTS Gradebook.getYears(INT);
DROP FUNCTION IF EXISTS Gradebook.getSeasons(INT, NUMERIC(4,0));
DROP FUNCTION IF EXISTS Gradebook.getCourses(INT, NUMERIC(4,0), NUMERIC(1,0));
DROP FUNCTION IF EXISTS Gradebook.getSections(INT, NUMERIC(4,0),
DROP FUNCTION IF EXISTS getYears(INT);
DROP FUNCTION IF EXISTS getSeasons(INT, NUMERIC(4,0));
DROP FUNCTION IF EXISTS getCourses(INT, NUMERIC(4,0), NUMERIC(1,0));
DROP FUNCTION IF EXISTS getSections(INT, NUMERIC(4,0),
NUMERIC(1,0), VARCHAR(8)
);


--function to get the years in which an instructor has taught
DROP FUNCTION IF EXISTS Gradebook.getInstructorYears(INT);
DROP FUNCTION IF EXISTS getInstructorYears(INT);

CREATE FUNCTION Gradebook.getInstructorYears(instructorID INT)
CREATE FUNCTION getInstructorYears(instructorID INT)
RETURNS TABLE(Year NUMERIC(4,0))
AS
$$

SELECT DISTINCT Year
FROM Gradebook.Term T JOIN Gradebook.Section N ON T.ID = N.Term
FROM Term T JOIN Section N ON T.ID = N.Term
WHERE $1 IN (N.Instructor1, N.Instructor2, N.Instructor3)
ORDER BY Year DESC;

Expand All @@ -121,18 +121,18 @@ $$ LANGUAGE sql


--function to get all seasons an instructor has taught in a specfied year
DROP FUNCTION IF EXISTS Gradebook.getInstructorSeasons(INT, NUMERIC(4,0));
DROP FUNCTION IF EXISTS getInstructorSeasons(INT, NUMERIC(4,0));

CREATE FUNCTION Gradebook.getInstructorSeasons(instructorID INT,
CREATE FUNCTION getInstructorSeasons(instructorID INT,
year NUMERIC(4,0)
)
RETURNS TABLE(SeasonOrder NUMERIC(1,0), SeasonName VARCHAR(20))
AS
$$

SELECT DISTINCT S."Order", S.Name
FROM Gradebook.Season S JOIN Gradebook.Term T ON S."Order" = T.Season
JOIN Gradebook.Section N ON N.Term = T.ID
FROM Season S JOIN Term T ON S."Order" = T.Season
JOIN Section N ON N.Term = T.ID
WHERE $1 IN (N.Instructor1, N.Instructor2, N.Instructor3)
AND T.Year = $2
ORDER BY S."Order";
Expand All @@ -143,11 +143,11 @@ $$ LANGUAGE sql


--function to get all courses an instructor has taught in a year-season combo
DROP FUNCTION IF EXISTS Gradebook.getInstructorCourses(INT, NUMERIC(4,0),
DROP FUNCTION IF EXISTS getInstructorCourses(INT, NUMERIC(4,0),
NUMERIC(1,0)
);

CREATE FUNCTION Gradebook.getInstructorCourses(instructorID INT,
CREATE FUNCTION getInstructorCourses(instructorID INT,
year NUMERIC(4,0),
seasonOrder NUMERIC(1,0)
)
Expand All @@ -156,7 +156,7 @@ AS
$$

SELECT DISTINCT N.Course
FROM Gradebook.Section N JOIN Gradebook.Term T ON N.Term = T.ID
FROM Section N JOIN Term T ON N.Term = T.ID
WHERE $1 IN (N.Instructor1, N.Instructor2, N.Instructor3)
AND T.Year = $2
AND T.Season = $3
Expand All @@ -173,11 +173,11 @@ $$ LANGUAGE sql
-- a string of the form "course-sectionNumber";
--this function is useful in showing Course-Section combinations directly
--without having to first explicitly choose a course to get sections
DROP FUNCTION IF EXISTS Gradebook.getInstructorSections(INT, NUMERIC(4,0),
DROP FUNCTION IF EXISTS getInstructorSections(INT, NUMERIC(4,0),
NUMERIC(1,0)
);

CREATE FUNCTION Gradebook.getInstructorSections(instructorID INT,
CREATE FUNCTION getInstructorSections(instructorID INT,
year NUMERIC(4,0),
seasonOrder NUMERIC(1,0)
)
Expand All @@ -191,7 +191,7 @@ $$

SELECT N.ID, N.Course, N.SectionNumber,
N.Course || '-' || N.SectionNumber AS CourseSection
FROM Gradebook.Section N JOIN Gradebook.Term T ON N.Term = T.ID
FROM Section N JOIN Term T ON N.Term = T.ID
WHERE $1 IN (N.Instructor1, N.Instructor2, N.Instructor3)
AND T.Year = $2
AND T.Season = $3
Expand All @@ -203,11 +203,11 @@ $$ LANGUAGE sql

--function to get the section number(s) of a course an instructor has taught
-- performs case-insensitive match for course
DROP FUNCTION IF EXISTS Gradebook.getInstructorSections(INT, NUMERIC(4,0),
DROP FUNCTION IF EXISTS getInstructorSections(INT, NUMERIC(4,0),
NUMERIC(1,0), VARCHAR(8)
);

CREATE FUNCTION Gradebook.getInstructorSections(instructorID INT,
CREATE FUNCTION getInstructorSections(instructorID INT,
year NUMERIC(4,0),
seasonOrder NUMERIC(1,0),
courseNumber VARCHAR(8)
Expand All @@ -217,7 +217,7 @@ AS
$$

SELECT SectionID, SectionNumber
FROM Gradebook.getInstructorSections($1, $2, $3)
FROM getInstructorSections($1, $2, $3)
WHERE LOWER(Course) = LOWER($4)
ORDER BY SectionNumber;

Expand Down
8 changes: 4 additions & 4 deletions src/db/addReferenceData.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-- in the calendar year; not in the school's academic year. For example, the
-- rows inserted here say that Spring is the first season classes are held in a
-- calendar year, followed by "Spring_Break" and so on
INSERT INTO Gradebook.Season("Order", Name, Code)
INSERT INTO Season("Order", Name, Code)
VALUES
('0','Spring','S'), ('1','Spring_Break','B'), ('2','Summer','M'),
('3','Fall','F'), ('4','Intersession','I');
Expand All @@ -33,8 +33,8 @@ VALUES

--populate the Grade table with values used at most US schools
-- each record establishes a correspondence between a letter grade and eqt. GPA;
-- see schema of Gradebook.Grade for values permitted in these columns
INSERT INTO Gradebook.Grade(Letter, GPA)
-- see schema of Grade for values permitted in these columns
INSERT INTO Grade(Letter, GPA)
VALUES
('A+', 4.333), ('A', 4), ('A-', 3.667), ('B+', 3.333), ('B', 3),
('B-', 2.667), ('C+', 2.333), ('C', 2), ('C-', 1.667), ('D+', 1.333),
Expand All @@ -45,7 +45,7 @@ VALUES
--add some well-known attendance statuses
-- each record creates a correspondence between an internal status code and a
-- description that is displayed to the user
INSERT INTO Gradebook.AttendanceStatus(Status, Description)
INSERT INTO AttendanceStatus(Status, Description)
VALUES
('P', 'Present'), ('A', 'Absent'), ('E', 'Explained'),
('S', 'Stopped Attending'), ('X', 'Excused'), ('N', 'Not Registered'),
Expand Down
18 changes: 9 additions & 9 deletions src/db/addSeasonMgmt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ SET LOCAL client_min_messages TO WARNING;
-- performs case-insensitive match of season name and code
-- this function makes it easier for users to indicate a season by any of the
-- three possible identifiers for seasons
DROP FUNCTION IF EXISTS Gradebook.getSeason(VARCHAR(20));
DROP FUNCTION IF EXISTS getSeason(VARCHAR(20));

CREATE FUNCTION Gradebook.getSeason(seasonIdentification VARCHAR(20))
CREATE FUNCTION getSeason(seasonIdentification VARCHAR(20))
RETURNS TABLE
(
"Order" NUMERIC(1,0),
Expand All @@ -35,7 +35,7 @@ AS
$$

SELECT "Order", Name, Code
FROM Gradebook.Season
FROM Season
WHERE CASE
WHEN $1 ~ '^[0-9]$' THEN "Order" = to_number($1,'9')
WHEN LENGTH($1) = 1 THEN Code = UPPER($1)
Expand All @@ -50,9 +50,9 @@ $$ LANGUAGE sql

--Function to get the details of the season matching a season order
-- this function exists to support clients that pass season order as a number
DROP FUNCTION IF EXISTS Gradebook.getSeason(NUMERIC(1,0));
DROP FUNCTION IF EXISTS getSeason(NUMERIC(1,0));

CREATE FUNCTION Gradebook.getSeason(seasonOrder NUMERIC(1,0))
CREATE FUNCTION getSeason(seasonOrder NUMERIC(1,0))
RETURNS TABLE
(
"Order" NUMERIC(1,0),
Expand All @@ -63,7 +63,7 @@ AS
$$

SELECT "Order", Name, Code
FROM Gradebook.Season
FROM Season
WHERE "Order" = $1;

$$ LANGUAGE sql
Expand All @@ -74,15 +74,15 @@ $$ LANGUAGE sql


--Function to get the "order" of the season matching a "season identification"
DROP FUNCTION IF EXISTS Gradebook.getSeasonOrder(VARCHAR(20));
DROP FUNCTION IF EXISTS getSeasonOrder(VARCHAR(20));

CREATE FUNCTION Gradebook.getSeasonOrder(seasonIdentification VARCHAR(20))
CREATE FUNCTION getSeasonOrder(seasonIdentification VARCHAR(20))
RETURNS NUMERIC(1,0)
AS
$$

SELECT "Order"
FROM Gradebook.getSeason($1);
FROM getSeason($1);

$$ LANGUAGE sql
STABLE
Expand Down
Loading