Skip to content

Commit

Permalink
Small backend adjustment
Browse files Browse the repository at this point in the history
  • Loading branch information
sdl60660 committed Jan 6, 2022
1 parent e6fcbbb commit 82e42b9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
3 changes: 1 addition & 2 deletions name_server/src/models/unnamedFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ const unamedFeatureSchema = new mongoose.Schema(
timestamp: Number,
route_start: String,
route_url: String,
},
{ collection: "unnamed_features" }
}
);

const UnnamedFeature = mongoose.model("UnnamedFeature", unamedFeatureSchema);
Expand Down
2 changes: 1 addition & 1 deletion public/data/global_stopping_features.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/components/Map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
} from "./utils/geoUtils";
import {
sendQueryData,
sendUnnamedFeatureData,
basicSiteTypeData,
getTickElevation,
getFlowrateData
Expand Down Expand Up @@ -639,6 +640,11 @@
(item, i, ar) => ar.indexOf(item) === i
);
const allNames = featurePoints.map(
(feature) => feature.properties.feature_name
)
sendUnnamedFeatureData(startCoordinates, allNames);
// This fixes a rare, but frustrating bug, where because I don't sample each flowline for VAA data, and because...
// I assume once a feature starts that it continues until the next unique feature, this function gets confused by...
// Long rivers sandwiching small unnames features, like the snake river in Idaho, and thinks that the small feature interruption
Expand Down
33 changes: 30 additions & 3 deletions src/components/utils/mapUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import {

import { addFeatureExtrusions } from "./mapboxUtils";

export const sendQueryData = async (lat, lng, startingSearch, query_error=false) => {
export const sendQueryData = async (lat, lng, startingSearch, query_error = false) => {
const queryData = {
lat,
lng,
from_share_link: startingSearch === true,
query_error
query_error,
};

fetch("https://river-runner-name-suggestions.herokuapp.com/api/query", {
Expand All @@ -24,6 +24,31 @@ export const sendQueryData = async (lat, lng, startingSearch, query_error=false)
});
};

export const sendUnnamedFeatureData = async (startCoordinates, featureNames) => {
console.log({ featureNames });

// Get list of unidentified, unique features
const unidentifiedFeatures = featureNames
.filter((d) => d.includes("Unidentified River "))
.filter((v, i, a) => a.indexOf(v) === i);

console.log({ unidentifiedFeatures });

const featureData = unidentifiedFeatures.map((feature) => ({
name_id: feature.split("Unidentified River ")[1],
current_name: `Unidentified River ${feature}`,
route_start: JSON.stringify(startCoordinates),
}));

fetch("https://river-runner-name-suggestions.herokuapp.com/api/unnamed_features", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(featureData),
});
};

export const basicSiteTypeData = {
"NWIS Surface Water Sites": {
color: "green",
Expand Down Expand Up @@ -223,7 +248,9 @@ export const getFlowrateData = async (flowlineFeatures, thinningIndex = 4, buffe
const nextIndex = thinningIndex * Math.ceil(i / thinningIndex);

const lastValue = flowrateData[lastIndex].properties.flowrate;
const nextValue = flowrateData[nextIndex] ? flowrateData[nextIndex].properties.flowrate : null;
const nextValue = flowrateData[nextIndex]
? flowrateData[nextIndex].properties.flowrate
: null;

let interpolatedValue = nextValue
? lastValue + (nextValue - lastValue) * ((i % thinningIndex) / thinningIndex)
Expand Down

1 comment on commit 82e42b9

@vercel
Copy link

@vercel vercel bot commented on 82e42b9 Jan 6, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.