Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More schema test helper functions #5448

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions translations/TranslationServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ if (typeof hoot === 'undefined') {
hoot.Settings.set({"ogr.note.extra": "attribute"});
hoot.Settings.set({"reader.add.source.datetime": "false"});
hoot.Settings.set({"writer.include.circular.error.tags": "false"});
hoot.Settings.set({"ogr.thematic.structure":"false"});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattjdnv This change doesn't really have a practical impact does it? The output is only ever going to osm format, not an ogr format like shp or gdb.


// LOTS of debug output on the console (journalctl -xe -u tomcat8)
// hoot.Settings.set({"ogr.debug.dumptags": "true"});


// Throw errors instead of returning partial translations/o2s_X features
hoot.Settings.set({'ogr.throw.error':'true'});

Expand Down Expand Up @@ -132,18 +136,15 @@ var translationsMap = {
var tLocal = {}
try {
tLocal = require(HOOT_HOME + '/translations-local/translationServerConfig.json');

Object.keys(tLocal.availableTrans).forEach(k => {availableTrans[k] = tLocal.availableTrans[k]});
Object.keys(tLocal.schemaMap).forEach(k => {schemaMap[k] = require(HOOT_HOME + tLocal.schemaMap[k]); });
Object.keys(tLocal.fcodeLookup).forEach(k => {fcodeLookup[k] = require(HOOT_HOME + tLocal.fcodeLookup[k])});

Object.keys(tLocal.translationsMap.toogr).forEach(k => {
translationsMap.toogr[k] = new hoot.SchemaTranslationOp({
'schema.translation.script': HOOT_HOME + tLocal.translationsMap.toogr[k],
'schema.translation.direction': 'toogr'
});
});

Object.keys(tLocal.translationsMap.toosm).forEach(k => {
translationsMap.toosm[k] = new hoot.SchemaTranslationOp({
'schema.translation.script': HOOT_HOME + tLocal.translationsMap.toosm[k],
Expand Down
32 changes: 25 additions & 7 deletions translations/checkAllFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

var HOOT_HOME = process.env.HOOT_HOME;

// Library functions
transTest = require(HOOT_HOME + '/translations/checkTranslations.js');

// Skip the TransportationGroundCrv type layers
Expand All @@ -43,6 +44,20 @@ hoot.Settings.set({"ogr.thematic.structure":"false"});
// hoot.Settings.set({"ogr.debug.dumptags":"true"});
hoot.Settings.set({"ogr.debug.dumpvalidate":"true"});


// ####################################################################################
// getTranslations, getCapabilities,
var tList = transTest.getThing('translations');
console.log('\nTransList: ' + JSON.stringify(tList));

tList = transTest.getThing('capabilities');
console.log('\nCapabilities: ' + JSON.stringify(tList));

tList = transTest.getThing('version');
console.log('\nVersion: ' + JSON.stringify(tList));

// process.exit();

// ####################################################################################
// The map of schema to test
var schemaMap = {
Expand All @@ -62,30 +77,33 @@ var schemaMap = {
// }

// Test every fcode in a schema
transTest.testSchema(schemaMap);
// transTest.testSchema(schemaMap);

process.exit();
// process.exit();

// ####################################################################################
// Dump values from a schema
// This dumps out what F_CODE has an attribute and if it is an enumeration, the consolidated list
// This dumps out what F_CODE has an attribute and if it is an enumeration, the list of values
console.log('\nMGCP F_CODES with FFN');
transTest.dumpValues(schemaMap.MGCP,'FFN');

console.log('\nMGCP F_CODES with WID');
transTest.dumpValues(schemaMap.MGCP,'WID');

// process.exit();
process.exit();

// ####################################################################################
// List of geometries to test
var geomList = ['Point','Line','Area'];

// All of the possible export schema
// All of the schema to test
var schemaList = ['MGCP','DNC','ENCv311','TDSv40','TDSv61','TDSv70','TDSv71','GGDMv30'];

// List of F_CODES to test
// NOTE: "smurf" should send back an error
var fCodeList = [
// 'AA012',
'smurf',
'smurf',
'BB082',
'AL015',
'AL013',
Expand All @@ -108,7 +126,7 @@ var fCodeList = [
// 'AD010'
];

// Test a single F_CODE
// Test a single F_CODE in multiple schema and with multiple geometry types
// transTest.testF_CODE(fCodeList,schemaList,geomList);

// End
36 changes: 26 additions & 10 deletions translations/checkTranslations.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ function makeJson(OSM)
return osmJson;
};


function getTranslationsList()
{
try {
Expand All @@ -141,6 +142,7 @@ function getTranslationsList()
}
}; // End getTranslationsList


// Wrapper for 'capabilities', 'translations','version' etc'
function getThing(thing)
{
Expand All @@ -158,6 +160,25 @@ function getThing(thing)
}; // End thing


// Console.log version of translate.dumpSchema
function dumpSchema(schema)
{
schema.forEach( function(item) {
console.log('Feature: ' + item.name + ' Geom: ' + item.geom + ' FdName: ' + item.fdname);

item.columns.forEach( function (column) {
console.log(' Attr: ' + column.name + ' Desc: ' + column.desc + ' Type: ' + column.type + ' Default: ' + column.defValue);
if (column.type == 'enumeration')
{
column.enumerations.forEach( function (eValue) {console.log(' Value: ' + eValue.value + ' Name: ' + eValue.name); });
}
});

console.log(''); // just to get one blank line
});
}


function schemaFromFcode(F_CODE,geometry,schema)
{
try {
Expand Down Expand Up @@ -225,7 +246,6 @@ var endLine = '</way></osm>'; // NOTE: This is also for Areas as well
function testTranslated(schema,featureCode,tagList,geomList = ['Point','Line','Area'])
{
console.log('---------------');

var osmFeatures = {};

osmFeatures.Point = startPoint + '<tag k="F_CODE" v="' + featureCode + '"/>';
Expand Down Expand Up @@ -436,20 +456,19 @@ function testSchema(schemaMap)
}; // End testSchema


// Go through a schema looking for attributes
// This is to help building a translation script
// Dump out the F_CODES with a particular attribute.
// If it is enumerzted, dump the values as well
var dumpValues = function (schema,aName)
{
console.log('---------------');

var enumList = {};

schema.getDbSchema().forEach(feature => {
console.log('F_CODE: ' + feature.fcode + ' Geom: ' + feature.geom + ' Desc: ' + feature.desc);

feature['columns'].forEach(attr => {
if (attr.name == aName)
{
console.log('F_CODE: ' + feature.fcode + ' Geom: ' + feature.geom + ' Desc: ' + feature.desc);
if (attr['type'] == 'enumeration')
{
attr['enumerations'].forEach(enValue => {
Expand All @@ -461,17 +480,13 @@ var dumpValues = function (schema,aName)
{
console.log(' name:' + aName + ' Type:' + attr['type']);
}
console.log('-----');
}
});
console.log('-----');
}); // End single schema

// If we have an enumerated list, dump out the consolidated version
for (var i in enumList) console.log(" ['XXX','" + i + "','YYY','" + enumList[i] + "'],X");
}; // End dumpValues



if (typeof exports !== 'undefined') {
exports.schemaFromFcode = schemaFromFcode;
exports.osmToOgr = osmToOgr;
Expand All @@ -482,5 +497,6 @@ if (typeof exports !== 'undefined') {
exports.testOSM = testOSM;
exports.testSchema = testSchema;
exports.dumpValues = dumpValues;
exports.dumpSchema = dumpSchema;
exports.getThing = getThing;
}