DASSL / Gradebook

Open-source product to provide a practical means for instructors to record student attendance and assessment
Other
8 stars 4 forks source link

Added getAttendance.sql to Gradebook repo #35

Closed bella004 closed 7 years ago

bella004 commented 7 years ago

The getAttendance function is now more modular only needing sectionID The getSectionID function returns the sectionID that getAttendance needs

Note: Make sure all imports are made before running

smurthys commented 7 years ago

A few observations;

bella004 commented 7 years ago

This raises some questions:

smurthys commented 7 years ago
bella004 commented 7 years ago

I just ran the file and it produced an error: column "st.lname" must appear in the GROUP BY clause or be used in an aggregate function. This is because I'm using st.lname, st.fname, and st.mname in the SELECT, so would it be preferred if I remove those from the SELECT, or put them back in the GROUP BY and remove the sdar.i from the GROUP BY, because I know I'm not using that in the SELECT.

smurthys commented 7 years ago

It is possible I am not seeing something that is really obvious (thus my use of the phrase "I feel" originally). Let me know what I am missing.

Anyway, I wrote the following script to test what I understand the scenario is. (I had to create my own tables because I don't have a functioning Gradebook DB right now).

The SELECT query here groups by S.ID but outputs S.FName and S.LName. This is possible because the name columns are used in expression involving the aggregate function string_agg.

CREATE TEMP TABLE IF NOT EXISTS S (ID INTEGER PRIMARY KEY, FName VARCHAR, LName VARCHAR);
CREATE TEMP TABLE IF NOT EXISTS A (SID INTEGER REFERENCES S, Status VARCHAR);

TRUNCATE S CASCADE;
INSERT INTO S VALUES(1, 'Joe', 'Baker');
INSERT INTO S VALUES(2, 'Mary', 'Anne');

INSERT INTO A VALUES(1, 'A');
INSERT INTO A VALUES(1, 'P');
INSERT INTO A VALUES(1, 'X');
INSERT INTO A VALUES(2, 'P');
INSERT INTO A VALUES(2, 'E');
INSERT INTO A VALUES(2, 'P');

SELECT S.LName || ',' || S.FName || ',' || string_agg(Status, ',') AS csv
FROM S JOIN A ON S.ID=A.SID
GROUP BY S.ID;

This script produces the following result:

csv
"Baker,Joe,A,P,X"
"Anne,Mary,P,E,P"
smurthys commented 7 years ago

I am sure other reviewers will have thoughts as well on my comments and this PR in general.

bella004 commented 7 years ago

It should now work. Apparently, it was okay to use only st.id in the GROUP BY, but not sdar.i

afig commented 7 years ago

The changes made so far look good.

One small issue that was mentioned by @smurthys has not been addressed:

Add product name after file name in the prologue comment: see ClassDB source files for example

Solution: Add - Gradebook on line 1 after the file name. This makes it consistent with the prologue of other files. As a side note, some files have capitalized Gradebook as GradeBook. However, we are using the first capitalization (lowercase 'b').

Apart from that, I noticed a couple of potential minor changes that should be considered:

Thanks for your help with this task.

wildtayne commented 7 years ago

(Updated to take Andrew's comment into consideration) Hi Kyle, I did some testing on getAttendance.sql while updating the web server, and I have a few observations:

With these couple tweaks, these functions should be go to go as far as the server is concerned.

bella004 commented 7 years ago

"On line 71 , sub queries (i.e. SELECT x FROM y) are used to pick a value to call datesFromSchedule with. Is it necessary to do so? For instance, does using curSec.sd instead of SELECT sd FROM curSec cause an error? Avoiding the use of sub queries here will make it easier to interpret this line. If we do this, then we will also have to add curSec to the FROM clause."

I would do that if I didn't have to JOIN curSec to the FROM clause, since I would:

  1. Need a JOIN condition to JOIN curSec on, which I don't think there is, or
  2. Need to justify a second cross join, which I don't know if I can do properly
bella004 commented 7 years ago

Scratch that, I found a way to justify the second cross join if it's in a separate WITH clause.

smurthys commented 7 years ago

This script is shaping up really well, thanks to @bella004's persistence and the reviewers' diligence.

In addition to the earlier review comments, I propose the following changes:

smurthys commented 7 years ago

On renaming the result column csvwheadattnrec to AttendanceCsvWithHeader: I don't know for sure, but it is possible this renaming conflicts with JSON naming (conventions) in the web server. However, almost any DB team is virtually guaranteed to disregard coding conventions of teams that use the DBMS. (They will of course reconsider names if they conflict with a protocol or other operational aspects.)