gtfs 4.17.2 → 4.17.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/gtfs-import.js
CHANGED
|
@@ -3353,16 +3353,6 @@ function convertLongTimeToDate(longDate) {
|
|
|
3353
3353
|
Long.fromBits(low, high, unsigned).toNumber() * 1e3
|
|
3354
3354
|
).toISOString();
|
|
3355
3355
|
}
|
|
3356
|
-
function calculateSecondsFromMidnight(time) {
|
|
3357
|
-
if (!time || typeof time !== "string") {
|
|
3358
|
-
return null;
|
|
3359
|
-
}
|
|
3360
|
-
const [hours, minutes, seconds] = time.split(":").map(Number);
|
|
3361
|
-
if ([hours, minutes, seconds].some(isNaN) || minutes >= 60 || seconds >= 60) {
|
|
3362
|
-
return null;
|
|
3363
|
-
}
|
|
3364
|
-
return hours * 3600 + minutes * 60 + seconds;
|
|
3365
|
-
}
|
|
3366
3356
|
function padLeadingZeros(time) {
|
|
3367
3357
|
const split = time.split(":").map((d) => String(Number(d)).padStart(2, "0"));
|
|
3368
3358
|
if (split.length !== 3) {
|
|
@@ -3587,18 +3577,6 @@ async function updateGtfsRealtimeData(task) {
|
|
|
3587
3577
|
}
|
|
3588
3578
|
|
|
3589
3579
|
// src/lib/import-gtfs.ts
|
|
3590
|
-
var timeCache = {};
|
|
3591
|
-
var formatAndCacheTime = (value) => {
|
|
3592
|
-
const cached = timeCache[value];
|
|
3593
|
-
if (cached !== void 0) {
|
|
3594
|
-
return cached;
|
|
3595
|
-
}
|
|
3596
|
-
const timeAsSecondsFromMidnight = calculateSecondsFromMidnight(value);
|
|
3597
|
-
const timeAsString = padLeadingZeros(value);
|
|
3598
|
-
const computed = [timeAsSecondsFromMidnight, timeAsString];
|
|
3599
|
-
timeCache[value] = computed;
|
|
3600
|
-
return computed;
|
|
3601
|
-
};
|
|
3602
3580
|
var getTextFiles = async (folderPath) => {
|
|
3603
3581
|
const files = await readdir(folderPath);
|
|
3604
3582
|
return files.filter((filename) => filename.slice(-3) === "txt");
|
|
@@ -3710,7 +3688,16 @@ var createGtfsTables = (db) => {
|
|
|
3710
3688
|
);
|
|
3711
3689
|
if (column.type === "time") {
|
|
3712
3690
|
sqlColumnCreateStatements.push(
|
|
3713
|
-
`${getTimestampColumnName(column.name)} INTEGER
|
|
3691
|
+
`${getTimestampColumnName(column.name)} INTEGER GENERATED ALWAYS AS (
|
|
3692
|
+
CASE
|
|
3693
|
+
WHEN ${column.name} IS NULL OR ${column.name} = '' THEN NULL
|
|
3694
|
+
ELSE CAST(
|
|
3695
|
+
substr(${column.name}, 1, instr(${column.name}, ':') - 1) * 3600 +
|
|
3696
|
+
substr(${column.name}, instr(${column.name}, ':') + 1, 2) * 60 +
|
|
3697
|
+
substr(${column.name}, -2) AS INTEGER
|
|
3698
|
+
)
|
|
3699
|
+
END
|
|
3700
|
+
) STORED`
|
|
3714
3701
|
);
|
|
3715
3702
|
}
|
|
3716
3703
|
}
|
|
@@ -3755,9 +3742,6 @@ var formatGtfsLine = (line, model, totalLineCount) => {
|
|
|
3755
3742
|
let value = line[name];
|
|
3756
3743
|
if (value === "" || value === void 0 || value === null) {
|
|
3757
3744
|
formattedLine[name] = null;
|
|
3758
|
-
if (type === "time") {
|
|
3759
|
-
formattedLine[getTimestampColumnName(name)] = null;
|
|
3760
|
-
}
|
|
3761
3745
|
if (required) {
|
|
3762
3746
|
throw new Error(
|
|
3763
3747
|
`Missing required value in ${filenameBase}.${filenameExtension} for ${name} on line ${lineNumber}.`
|
|
@@ -3773,9 +3757,7 @@ var formatGtfsLine = (line, model, totalLineCount) => {
|
|
|
3773
3757
|
);
|
|
3774
3758
|
}
|
|
3775
3759
|
} else if (type === "time") {
|
|
3776
|
-
|
|
3777
|
-
value = timeAsString;
|
|
3778
|
-
formattedLine[getTimestampColumnName(name)] = timeAsSecondsFromMidnight ?? null;
|
|
3760
|
+
value = padLeadingZeros(value);
|
|
3779
3761
|
}
|
|
3780
3762
|
if (type === "json") {
|
|
3781
3763
|
value = JSON.stringify(value);
|
|
@@ -3808,19 +3790,7 @@ var importGtfsFiles = (db, task) => mapSeries2(
|
|
|
3808
3790
|
return;
|
|
3809
3791
|
}
|
|
3810
3792
|
task.log(`Importing - ${filename}\r`);
|
|
3811
|
-
const columns = model.schema
|
|
3812
|
-
if (column.type === "time") {
|
|
3813
|
-
return [
|
|
3814
|
-
column,
|
|
3815
|
-
{
|
|
3816
|
-
name: getTimestampColumnName(column.name),
|
|
3817
|
-
type: "integer",
|
|
3818
|
-
index: true
|
|
3819
|
-
}
|
|
3820
|
-
];
|
|
3821
|
-
}
|
|
3822
|
-
return column;
|
|
3823
|
-
});
|
|
3793
|
+
const columns = model.schema;
|
|
3824
3794
|
const prefixedColumns = new Set(
|
|
3825
3795
|
columns.filter((column) => column.prefix).map((column) => column.name)
|
|
3826
3796
|
);
|