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 facilitator and workshop rollups #29518

Merged
merged 9 commits into from Jul 26, 2019
Merged

Add facilitator and workshop rollups #29518

merged 9 commits into from Jul 26, 2019

Conversation

hacodeorg
Copy link
Contributor

@hacodeorg hacodeorg commented Jul 4, 2019

3rd PR in a series to support workshop surveys rollup. (PLC-330, 1st PR, 2nd PR)

This is not the final PR, it just gets the core functionality in under an experiment flag. There are still quite a few things to iron out.

What added

  • Facilitator effectiveness average for this workshop.

  • Facilitator effectiveness average across all workshops they facilitated for the same course.

  • Overall success and Teacher engagement averages for this workshop.

  • Overall success and Teacher engagement averages across workshops facilitated by same facilitator for the same course.

  • User permissions: Workshop admin, program manager, workshop organizer can see all results of facilitators in this workshop. Facilitator can only see their own results.

  • UI change: The only difference is in the Total responses row. It shows number of responses for Facilitator surveys and Workshop surveys (they are not the same). Previously it was just 1 number without explaining what that number means.

Screen Shot 2019-07-04 at 11 56 45 AM

How tested

  • Unit test: bundle exec rails test test/controllers/api/v1/pd/workshop_survey_report_controller_test.rb
  • Manual integration test with and without the experiment flag
    • Experiment: http://localhost-studio.code.org:3000/pd/workshop_dashboard/daily_survey_results/6482?enableExperiments=rollupSurveyReport
    • No experiment: http://localhost-studio.code.org:3000/pd/workshop_dashboard/daily_survey_results/6482?disableExperiments=rollupSurveyReport

How to try in production

  • To enable experiment

    • Add ?enableExperiments=rollupSurveyReport at the end of a query string. You only have to do this once (the setting is saved to browser local storage). E.g. https://studio.code.org/pd/workshop_dashboard/daily_survey_results/6482?enableExperiments=rollupSurveyReport
    • In workshop dashboard, click on "View Survey Results" for CSF deep or Local summer workshops will use the experiment view and API.
  • To disable experiment

    • Add ?disableExperiments=rollupSurveyReport at the end of a query string. Only have to do this once.
  • To compare current view and experiment view

    • The experiment setting doesn't affect browser in private/incognito mode and doesn't effect other browsers. Thus, you can open 2 browsers or same browser in different modes to compare the current vs. experiment views.

To do in the next PR

  • Add automated testing in production. Now that the experiment is live in production, we can start hitting it with queries just like in real user scenario to exercise the code with real data.
  • Fix critical bug: some questions are missing in pre/post/daily tabs. I suspect those questions have different answer types than I thought here.
  • Update tab names to say Day 1-5. Right now it just show form ids in tab names.
  • Split average scores into 2 tabs, 1 for facilitator-specific scores, 1 for general workshop scores.
  • Clean up duplicate code. Convert functions to pure functions (function that doesn't change states).
  • Add unit tests for survey_pipeline_helper.rb & survey_rollup_decorator.rb.

@hacodeorg hacodeorg marked this pull request as ready for review July 4, 2019 19:38
@agealy
Copy link

agealy commented Jul 8, 2019

A note that we are planning to deprecate the workshop_organizer permission (https://codedotorg.atlassian.net/browse/PLC-256), which is mentioned here. It doesn't look anything will break once we remove it, so I wouldn't advocate for any changes.

Copy link

@agealy agealy left a comment

Choose a reason for hiding this comment

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

I like the experiment flag approach! Looks like there's still much to fix, but so long as we're gating this behind the flag, I don't see an issue

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

Looks very good, especially as a incremental step while we're behind the experiment. I'd like to address the raw SQL query before merge.

--

A thought on your listed next steps:

Add automated testing in production.

I'd like to discuss this idea before we move forward with it. I think we should do some manual testing in production using the experiment, spot-checking real scenarios, but I'd like to keep automated testing in our test environment, because:

  • Tests against production, by definition, can't catch problems before they reach production.
  • Tests against production data may either be brittle (looking for specific values that are likely to change) or too general (unable to make assertions about correctness of displayed data).
  • Isolation: We don't want our automated tests to cause undue load on our frontends. We don't want to risk tests accidentally writing to the production database. We don't want to risk exposing private production information in test output. We don't want our automated tests to affect any usage metrics on production.
  • Maintenance: We don't currently have a test suite that runs against production, and introducing one would add one more system we have to maintain as a team.

next unless reducer_result.present?

summaries << group_key.merge({reducer: reducer.name, reducer_result: reducer_result})
rescue => e
errors << e.message
Copy link
Contributor

Choose a reason for hiding this comment

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

Not blocking on this PR, but I'm interested in a discussion about how specific we can usefully get with this (and similar) rescue blocks. I know we want to be resilient against failures, but I wonder if we can define useful boundaries of that resilience that will help us notice very unexpected scenarios faster.

Related: Rescue StandardError, Not Exception - ThoughtBot (especially the "Best-case Scenario" example)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My train of thought when dealing with errors (StandardError) is

  1. What code is more likely to produce errors? (Any code could potentially fail, but some has higher risk than the other.)
  2. What errors are expected (everything else is unexpected)?
  3. What errors are fatal at what layers? (An error could be fatal and halt execution of a callee function but at the same time is non-fatal to the caller.)
  4. What to do when catch an expected/unexpected fatal/non-fatal error? A few options are
    a) Interrupt the current code flow, throw error up 1 layer and let the upper layer deal with it.
    b) Swallow the error and continue with the current code flow.
    c) Swallow the error but report it via Honeybadger (externally) or record it and bubble the info up to upper layers.

In this particular case, the rescued block executes one reducer function on one group of data, which is a part of applying multiple reducers to multiple groups. I chose option (c) here, swallow all errors, record and bubble them up. This is best-effort approach, getting usable results but still notify higher layers about caught errors.

ws_facilitated_query =
"SELECT DISTINCT pd_workshop_id FROM pd_workshops_facilitators "\
"WHERE user_id = #{fac_id}"
ws_facilitated = ActiveRecord::Base.connection.exec_query(ws_facilitated_query).rows.flatten
Copy link
Contributor

Choose a reason for hiding this comment

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

Although fac_id should only come from our own database, I'd like to be paranoid and pass it as a bind instead of inlining it into the query statement here.

Also, is it possible that Pd::Workshop.managed_by already does what you want, taking a few more edge cases into account?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see the vulnerability here. I have 2 options to fix it

  1. Sanitize fac_id using quote as suggested here

  2. Doing something similar to Pd::Workshop.managed_by

  def find_related_workshops(fac_id, course)
    Pd::Workshop.left_outer_joins(:facilitators).
      where(users: {id: fac_id}, course: course).
      distinct.
      pluck(:id)
  end

This looks cleaner but one thing bothers me is it actually joins 3 tables instead of 2, pd_workshops, pd_workshop_facilitators and users. The last join with users is only to use users.id instead of pd_workshop_facilitators.user_id in filter.

The behind-the-scene SQL command is

SELECT DISTINCT `pd_workshops`.`id` FROM `pd_workshops` LEFT OUTER JOIN `pd_workshops_facilitators` ON `pd_workshops_facilitators`.`pd_workshop_id` = `pd_workshops`.`id` LEFT OUTER JOIN `users` ON `users`.`id` = `pd_workshops_facilitators`.`user_id` AND `users`.`deleted_at` IS NULL WHERE `pd_workshops`.`deleted_at` IS NULL AND `users`.`id` = 124 AND `pd_workshops`.`course` = 'CS Fundamentals'

I can go with option 2 to make the code more succinct, but I'm still interested in learning about better options.

Copy link
Contributor

Choose a reason for hiding this comment

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

1 is fine with me - I just want to make sure we're sanitizing our parameters.

@clareconstantine
Copy link

Having spent a lot of time trying to figure out how the old pipeline did a lot of this, your comments are super helpful!!!

@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (staging@a598b21). Click here to learn what that means.
The diff coverage is 29.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##             staging   #29518   +/-   ##
==========================================
  Coverage           ?   73.15%           
==========================================
  Files              ?     2052           
  Lines              ?   112316           
  Branches           ?     3397           
==========================================
  Hits               ?    82162           
  Misses             ?    26921           
  Partials           ?     3233
Flag Coverage Δ
#integration 55.04% <ø> (?)
#storybook 56.62% <ø> (?)
#unit 58.01% <ø> (?)
Impacted Files Coverage Δ
...ents/survey_results/facilitator_averages_table.jsx 74.5% <ø> (ø)
...d/lib/pd/survey_pipeline/daily_survey_decorator.rb 100% <100%> (ø)
...oard/lib/pd/survey_pipeline/daily_survey_parser.rb 100% <100%> (ø)
...ers/api/v1/pd/workshop_survey_report_controller.rb 92.2% <100%> (ø)
.../lib/pd/survey_pipeline/survey_rollup_decorator.rb 17.18% <17.18%> (ø)
...d/lib/pd/survey_pipeline/survey_pipeline_helper.rb 44.59% <26.78%> (ø)
dashboard/lib/pd/survey_pipeline/mapper.rb 96.96% <83.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a598b21...0cc77cc. Read the comment docs.

1 similar comment
@codecov-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (staging@a598b21). Click here to learn what that means.
The diff coverage is 29.62%.

Impacted file tree graph

@@            Coverage Diff             @@
##             staging   #29518   +/-   ##
==========================================
  Coverage           ?   73.15%           
==========================================
  Files              ?     2052           
  Lines              ?   112316           
  Branches           ?     3397           
==========================================
  Hits               ?    82162           
  Misses             ?    26921           
  Partials           ?     3233
Flag Coverage Δ
#integration 55.04% <ø> (?)
#storybook 56.62% <ø> (?)
#unit 58.01% <ø> (?)
Impacted Files Coverage Δ
...ents/survey_results/facilitator_averages_table.jsx 74.5% <ø> (ø)
...d/lib/pd/survey_pipeline/daily_survey_decorator.rb 100% <100%> (ø)
...oard/lib/pd/survey_pipeline/daily_survey_parser.rb 100% <100%> (ø)
...ers/api/v1/pd/workshop_survey_report_controller.rb 92.2% <100%> (ø)
.../lib/pd/survey_pipeline/survey_rollup_decorator.rb 17.18% <17.18%> (ø)
...d/lib/pd/survey_pipeline/survey_pipeline_helper.rb 44.59% <26.78%> (ø)
dashboard/lib/pd/survey_pipeline/mapper.rb 96.96% <83.33%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a598b21...0cc77cc. Read the comment docs.

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

This looks great! Let's do it.

@hacodeorg hacodeorg merged commit 6b6b6d0 into staging Jul 26, 2019
@hacodeorg hacodeorg deleted the ha/sp-rollup-3 branch September 23, 2019 21:32
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.

None yet

5 participants