Skip to content

Commit

Permalink
Merge pull request #67 from traveltime-dev/add-level-of-details-to-ti…
Browse files Browse the repository at this point in the history
…me-map

Add level of details to time-map
  • Loading branch information
Donatas-L authored Jul 24, 2024
2 parents 0514563 + 8bcca9a commit 3286986
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions scripts/time-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function setup () {
const url = `https://${host}/v4/time-map`
const transportation = __ENV.TRANSPORTATION || 'driving+ferry'
const travelTime = parseInt(__ENV.TRAVEL_TIME || 7200)
const levelOfDetails = parseInt(__ENV.LEVEL_OF_DETAILS || -8)
const uniqueRequestsAmount = parseInt(__ENV.UNIQUE_REQUESTS || 100)

const params = {
Expand All @@ -54,8 +55,8 @@ export function setup () {
const dateTime = new Date().toISOString()

const requestBodies = precomputedDataFile
? readRequestsBodies(travelTime, transportation, dateTime, precomputedDataFile)
: generateRequestBodies(uniqueRequestsAmount, travelTime, transportation, locationCoords, dateTime)
? readRequestsBodies(travelTime, transportation, dateTime, levelOfDetails, precomputedDataFile)
: generateRequestBodies(uniqueRequestsAmount, travelTime, transportation, locationCoords, dateTime, levelOfDetails)

return { url, requestBodies, params }
}
Expand Down Expand Up @@ -86,7 +87,7 @@ export function handleSummary (data) {
}
}

function generateBody (travelTime, transportation, coords, dateTime) {
function generateBody (travelTime, transportation, coords, dateTime, levelOfDetails) {
return JSON.stringify({
departure_searches: [{
id: 'Time map benchmark',
Expand All @@ -95,12 +96,16 @@ function generateBody (travelTime, transportation, coords, dateTime) {
travel_time: travelTime,
transportation: {
type: transportation
},
level_of_detail: {
scale_type: 'simple_numeric',
level: levelOfDetails
}
}]
})
}

function readRequestsBodies (travelTime, transportation, dateTime, precomputedDataFile) {
function readRequestsBodies (travelTime, transportation, dateTime, levelOfDetails, precomputedDataFile) {
const data = papaparse
.parse(precomputedDataFile, { header: true, skipEmptyLines: true })
.data
Expand All @@ -109,14 +114,15 @@ function readRequestsBodies (travelTime, transportation, dateTime, precomputedDa
travelTime,
transportation,
{ lat: parseFloat(origins.lat), lng: parseFloat(origins.lng) },
dateTime
dateTime,
levelOfDetails
)
)
console.log('The amount of requests read: ' + data.length)
return data
}

function generateRequestBodies (count, travelTime, transportation, locationCoords, dateTime) {
function generateRequestBodies (count, travelTime, transportation, locationCoords, dateTime, levelOfDetails) {
console.log('The amount of requests generated: ' + count)
const diff = 0.01

Expand All @@ -127,7 +133,8 @@ function generateRequestBodies (count, travelTime, transportation, locationCoord
travelTime,
transportation,
generateRandomCoordinate(locationCoords.lat, locationCoords.lng, diff),
dateTime
dateTime,
levelOfDetails
)
)
}

0 comments on commit 3286986

Please sign in to comment.