Skip to content

Commit

Permalink
Task 1062 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MashB committed Jul 17, 2024
1 parent 9fbe1b2 commit 588fa08
Show file tree
Hide file tree
Showing 11 changed files with 6,171 additions and 5 deletions.
53 changes: 53 additions & 0 deletions db-management/migrations/20240712072852-osw-entity-column-alter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20240712072852-osw-entity-column-alter-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20240712072852-osw-entity-column-alter-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE content.edge
DROP COLUMN IF EXISTS "crossing:markings";

ALTER TABLE content.edge
ADD COLUMN IF NOT EXISTS "crossing_markings" character varying GENERATED ALWAYS AS ((feature->'properties'->>'crossing:markings')::text) STORED;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE content.edge
DROP COLUMN IF EXISTS "crossing_markings";

ALTER TABLE content.edge
ADD COLUMN IF NOT EXISTS "crossing:markings" character varying GENERATED ALWAYS AS ((feature->'properties'->>'crossing:markings')::text) STORED;
148 changes: 148 additions & 0 deletions osw_entity_identifying_fields_extract_script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
const fs = require('fs');

// Read the JSON file
fs.readFile('src/assets/opensidewalks_0.2.schema.json', 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
const ignore_keys = ["BuildingField", "BuildingFields", "BareNodeFields"];
const entity_types = {
"RolledCurb": {
"entity_type": "node"
},
"RaisedCurb": {
"entity_type": "node"
},
"CurbRamp": {
"entity_type": "node"
},
"FlushCurb": {
"entity_type": "node"
},
"GenericCurb": {
"entity_type": "node"
},
"Footway": {
"entity_type": "edge"
},
"Sidewalk": {
"entity_type": "edge"
},
"Crossing": {
"entity_type": "edge"
},
"TrafficIsland": {
"entity_type": "edge"
},
"Pedestrian": {
"entity_type": "edge"
},
"Steps": {
"entity_type": "edge"
},
"LivingStreet": {
"entity_type": "edge"
},
"PrimaryStreet": {
"entity_type": "edge"
},
"SecondaryStreet": {
"entity_type": "edge"
},
"TertiaryStreet": {
"entity_type": "edge"
},
"ResidentialStreet": {
"entity_type": "edge"
},
"ServiceRoad": {
"entity_type": "edge"
},
"Alley": {
"entity_type": "edge"
},
"Driveway": {
"entity_type": "edge"
},
"ParkingAisle": {
"entity_type": "edge"
},
"TrunkRoad": {
"entity_type": "edge"
},
"UnclassifiedRoad": {
"entity_type": "edge"
},
"PedestrianZone": {
"entity_type": "zone"
},
"PowerPole": {
"entity_type": "point"
},
"FireHydrant": {
"entity_type": "point"
},
"Bench": {
"entity_type": "point"
},
"WasteBasket": {
"entity_type": "point"
},
"Bollard": {
"entity_type": "point"
},
"Manhole": {
"entity_type": "point"
},
"StreetLamp": {
"entity_type": "point"
},
"Fence": {
"entity_type": "edge"
}
};
// Parse the JSON data
const schema = JSON.parse(data);

// Initialize an empty object to store the results
let result = {};

// Iterate over each key in the definitions
for (let key in schema.definitions) {
// Check if the key starts with an underscore
if (key.includes('Fields') && !ignore_keys.includes(key)) {
// if (!key.startsWith('_')) {
// Get the required properties
let required = schema.definitions[key].required;

// Initialize an empty object for the identifying_key_val
let identifying_key_val = {};

// Iterate over each required property
for (let prop of required) {
// Check if the property starts with an underscore
if (!prop.startsWith('_')) {
// Get the first enum value for the property
let enumVal = schema.definitions[key].properties[prop].enum[0];
// Add the property and its first enum value to the identifying_key_val object
identifying_key_val[prop] = enumVal;
}
}

let prop_key = key.replace("Fields", "");
// Add the identifying_key_val object to the result object
result[prop_key] = { entity_type: entity_types[prop_key].entity_type, identifying_key_val };
}
}
let resultJson = JSON.stringify(result, null, 2);

// Write the JSON string to a file
fs.writeFile('src/assets/opensidewalks_0.2.identifying.fields.json', resultJson, 'utf8', (err) => {
if (err) {
console.error(err);
return;
}
console.log('File has been saved.');
});
});
Loading

0 comments on commit 588fa08

Please sign in to comment.