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

Firebreak - Add reports to download live form data as CSV files #1681

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

stephencdaly
Copy link
Contributor

@stephencdaly stephencdaly commented Dec 23, 2024

What problem does this pull request solve?

Trello card: https://trello.com/c/mPtJhtWq/

Add 2 reports to get all data about live forms as a CSV, and to get all questions in all live forms as a CSV.

The intention of this is that it should make it easier to analyse data about forms and questions that exist on the platform without having to spend time to make dedicated reports. It should be quick and easy to add additional columns into these CSV reports as we add new features.

These reports call the forms-api "/api/v2/form-documents" endpoint added in alphagov/forms-api#663 to get the form document objects for all live forms. We get the form documents rather than the form model as the form document represents the state of the live form that is served to form fillers, whereas the form model might have changes that have been made to a draft version of the form.

The forms-api endpoint supports pagination. Use this to avoid sending all form documents in a single large API response - default to 100 results per request page.

To make requests to forms-api, use Net:HTTP rather than ActiveResource. I attempted to use ActiveResource at first but this required an additional gem and some additional hacking at to be able to consume the headers for pagination.

Screenshot 2025-01-03 at 12 23 38 Screenshot 2025-01-03 at 15 02 06

Example CSVs:

live_forms_report-2025-01-03 12_59_53 UTC.csv

live_questions_report-2025-01-03 13_03_47 UTC.csv

Relies on forms-api pull request: alphagov/forms-api#663

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Has all relevant documentation been updated?

@stephencdaly stephencdaly force-pushed the add-csv-download-reports branch 3 times, most recently from 5729c92 to 54dd2ee Compare December 24, 2024 11:50
@stephencdaly stephencdaly force-pushed the add-csv-download-reports branch 9 times, most recently from 689c5de to d15dc1d Compare January 3, 2025 13:26
@stephencdaly stephencdaly marked this pull request as ready for review January 3, 2025 13:35
@stephencdaly stephencdaly force-pushed the add-csv-download-reports branch 2 times, most recently from b5bb6c9 to 1b3e8ae Compare January 3, 2025 13:46
This report downloads a CSV file containing data about all live forms.

This calls the forms-api "/api/v2/form-documents" endpoint to get
the form document objects for all live forms. We get the form
documents rather than the form model as the form document represents
the state of the live form that is served to form fillers, whereas the
form model might have changes that have been made to a draft version
of the form.

The forms-api endpoint supports pagination. Use this to avoid sending
all form documents in a single large API response - default to 100
results per request page.

To make requests to forms-api, use Net:HTTP rather than
ActiveResource. I attempted to use ActiveResource at first but this
required an additional gem and some additional hacking at to be able
to consume the headers for pagination.

When we consume the data from forms-admin, add in details about the
organisation and group for the form and manipulate some of the data to
produce a useful CSV report.

For the tests, use a JSON fixutre file that was generated by making a
real API request to forms-api with the data from the database seeds.
Once we have transitioned to using the V2 API in forms-admin, it
might make more sense to use factories to generate the response.
This report downloads a CSV file containing data about all questions
in live forms.

This works the same way as the report for getting data about forms
themselves, but includes a row in the CSV per question in a live form.
Move the `UserReportService` in to a `reports` directory and under a
`Reports` module to group the different reports services together.
@stephencdaly stephencdaly force-pushed the add-csv-download-reports branch from 1b3e8ae to a6d2190 Compare January 3, 2025 14:06
Copy link

sonarqubecloud bot commented Jan 3, 2025

@hannahkc
Copy link
Contributor

hannahkc commented Jan 3, 2025

Looks good from a content perspective. This will be so useful - thank you!

Copy link
Contributor

@DavidBiddle DavidBiddle left a comment

Choose a reason for hiding this comment

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

Code changes make sense to me, the commits are well structured & documented, and the report download works on my local machine 🎉

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