From 3275b514d85710b001f658b4c531901a922ea33e Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 7 Aug 2014 19:25:10 +0100 Subject: Update to the new mfd-location format Also fix a query issue resulting in duplicate printers --- create-data.js | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'create-data.js') diff --git a/create-data.js b/create-data.js index fc956ec..efb95cf 100755 --- a/create-data.js +++ b/create-data.js @@ -13,19 +13,11 @@ S.extendPrototype(); var fs = require('fs'); var http = require("http"); var async = require("async"); -var yaml = require('js-yaml'); var config = require("./config.json"); var library_data = require("./resources/hartley-library-map-data/data.json"); -try { - var printers = yaml.safeLoad(fs.readFileSync('./resources/mfd-location/data.yaml', 'utf8')); -} catch (e) { - console.error(e); - return; -} - var validationByURI = {}; // prefix for the database tables @@ -1191,7 +1183,7 @@ PREFIX soton: \ PREFIX rdfs: \ PREFIX ns1: \ PREFIX rdf: \ -SELECT * WHERE {\ +SELECT DISTINCT * WHERE {\ ?mdf a ;\ rdfs:label ?label ;\ ?building .\ @@ -1213,6 +1205,7 @@ SELECT * WHERE {\ // For validation var openDataPrinterURIs = {} + var printersWithLocations = 0; async.map(data.results.bindings, function(result, callback) { if ('error-message' in result) { @@ -1242,13 +1235,23 @@ SELECT * WHERE {\ } }; - if (uri in printers) { - feature.geometry = { - type: "Point", - coordinates: printers[uri].coordinates - }; + var printers = require("./resources/mfd-location/data.json"); + + var printersByURI = {} + printers.features.forEach(function(printer) { + printersByURI[printer.properties.uri] = printer; + }); + + if (uri in printersByURI) { + printer = printersByURI[uri]; - feature.properties.level = parseInt(printers[uri].level, 10); + feature.geometry = printer.geometry; + + feature.properties.level = printer.properties.level; + + printersWithLocations += 1; + } else { + console.error("error printer " + uri + " is not known"); } if (building in buildings) { @@ -1273,16 +1276,6 @@ SELECT * WHERE {\ callback(null, feature); }, function(err, results) { - var printersWithLocations = 0; - - Object.keys(printers).forEach(function(uri) { - if (!(uri in openDataPrinterURIs)) { - console.error("error printer " + uri + " is not known"); - } else { - printersWithLocations++; - } - }); - console.info("finished processing printers (" + printersWithLocations + "/" + Object.keys(openDataPrinterURIs).length + ")"); async.filter(results, -- cgit v1.2.3