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 water quality data to site model and use it to power site filter #1076

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

yaodingyd
Copy link
Collaborator

fix #1026
/claim #1026

Add waterQuality to site model that would include list of water quality metrics.

The logics to determine water quality metrics is from

const combinedArray = [...forecastData, ...latestData];
const parsedData = parseLatestData(combinedArray);
const hasSpotter = Boolean(parsedData.bottomTemperature);
const hasSonde =
sondeMetrics.filter((x) => Boolean(parsedData[x])).length >=
MINIMUM_SONDE_METRICS_TO_SHOW_CARD;
const hasHUI =
latestData.some((x) => x.source === 'hui') ||
sourceWithinDataRangeInterval(
acceptHUIInterval,
'hui',
timeSeriesRange,
);
setHasSondeData(hasSonde);
setHasSpotterData(hasSpotter);
setHasHUIData(hasHUI);

which looks at LatestData entity (and forecast data, omitted by now) and check if they have hui source or enough sonde metrics.

If this is the correct direction, I can work on a follow up to remove the checks in frontend and consolidate to the backend, so we have single source of truth. This also avoid multiple data fetching to get water quality data

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 for review. Expert reviewers are now being matched to your request based on the code's requirements. Stay tuned!

What to expect from this code review:
  • Comments posted to any areas of potential concern or improvement.
  • Detailed feedback or actions needed to resolve issues that are found.
  • Turnaround times vary, but we aim to be swift.

@yaodingyd you can click here to see the review status or cancel the code review job.

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

+ 70
- 1

85% TypeScript
15% Jest Snapshot (tests)

Type of change

Feature - These changes are adding a new feature or improvement to existing code.

Copy link

github-actions bot commented Dec 17, 2024

Build succeeded and deployed at https://aqualink-app-1076.surge.sh
(hash d7361e9 deployed at 2025-01-23T16:00:57)

@yaodingyd yaodingyd marked this pull request as draft December 17, 2024 15:28
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 would normally not be reviewed by PullRequest because the pull request is a draft; however since a review was already requested, it is currently being reviewed by the PullRequest network. If you would like to cancel it, you can do so manually from the PullRequest dashboard.

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.

Nice work here. I don't have any concerns with these changes, security or otherwise.

Image of Graham C Graham C


Reviewed with ❤️ by PullRequest

@@ -1,3 +1,5 @@
/* eslint-disable fp/no-mutating-methods */
Copy link
Member

Choose a reason for hiding this comment

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

Would it be easy to do this inline instead of for the whole file?

@yaodingyd yaodingyd marked this pull request as ready for review December 17, 2024 16:45
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 #1076 up until the latest commit (a17524a). No further issues were found.

Reviewed by:

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.

Due to inactivity, PullRequest has cancelled this review job. You can reactivate the code review job from the PullRequest dashboard.

@K-Markopoulos K-Markopoulos self-requested a review January 21, 2025 15:59
packages/api/src/sites/sites.entity.ts Outdated Show resolved Hide resolved
@@ -278,6 +278,52 @@ export const hasHoboDataSubQuery = async (
return hasHoboDataSet;
};

export const hasWaterQualityDataSubQuery = async (
Copy link
Collaborator

Choose a reason for hiding this comment

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

has prefix is usually used for functions that return boolean, but this one returns a map. It might be better to rename or return a boolean instead of the map, since we are only interested in a specific site and not all the map.

packages/api/src/utils/site.utils.ts Outdated Show resolved Hide resolved
.select('site_id', 'siteId')
.addSelect('metric')
.addSelect('source')
.where(`source != '${SourceType.HOBO}'`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are looking for hui and sonde sources so let's specify that in the where clause to only get these. Also, it will be more performant to filter by siteId here and not load the whole table (or view) in memory.

Comment on lines +292 to +298
const sondeMetrics = [
'odoConcentration',
'cholorophyllConcentration',
'ph',
'salinity',
'turbidity',
];
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can use the metrics in snake_case as they are stored in DB instead of writing them in camel case and converting the metric in each iteration. We can use Metric enum directly.

yaodingyd and others added 2 commits January 23, 2025 10:57
Co-authored-by: Konstantinos Markopoulos <[email protected]>
Co-authored-by: Konstantinos Markopoulos <[email protected]>
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.

Add water quality sites in the map filter
3 participants