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

just modifying the breakpoints for all the index endpoints #3843

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/device-registry/config/global/mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ function generateDateFormatWithoutHrs(ISODate) {

const mappings = {
AQI_INDEX: {
good: [0, 12],
moderate: [12.1, 35.4],
u4sg: [35.5, 55.4],
unhealthy: [55.5, 150.4],
very_unhealthy: [150.5, 250.4],
hazardous: [250.5, 500],
good: { min: 0, max: 9.0 },
moderate: { min: 9.1, max: 35.4 },
u4sg: { min: 35.5, max: 55.4 },
unhealthy: { min: 55.5, max: 125.4 },
very_unhealthy: { min: 125.5, max: 225.4 },
hazardous: { min: 225.5, max: null },
Comment on lines +30 to +35
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

Data structure updated, but range boundaries and category naming require attention

The AQI_INDEX structure has been improved for clarity. However, please address the following:

  • Range Boundaries: There appears to be a gap between 9.0 and 9.1. Ensure that all values are covered without overlaps or gaps.
  • Category Naming: The category name "u4sg" is non-standard and may cause confusion. Consider renaming it to a more descriptive term for better clarity and maintainability.
🔗 Analysis chain

Improved data structure, but ranges need verification

The transition from array-based to object-based structure with explicit min and max values improves clarity and maintainability. However, let's verify a few critical aspects:

  1. The ranges appear to have potential gaps at the boundary values (e.g., between 9.0 and 9.1)
  2. The category name "u4sg" is non-standard and could be unclear
  3. The ranges should be validated against standard AQI breakpoints

Consider these improvements:

 AQI_INDEX: {
-    good: { min: 0, max: 9.0 },
-    moderate: { min: 9.1, max: 35.4 },
-    u4sg: { min: 35.5, max: 55.4 },
+    good: { min: 0, max: 9 },
+    moderate: { min: 9, max: 35 },
+    unhealthy_sensitive: { min: 35, max: 55 },
     unhealthy: { min: 55.5, max: 125.4 },
     very_unhealthy: { min: 125.5, max: 225.4 },
     hazardous: { min: 225.5, max: null },
 },
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usages of AQI_INDEX to ensure compatibility with new structure

# Look for direct references to AQI_INDEX
echo "Searching for AQI_INDEX usage patterns..."
rg -l "AQI_INDEX" 

# Look for specific category references
echo "\nSearching for category references..."
rg -l "good|moderate|u4sg|unhealthy|very_unhealthy|hazardous"

Length of output: 1902


Script:

#!/bin/bash
# Description: Extract usages of AQI_INDEX in generate-filter.js

rg "AQI_INDEX" src/device-registry/utils/generate-filter.js

# Description: Search for usage of the "u4sg" category across the codebase
rg "\"u4sg\"" .

Length of output: 634

},
GET_ROAD_METADATA_PATHS: {
altitude: "altitude",
Expand Down
26 changes: 20 additions & 6 deletions src/device-registry/utils/generate-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ const generateFilter = {
if (!index) {
delete filter["values.pm2_5.value"];
} else if (Object.keys(constants.AQI_INDEX).includes(index)) {
filter["values.pm2_5.value"]["$gte"] = constants.AQI_INDEX[index][0];
filter["values.pm2_5.value"]["$lte"] = constants.AQI_INDEX[index][1];
const range = constants.AQI_INDEX[index];
filter["values.pm2_5.value"]["$gte"] = range.min;
// Only set $lte if max is not null
if (range.max !== null) {
filter["values.pm2_5.value"]["$lte"] = range.max;
}
Comment on lines +83 to +88
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Initialize 'filter["values.pm2_5.value"]' before assigning properties

To prevent potential runtime errors, please ensure that filter["values.pm2_5.value"] is initialized as an object before setting the $gte and $lte properties.

Apply this diff to fix the issue:

+          filter["values.pm2_5.value"] = {};
           filter["values.pm2_5.value"]["$gte"] = range.min;
           // Only set $lte if max is not null
           if (range.max !== null) {
             filter["values.pm2_5.value"]["$lte"] = range.max;
           }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const range = constants.AQI_INDEX[index];
filter["values.pm2_5.value"]["$gte"] = range.min;
// Only set $lte if max is not null
if (range.max !== null) {
filter["values.pm2_5.value"]["$lte"] = range.max;
}
const range = constants.AQI_INDEX[index];
filter["values.pm2_5.value"] = {};
filter["values.pm2_5.value"]["$gte"] = range.min;
// Only set $lte if max is not null
if (range.max !== null) {
filter["values.pm2_5.value"]["$lte"] = range.max;
}

filter["index"] = index;
} else {
delete filter["values.pm2_5.value"];
Expand Down Expand Up @@ -341,8 +345,13 @@ const generateFilter = {
if (!index) {
delete filter["values.pm2_5.value"];
} else if (Object.keys(constants.AQI_INDEX).includes(index)) {
filter["values.pm2_5.value"]["$gte"] = constants.AQI_INDEX[index][0];
filter["values.pm2_5.value"]["$lte"] = constants.AQI_INDEX[index][1];
const range = constants.AQI_INDEX[index];
filter["values.pm2_5.value"] = {};
filter["values.pm2_5.value"]["$gte"] = range.min;
// Only set $lte if max is not null
if (range.max !== null) {
filter["values.pm2_5.value"]["$lte"] = range.max;
}
filter["index"] = index;
} else {
delete filter["values.pm2_5.value"];
Expand Down Expand Up @@ -670,8 +679,13 @@ const generateFilter = {
if (!index) {
delete filter["values.pm2_5.value"];
} else if (Object.keys(constants.AQI_INDEX).includes(index)) {
filter["values.pm2_5.value"]["$gte"] = constants.AQI_INDEX[index][0];
filter["values.pm2_5.value"]["$lte"] = constants.AQI_INDEX[index][1];
const range = constants.AQI_INDEX[index];
filter["values.pm2_5.value"] = {};
filter["values.pm2_5.value"]["$gte"] = range.min;
// Only set $lte if max is not null
if (range.max !== null) {
filter["values.pm2_5.value"]["$lte"] = range.max;
}
filter["index"] = index;
} else {
delete filter["values.pm2_5.value"];
Expand Down
Loading