Skip to content

Commit

Permalink
implement data-dependant date limits
Browse files Browse the repository at this point in the history
  • Loading branch information
Nate-Wessel committed Jul 15, 2024
1 parent 432cf7c commit c428b51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 12 additions & 5 deletions frontend/src/dateRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { DataContext } from './Layout'
export class DateRange extends Factor {
#startDate
#endDate
#dataContext
constructor(dataContext){
super(dataContext)
this.#dataContext = dataContext
}
get isComplete(){
return this.#startDate && this.#endDate && this.#startDate < this.#endDate
Expand Down Expand Up @@ -71,6 +73,14 @@ export class DateRange extends Factor {
}
return dayCount
}
get maxDate(){
// default to today if actual max date not known (yet)
return this.#dataContext.dateRange.maxDate ?? new Date()
}
get minDate(){
// default to today if actual max date not known (yet)
return this.#dataContext.dateRange.minDate ?? new Date('2017-09-01')
}
}

function formatISODate(dt){ // this is waaay too complicated... alas
Expand All @@ -80,9 +90,6 @@ function formatISODate(dt){ // this is waaay too complicated... alas
return `${year}-${('0'+month).slice(-2)}-${('0'+day).slice(-2)}`
}

const today = new Date()
const earliestDataDate = new Date('2017-01-01')

function DateRangeElement({dateRange}){
const { logActivity } = useContext(DataContext)
const [ selectedRange, setSelectedRange ] = useState(undefined)
Expand All @@ -102,8 +109,8 @@ function DateRangeElement({dateRange}){
selectRange={true}
allowPartialRange={true}
onChange={setSelectedRange}
maxDate={today}
minDate={earliestDataDate}
maxDate={dateRange.maxDate}
minDate={dateRange.minDate}
/>
</> }
</div>
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/spatialData.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@ export class SpatialData {
#factors = []
#queries = new Map() // store/cache for travelTimeQueries, letting them remember their results if any
#knownHolidays = []
#dataDateRange = { minDate: undefined, maxDate: undefined }
#queue = new PQueue({concurrency: 3})
constructor(){
this.#factors.push(new Days(this))
this.#factors.push(new HolidayOption(this,true))
fetch(`${domain}/holidays`)
.then( response => response.json() )
.then( holidayList => this.#knownHolidays = holidayList )
fetch(`${domain}/date-range`)
.then( response => response.json() )
.then( dates => {
this.#dataDateRange.minDate = new Date(dates.minDate)
this.#dataDateRange.maxDate = new Date(dates.maxDate)
} )
}
get corridors(){ return this.#factors.filter( f => f instanceof Corridor ) }
get timeRanges(){ return this.#factors.filter( f => f instanceof TimeRange ) }
Expand All @@ -31,6 +38,7 @@ export class SpatialData {
return this.corridors.find( cor => cor.isActive )
}
get holidays(){ return this.#knownHolidays }
get dateRange(){ return this.#dataDateRange }
createCorridor(){
let corridor = new Corridor(this)
this.#factors.push(corridor)
Expand Down

0 comments on commit c428b51

Please sign in to comment.