Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add download queue data button #290

Merged
merged 19 commits into from
Oct 14, 2019
Merged

Add download queue data button #290

merged 19 commits into from
Oct 14, 2019

Conversation

jackieo5023
Copy link
Collaborator

@jackieo5023 jackieo5023 commented Oct 5, 2019

This PR:

  • Adds a button and endpoint to download course queue data as a csv on the course page
    • This is only viewable to course staff, which I have tested
  • Changed a comment that was probably not changed after copy/paste to say "remove" instead of "add"

image

Here is an example of what the download would look like given fake data. Unfortunately, I couldn't upload to GitHub as a csv.
Here is the SQL query that this was based off of:

SELECT
  questions.id AS id,
  courses.name AS CourseName,
  queues.name AS QueueName,
  u_asked.netid AS AskedBy_netid, u_asked.universityName AS AskedBy_RealName,
  u_answered.netid AS AnsweredBy_netid, u_answered.universityName AS AnsweredBy_RealName,
  topic,
  CONVERT_TZ(enqueueTime, '+0:00', 'US/Central') AS enqueueTime,
  CONVERT_TZ(dequeueTime, '+0:00', 'US/Central') AS dequeueTime,
  CONVERT_TZ(answerStartTime, '+0:00', 'US/Central') AS answerStartTime,
  CONVERT_TZ(answerFinishTime, '+0:00', 'US/Central') AS answerFinishTime,
  comments, preparedness,
  questions.location AS UserLocation,
  queues.location AS QueueLocation,
  CONVERT_TZ(queues.createdAt, '+0:00', 'US/Central') AS Queue_CreatedAt,
  queueId, courseId
FROM questions
  INNER JOIN queues ON questions.queueId = queues.id
  INNER JOIN courses ON queues.courseId = courses.id
  INNER JOIN users u_asked ON questions.askedById = u_asked.id
  LEFT JOIN users u_answered ON questions.answeredById = u_answered.id
WHERE courseId=6
ORDER BY enqueueTime DESC

@vercel
Copy link

vercel bot commented Oct 5, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/illinois/queue/fmpfyvbdci
🌍 Preview: In Progress

@jackieo5023 jackieo5023 changed the title Download queue data Add download queue data button Oct 5, 2019
Copy link
Member

@nwalters512 nwalters512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! It'll be great to have these data exports be self-service instead of requiring manual queries from an admin. I left a few inline comments. A few broader questions:

  • Is there a reason the download is associated with the course as a whole and not with a specific queue? Now that queues are being used "persistently", I would imagine it would be most useful to have this data be per-queue. That's not to say an endpoint to get data for a course as a whole wouldn't be useful too!
  • To my point of potentially wanting more downloads in the future, it might be nice to design for that from the start and put downloads in a location other than the course header. Perhaps a separate "downloads" section at the bottom of the course page?

src/api/courses.js Outdated Show resolved Hide resolved
src/pages/course.js Outdated Show resolved Hide resolved
@james9909
Copy link
Member

Adding onto Nathan's comments, we should also add some tests for this new endpoint

src/api/courses.js Outdated Show resolved Hide resolved
attributes: {
include: [
['netid', 'AskedBy_netid'],
['universityName', 'AskedBy_RealName'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling something a "real" name has certain unwanted connotations. For instance, I have trans friends whose university name is not their real name; there are also students who use a different name day-to-day from what's in Enterprise. I think there are a couple potential changes here:

  • calling this UniversityName
  • the above, but also exporting the PreferredName field
  • doing what the UI/API already do: taking the preferred name if it's specified and falling back to the name provided by Shib if they aren't
  • omitting the name entirely

I think my personal preference would be the third option: it's most consistent with how names are treated everywhere else in the queue. There is the potential for abuse (I can set my preferred name to an arbitrary string), but the nedid can always be cross-referenced with a roster or the university directory if there are doubts about a user's identity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll play around with the options you listed here - maybe one of them can solve the weird issue mentioned above.

@jackieo5023
Copy link
Collaborator Author

@nwalters512 as for your point about downloads being in another section, I think at this point @wadefagen just wants downloads to be pushed out as quick as possible - so I guess think of this as a temporary solution, and later I can make it nicer to be able to download per queue as well.

@jackieo5023
Copy link
Collaborator Author

jackieo5023 commented Oct 10, 2019

Now ready for review again.

  • Sequelize is weird in that if you specifically include an attribute in a related model, it doesn't exclude other attributes. So in the getColumns function, I whitelist the fields we want to display.
  • Added tests for the endpoint.
  • RealName is changed to UniversityName
  • Moved all logic to api except for the download
  • Changed timezone calculation to be on the javascript side rather than sequelize, as sqlite and mysql don't have the same timezone conversion functions

Here is an updated version of an example csv.

@jackieo5023
Copy link
Collaborator Author

Tested on staging. Everything appears to be working properly and correctly (times are verified to be in CST as well).

@nwalters512
Copy link
Member

Going to give this a final look over!

src/api/courses.js Outdated Show resolved Hide resolved
src/api/courses.js Outdated Show resolved Hide resolved
src/pages/course.js Outdated Show resolved Hide resolved
.eslintrc.js Outdated Show resolved Hide resolved
const formattedTime =
time !== null
? moment
.tz(time, 'YYYY-MM-DD HH:mm:ss.SSS Z', 'US/Central')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought: this may be undesirable if/when we roll out to schools like UBC that aren't in the central timezone. When that happens, we should either a) report times in UTC and allow consumers of this data to transform it as needed, or b) associate some concept of timezone with either courses or institutions (one institutions are an entity that we have). I think I'd prefer the latter; at any rate, that's outside the scope of this PR.

Copy link
Member

@nwalters512 nwalters512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good! Merging is blocked on fixing the href on the download button; the other few comments are just questions.

src/api/courses.js Outdated Show resolved Hide resolved
src/pages/course.js Outdated Show resolved Hide resolved
src/api/courses.js Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to staging October 14, 2019 04:03 Inactive
@vercel vercel bot temporarily deployed to staging October 14, 2019 04:05 Inactive
Copy link
Member

@nwalters512 nwalters512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woot, looks great! 🚀

@james9909 james9909 merged commit 51ec9d1 into master Oct 14, 2019
@james9909 james9909 deleted the download-queue-data branch October 14, 2019 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants