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

Fix missing data from CSV download #899

Merged
merged 15 commits into from
Jul 27, 2023
Merged

Fix missing data from CSV download #899

merged 15 commits into from
Jul 27, 2023

Conversation

echaidemenos
Copy link
Collaborator

resolves #879

Basically moves CSV creation to the backend, fixing the issue of missing date when selecting all dates.
The issue was caused because the backend limits time-series data to 3 months if no other limit is specified.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

✅ This pull request was sent to the PullRequest network.


Check the status or cancel PullRequest code review here.

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

PullRequest Breakdown

Reviewable lines of change

+ 319
- 206

63% TypeScript
33% TSX
3% TypeScript (tests)
1% JSON (tests)
1% JSON

Generated lines of change

+ 15
- 5

Type of change

Fix - These changes are likely to be fixing a bug or issue.

@github-actions
Copy link

github-actions bot commented Jul 4, 2023

Build succeeded and deployed at https://aqualink-app-899.surge.sh
(hash ff2c9f9 deployed at 2023-07-24T16:14:03)

Copy link

@pullrequest pullrequest bot 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 directionally correct, but I have a few concerns left inline for your consideration, some I am aware were issues before, but in touched code or very close to touched code, so I have brought them up to be on the safe side. Other than those issues, a little more test coverage would be great to see.

Image of Graham C Graham C


Reviewed with ❤️ by PullRequest

packages/api/src/time-series/time-series.service.ts Outdated Show resolved Hide resolved
packages/api/src/time-series/time-series.service.ts Outdated Show resolved Hide resolved
packages/api/src/utils/time-series.utils.ts Outdated Show resolved Hide resolved
packages/website/src/helpers/siteUtils.ts Outdated Show resolved Hide resolved
packages/website/src/utils/utils.ts Outdated Show resolved Hide resolved
Copy link

@pullrequest pullrequest bot 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 much better. We still have an issue with unbounded work due to no checks on the to and from date, and I've noted a few more things inline for your consideration. Bounded work is important to make sure that the database is not overloaded and that the response size is small enough to not cause issues.

There's a great talk https://www.youtube.com/watch?v=Fup5vHEvU50 that covers things like bounded work, which matters for availability, which is one of the three tiers for good security: confidentiality, integrity, availability - the so called CIA triad.

Image of Graham C Graham C


Reviewed with ❤️ by PullRequest

packages/api/src/pipes/parse-metric-array.pipe.ts Outdated Show resolved Hide resolved
packages/api/src/time-series/time-series.controller.ts Outdated Show resolved Hide resolved
packages/api/src/time-series/time-series.service.ts Outdated Show resolved Hide resolved
@@ -171,6 +175,53 @@ export class TimeSeriesController {
const file = this.timeSeriesService.getSampleUploadFiles(
surveyPointDataRangeDto,
);
res.set({
'Content-Disposition': `attachment; filename=${encodeURIComponent(
`${surveyPointDataRangeDto.source}_example.csv`,
Copy link

Choose a reason for hiding this comment

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

This encoding is wrapping the wrong thing. The while filename needs to be in there, not just the variable part, as per the code snippet from the previous review.


const filename = `${surveyPointDataRangeDto.source}_example.csv`;
res.set({
  'Content-Disposition': `attachment; filename=${encodeURIComponent(filename)}`,
});

🔸 Bug (Important)

Image of Graham C Graham C

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is the same:

res.set({
      'Content-Disposition': `attachment; filename=${encodeURIComponent(
        `${surveyPointDataRangeDto.source}_example.csv`,
      )}`,
    });

encodeURIComponent wraps

`${surveyPointDataRangeDto.source}_example.csv`

Copy link

Choose a reason for hiding this comment

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

The output is the same, but the code no longer violates separation of concerns. We should not assume that encoding _example.csv doesn't change it.

Image of Graham C Graham C

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the code does not assume that _example.csv doesn't change. It is wrapped by the encodeURIComponent call. What i meant is the same was that i don't declare

const filename = `${surveyPointDataRangeDto.source}_example.csv`;

but i just call encodeURIComponent with ${surveyPointDataRangeDto.source}_example.csv as argument

Copy link

Choose a reason for hiding this comment

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

Because you are assuming that _example.csv is the output of encodeURIComponent('_example.csv'), which breaks separation of concerns.

Image of Graham C Graham C

Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

Great work. Thanks for being so patient with my feedback. 🚀

Image of Graham C Graham C


Reviewed with ❤️ by PullRequest

@ericboucher ericboucher merged commit faf5c93 into master Jul 27, 2023
3 checks passed
@ericboucher ericboucher deleted the csv-dowloads branch July 27, 2023 20:11
Copy link

@pullrequest pullrequest bot left a comment

Choose a reason for hiding this comment

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

PullRequest reviewed the updates made to #899 up until the latest commit (ff2c9f9). No further issues were found.

Reviewed by:

Image of Graham C Graham C

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.

CSV download missing data
2 participants