From 6ea0485f777656208e5064882ec22cfaed127a69 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 16 Jun 2014 19:33:40 +0100 Subject: Refactor the indoor stuff The queries to lookup University room information do not really work... --- create-data.js | 419 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 241 insertions(+), 178 deletions(-) diff --git a/create-data.js b/create-data.js index efe21b0..7f062a0 100755 --- a/create-data.js +++ b/create-data.js @@ -266,220 +266,283 @@ function getBuildingImages(buildings, callback) { // buildingParts -function createBuildingParts(buildings, callback) { - console.info("creating buildingParts collection"); - +function processBuildingParts(buildingParts, callback) { + var buildingPartsByURI = {}; var workstations = {}; - async.parallel([getBuildingParts, getBuildingRelations], - function(err, results) { - var buildingParts = results[0]; - var buildingRelations = results[1]; + async.each(buildingParts, function(part, callback) { + if (part.properties.buildingpart === "room") { + if ("uri" in part.properties) { + buildingPartsByURI[part.properties.uri] = part; - var buildingPartsByURI = {}; + var expectedRef = part.properties.uri.split("/").slice(-1)[0].split("-")[1]; - async.parallel([ - function(callback) { - async.each(buildingParts, function(part, callback) { - if (part.properties.buildingpart === "room") { + if ("ref" in part.properties) { + if (part.properties.ref !== expectedRef) { + console.warn("Unexpected ref \"" + part.properties.ref + "\" for room " + part.properties.uri); + } + } else { + console.warn("Missing ref \"" + expectedRef + "\" for room " + part.properties.uri); + } - if ("ref" in part.properties && !("uri" in part.properties)) { - console.warn("room missing URI " + JSON.stringify(part.properties.center)); - } + async.parallel([ + function(callback) { + findRoomFeatures(part, callback); + }, + function(callback) { + findRoomContents(part, workstations, callback); + }, + function(callback) { + findRoomImages(part, callback); + }], + callback); + } else { + console.warn("room has no URI " + JSON.stringify(part.properties.center)); + callback(); + } + } else { + callback(); + } + }, function(err) { + // list such that it fits within async's pattern + callback(err, [buildingPartsByURI, workstations]); + }); +} - if ("uri" in part.properties) { - buildingPartsByURI[part.properties.uri] = part; +function getPartToLevelMap(buildingRelations, callback) { + var levelRelations = []; - var expectedRef = part.properties.uri.split("/").slice(-1)[0].split("-")[1]; + // Process level relations + async.each(buildingRelations, function(buildingRelation, callback) { + getLevelRelations(buildingRelation, function(err, newLevelRelations) { + levelRelations.push.apply(levelRelations, newLevelRelations); + callback(); + }); + }, function(err) { - if ("ref" in part.properties) { - if (part.properties.ref !== expectedRef) { - console.warn("Unexpected ref \"" + part.properties.ref + "\" for room " + part.properties.uri); - } - } else { - console.warn("Missing ref \"" + expectedRef + "\" for room " + part.properties.uri); - } + osmIDToLevels = {}; - async.parallel([ - function(callback) { - findRoomFeatures(part, callback); - }, - function(callback) { - findRoomContents(part, workstations, callback); - }, - function(callback) { - findRoomImages(part, callback); - }], - callback); - } else { - console.warn("room has no URI " + JSON.stringify(part.properties.center)); - callback(); - } - } else { - callback(); - } - }, callback); - }, - function(callback) { - var levelRelations = [] + async.each(levelRelations, function(level, callback) { + getBuildingPartMemberRefs(level, function(err, refs) { + for (var i=0; i +PREFIX ns1: +PREFIX rdfs: +PREFIX spacerel: +PREFIX soton: +SELECT ?room ?type ?label ?building WHERE { + ?room a ns1:Room . + OPTIONAL { ?room spacerel:within ?building } . + OPTIONAL { ?room rdfs:label ?label } . + OPTIONAL { ?room rdf:type ?type } +} + */ + + // This seems to not pick up much... + var query = "PREFIX rdf: \ + PREFIX ns1: \ + PREFIX rdfs: \ + PREFIX spacerel: \ + PREFIX soton: \ + SELECT * WHERE {\ + { ?room a ns1:Room ;\ + rdf:type ?type ;\ + rdfs:label ?label ;\ + spacerel:within ?building .\ + } UNION {\ + ?room a soton:SyllabusLocation ;\ + rdf:type ?type ;\ + rdfs:label ?label ;\ + spacerel:within ?building .\ + }\ + }"; - if (!(ref in osmIDToLevels)) { - osmIDToLevels[ref] = []; - } + sparqlQuery(query, function(err, data) { + if (err) { + console.error("Query " + query); + console.error(err); + } - osmIDToLevels[refs[i]].push(parseInt(level.tags.level, 10)); - } - callback(); - }); - }, function(err) { - // Assign levels to parts + console.log("Got building parts sparql query back"); - for (var i=0; i