Cook up systems ingest script for pocketbase
This commit is contained in:
28
ingest/systemregion.sql
Normal file
28
ingest/systemregion.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
WITH RegionConnections AS (
|
||||
SELECT
|
||||
ss.regionId AS fromRegionId,
|
||||
ss_to.regionId AS toRegionId
|
||||
FROM StarGates sg
|
||||
JOIN SolarSystems ss ON sg.fromSystemId = ss.solarSystemId
|
||||
JOIN SolarSystems ss_to ON sg.toSystemId = ss_to.solarSystemId
|
||||
WHERE ss.regionId != ss_to.regionId
|
||||
),
|
||||
ConnectedRegions AS (
|
||||
SELECT
|
||||
fromRegionId,
|
||||
GROUP_CONCAT(DISTINCT r2.regionName) AS connectedRegions
|
||||
FROM RegionConnections rc
|
||||
JOIN Regions r2 ON rc.toRegionId = r2.regionId
|
||||
GROUP BY fromRegionId
|
||||
)
|
||||
SELECT
|
||||
re.regionName AS regionName,
|
||||
rml.x,
|
||||
rml.y,
|
||||
AVG(ss.security) AS security,
|
||||
COALESCE(cr.connectedRegions, '') AS connectsTo
|
||||
FROM RegionMapLayout rml
|
||||
JOIN Regions re ON rml.regionId = re.regionId
|
||||
JOIN SolarSystems ss ON ss.regionId = re.regionId
|
||||
LEFT JOIN ConnectedRegions cr ON re.regionId = cr.fromRegionId
|
||||
GROUP BY re.regionId;
|
26
ingest/systems.js
Normal file
26
ingest/systems.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import fs from 'fs';
|
||||
|
||||
const data = JSON.parse(fs.readFileSync('systems.json', 'utf8'));
|
||||
const pbUrl = "https://evebase.site.quack-lab.dev/api/collections/system/records"
|
||||
|
||||
async function main() {
|
||||
for (const system of data) {
|
||||
const datum = {
|
||||
name: system.solarSystemName,
|
||||
region: system.regionName,
|
||||
connectedTo: system.connectedSystems,
|
||||
}
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
const response = await fetch(pbUrl, {
|
||||
method: 'POST',
|
||||
headers: headers,
|
||||
body: JSON.stringify(datum),
|
||||
});
|
||||
console.log(response);
|
||||
}
|
||||
}
|
||||
main().then(() => {
|
||||
console.log('done');
|
||||
});
|
1
ingest/systems.json
Normal file
1
ingest/systems.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user