Public
Edited
Jan 16, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
good_days_for_bidirectional_trip = calculatePercentDaysUnderLimit(gage_height_daily_array,"value",too_high_for_normal_bidirectional_trip)
Insert cell
gage_height_daily_array
Insert cell
function percent_good_days_for_bidirectional_trip(stream_data_array_of_objects,key_name,max_value){
var good_days = calculatePercentDaysUnderLimit(stream_data_array_of_objects,key_name,max_value)
var percent_good_days = good_days.length / stream_data_array_of_objects.length
return percent_good_days
}
Insert cell
function calculatePercentDaysUnderLimit(stream_data_array_of_objects,key_name,max_value){
return stream_data_array_of_objects.filter(good_days => (good_days[key_name] < max_value));
}
Insert cell
function limit_data_to_smaller_date_range(data){
}
Insert cell
Insert cell
maxDate = gage_height_daily_array.slice().sort((a, b) => d3.descending(a.dateTime, b.dateTime))[0].dateTime
Insert cell
minDate = gage_height_daily_array.slice().sort((a, b) => d3.ascending(a.dateTime, b.dateTime))[0].dateTime
Insert cell
function filterBySameDay(objectsArray, targetDate) {
return objectsArray.filter(obj => {
const objDate = new Date(obj.dateTime);
const targetDateObj = new Date(targetDate);
return (
objDate.getFullYear() === targetDateObj.getFullYear() &&
objDate.getMonth() === targetDateObj.getMonth() &&
objDate.getDate() === targetDateObj.getDate()
);
});
}

Insert cell
gage_height = data.value.timeSeries[1].values[0].value
Insert cell
targetDate = "2022-01-01T00:00:00.000-06:00";
Insert cell
heights_over_day = data.value.timeSeries[1].values[0].value
Insert cell
filteredArrayForSeletedDate = filterBySameDay(heights_over_day, time_slice_date.value);
Insert cell
data = d3.json('https://nwis.waterservices.usgs.gov/nwis/iv/?format=json&sites=08074000&startDT='+date_for_filter_start+'&endDT='+date_today_YYYYMMDD_string+'&parameterCd=00060,00065&siteStatus=all')
Insert cell
url_used = 'https://nwis.waterservices.usgs.gov/nwis/iv/?format=json&sites=08074000&startDT='+date_for_filter_start+'&endDT='+date_today_YYYYMMDD_string+'&parameterCd=00060,00065&siteStatus=all'
Insert cell
gage_height_daily_array = getGageHeightFromDailyAverageResults(data_daily_avg,"Gage height, ft")
Insert cell
data_daily_avg
Insert cell
function getGageHeightFromDailyAverageResults(raw_json_returned_daily_avgs,variableName){
var variableName = "Gage height, ft"
var data = raw_json_returned_daily_avgs.value.timeSeries
for (var i = 0; i < data.length; i++){
if(data[i].variable.variableName == "Gage height, ft"){
return data[i].values[0].value
}
}
}
Insert cell
Insert cell
data_daily_avg = d3.json('https://waterservices.usgs.gov/nwis/dv/?format=json&sites=08074000&startDT='+date_for_filter_start+'&endDT='+date_today_YYYYMMDD_string+'&siteStatus=all')


Insert cell
import {date} from "@jashkenas/inputs"

Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
d3 = require("d3@5")
Insert cell
vegalite = require("@observablehq/vega-lite@0.1")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more