Change election date calculations and shipping logic#1
Open
jfsalzmann wants to merge 2 commits intookfde:mainfrom
Open
Change election date calculations and shipping logic#1jfsalzmann wants to merge 2 commits intookfde:mainfrom
jfsalzmann wants to merge 2 commits intookfde:mainfrom
Conversation
Author
|
code for simulation // AFTER
function sim(ndays){
const CUTOFF_HOUR = 24 // //////////////////// ignore cutoff for simulation
const MIN_DAYS_SHIPPING = 2
const MIN_DAYS_RETURN = 3
const MIN_DAYS_BALLOTS_READY_BEFORE_ELECTION = 30
const MIN_DAYS_ORDER_BEFORE_ELECTION = 6
const MAX_DAYS_SHIPMENT_PERIOD = 7
const MAX_DAYS_PROCESSING = 14
const MAX_DAYS_SHIPPING = MIN_DAYS_SHIPPING + MAX_DAYS_PROCESSING
const day = 1000 * 60 * 60 * 24
const todayDate = new Date()
const today = todayDate.getTime() + (todayDate.getHours() >= CUTOFF_HOUR ? day : 0) + (-ndays*day)
const electionTime = selectedElection.date.getTime()
const daysLeft = Math.floor((electionTime - today) / day)
const shiftSundays = d => d + (new Date(d).getDay() === 0 ? day : 0)
const shiftWeekends = d => shiftSundays(d) + (new Date(shiftSundays(d)).getDay() === 6 ? (2 * day) : 0)
const shippingDateMin = shiftSundays(
Math.max(
shiftWeekends(today) + (MIN_DAYS_SHIPPING * day), electionTime - (MIN_DAYS_BALLOTS_READY_BEFORE_ELECTION * day)
)
)
const shippingDateMax = shiftSundays(
Math.max(
shippingDateMin, Math.min(
electionTime - (MIN_DAYS_RETURN * day), Math.max(
shippingDateMin + (MAX_DAYS_SHIPMENT_PERIOD * day), today + (MAX_DAYS_SHIPPING * day)
)
)
)
)
const arrival = (shippingDateMin === shippingDateMax) ?
`${formatDate(shippingDateMin)}` :
`${formatDate(shippingDateMin)} – ${formatDate(shippingDateMax)}`
//document.getElementById("arrival-date").innerText = arrival
return([formatDate(today),daysLeft,formatDate(shippingDateMin),formatDate(shippingDateMax),arrival]);
}
for(let i = -52; i <= 8; i++){
console.log(sim(-i));
}// BEFORE
function sim(ndays){
const MIN_DAYS = 6
const MIN_SHIPPING_DAYS = 3
const day = 1000 * 60 * 60 * 24
const todayDate = new Date()
const today = todayDate.getTime() + (-ndays*day)
const electionTime = selectedElection.date.getTime()
const shippingDateMin = Math.max(today + (3 * day), electionTime - (30 * day))
const shippingDateMax = Math.max(shippingDateMin, Math.min(today + (21 * day), electionTime - (MIN_SHIPPING_DAYS * day)))
const daysLeft = Math.floor((electionTime - today) / day)
const arrival = (shippingDateMin === shippingDateMax) ?
`${formatDate(shippingDateMin)}` :
`${formatDate(shippingDateMin)} – ${formatDate(shippingDateMax)}`
//document.getElementById("arrival-date").innerText = arrival
return([formatDate(today),daysLeft,formatDate(shippingDateMin),formatDate(shippingDateMax),arrival]);
}
for(let i = -52; i <= 8; i++){
console.log(sim(-i));
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vorschlag für eine verbesserte Berechnung der voraussichtlichen Zustellzeit der Briefwahlunterlagen.
Basiert weiterhin auf einer Heuristik die es nicht ganz so genau nimmt mit Werktagen, Postlaufzeiten etc., die aber ein paar offensichtliche Fehler behebt:
Im Ergebnis ist die Beantragung den gesamten Montag vor der Wahl noch möglich (bzw. bis Dienstag früh zum Cutoff).
Explizitere Benennung der zeitlichen Annahmen, teilweise sind die Annahmen verändert.