def test_logger(self): outputFolder = self.dir + '%digiroad%test%data%outputFolder'.replace("%", os.sep) Logger.configureLogger(outputFolder=outputFolder, prefix="prefix") Logger.getInstance().info("MY LOG")
def test_givenAMultiPointGeojson_then_returnGeojsonFeatures(self): inputStartCoordinatesURL = self.dir + '%digiroad%test%data%geojson%reititinTestPoints.geojson'.replace( "%", os.sep) inputEndCoordinatesURL = self.dir + '%digiroad%test%data%geojson%reititinTestPoints.geojson'.replace( "%", os.sep) # inputStartCoordinatesURL = self.dir + '%digiroad%test%data%geojson%not-fast-points.geojson'.replace("%", os.sep) # inputEndCoordinatesURL = self.dir + '%digiroad%test%data%geojson%not-fast-points2.geojson'.replace("%", os.sep) # outputFolderFeaturesURL = self.dir + '%digiroad%test%data%outputFolderNotFast3%'.replace("%", os.sep) outputFolderFeaturesURL = self.dir + '%digiroad%test%data%outputFolder%'.replace( "%", os.sep) # distanceCostAttribute = CostAttributes.BICYCLE_FAST_TIME distanceCostAttribute = { # "DISTANCE": CostAttributes.DISTANCE, "BICYCLE_FAST_TIME": CostAttributes.BICYCLE_FAST_TIME # "BICYCLE_SLOW_TIME": CostAttributes.BICYCLE_SLOW_TIME, } prefix = CostAttributes.BICYCLE_FAST_TIME + "_log." Logger.configureLogger(outputFolderFeaturesURL, prefix) self.metroAccessDigiroad.calculateTotalTimeTravel( startCoordinatesGeojsonFilename=inputStartCoordinatesURL, endCoordinatesGeojsonFilename=inputEndCoordinatesURL, outputFolderPath=outputFolderFeaturesURL, costAttribute=distanceCostAttribute) inputCoordinatesGeojson = self.fileActions.readJson( inputStartCoordinatesURL) for key in distanceCostAttribute: if not outputFolderFeaturesURL.endswith(os.sep): geomsOutputFolderFeaturesURL = outputFolderFeaturesURL + os.sep + \ "geoms" + os.sep + getEnglishMeaning(distanceCostAttribute[key]) + os.sep else: geomsOutputFolderFeaturesURL = outputFolderFeaturesURL + "geoms" + os.sep + getEnglishMeaning( distanceCostAttribute[key]) + os.sep outputFileList = self.readOutputFolderFiles( geomsOutputFolderFeaturesURL) totalCombinatory = len(inputCoordinatesGeojson["features"]) * len( inputCoordinatesGeojson["features"]) - len( inputCoordinatesGeojson["features"]) self.assertEqual(totalCombinatory, len(outputFileList))
def test_givenAPointGeojson_then_returnGeojsonFeatures(self): inputCoordinatesURL = self.dir + '%digiroad%test%data%geojson%onePoint.geojson'.replace( "%", os.sep) input2CoordinatesURL = self.dir + '%digiroad%test%data%geojson%anotherPoint.geojson'.replace( "%", os.sep) outputFolderFeaturesURL = self.dir + '%digiroad%test%data%outputFolderBicycle%'.replace( "%", os.sep) expectedResultPath = self.dir + '%digiroad%test%data%geojson%shortpathBetweenTwoPoints.geojson'.replace( "%", os.sep) # distanceCostAttribute = CostAttributes.BICYCLE_FAST_TIME distanceCostAttribute = { "DISTANCE": CostAttributes.DISTANCE, "BICYCLE_FAST_TIME": CostAttributes.BICYCLE_FAST_TIME, "BICYCLE_SLOW_TIME": CostAttributes.BICYCLE_SLOW_TIME, } prefix = os.path.basename( inputCoordinatesURL) + "_" + os.path.basename( input2CoordinatesURL) + "_log." Logger.configureLogger(outputFolderFeaturesURL, prefix) self.metroAccessDigiroad.calculateTotalTimeTravel( startCoordinatesGeojsonFilename=inputCoordinatesURL, endCoordinatesGeojsonFilename=input2CoordinatesURL, outputFolderPath=outputFolderFeaturesURL, costAttribute=distanceCostAttribute) inputCoordinatesGeojson = self.fileActions.readJson( inputCoordinatesURL) expectedResult = self.fileActions.readJson(expectedResultPath) if not outputFolderFeaturesURL.endswith(os.sep): geomsOutputFolderFeaturesURL = outputFolderFeaturesURL + os.sep + \ "geoms" + os.sep + \ getEnglishMeaning(CostAttributes.BICYCLE_FAST_TIME) + os.sep else: geomsOutputFolderFeaturesURL = outputFolderFeaturesURL + "geoms" + os.sep + getEnglishMeaning( CostAttributes.BICYCLE_FAST_TIME) + os.sep outputFileList = self.readOutputFolderFiles( geomsOutputFolderFeaturesURL) outputFilename = outputFileList[0] outputFilePath = outputFolderFeaturesURL + os.sep + "geoms" + os.sep + getEnglishMeaning( CostAttributes.BICYCLE_FAST_TIME) + os.sep + outputFilename outputResult = self.fileActions.readJson(outputFilePath) for feature in expectedResult["features"]: if "id" in feature: del feature["id"] maxSeq = 0 for feature in outputResult["features"]: maxSeq = max(feature["properties"]["seq"], maxSeq) if "id" in feature: del feature["id"] self.assertEqual(expectedResult, outputResult)
def executeSpatialDataAnalysis(outputFolder, startPointsGeojsonFilename, endPointsGeojsonFilename, starterApplication, impedanceList, impedances, allImpedanceAttribute, summaryOnly, routesOnly, prefix): Logger.configureLogger(outputFolder, prefix) config = getConfigurationProperties() # wfsServiceProvider = WFSServiceProvider( # wfs_url=config["wfs_url"], # nearestVertexTypeName=config["nearestVertexTypeName"], # nearestCarRoutingVertexTypeName=config["nearestCarRoutingVertexTypeName"], # shortestPathTypeName=config["shortestPathTypeName"], # outputFormat=config["outputFormat"] # ) if not allImpedanceAttribute: for impedance in impedanceList: if routesOnly: starterApplication.calculateTotalTimeTravel( startCoordinatesGeojsonFilename=startPointsGeojsonFilename, endCoordinatesGeojsonFilename=endPointsGeojsonFilename, outputFolderPath=outputFolder, costAttribute=impedance) if summaryOnly: starterApplication.createDetailedSummary( folderPath=outputFolder, costAttribute=impedance, outputFilename=prefix + "metroAccessDigiroadSummary.geojson") elif summaryOnly: starterApplication.createGeneralSummary( startCoordinatesGeojsonFilename=startPointsGeojsonFilename, endCoordinatesGeojsonFilename=endPointsGeojsonFilename, costAttribute=impedance, outputFolderPath=outputFolder, outputFilename=prefix + "dijsktraCostMetroAccessDigiroadSummary") if allImpedanceAttribute: if routesOnly: starterApplication.calculateTotalTimeTravel( startCoordinatesGeojsonFilename=startPointsGeojsonFilename, endCoordinatesGeojsonFilename=endPointsGeojsonFilename, outputFolderPath=outputFolder, costAttribute=impedances) for key in impedances: if routesOnly and summaryOnly: starterApplication.createDetailedSummary( folderPath=outputFolder, costAttribute=impedances[key], outputFilename=prefix + "metroAccessDigiroadSummary.geojson") elif summaryOnly: starterApplication.createGeneralSummary( startCoordinatesGeojsonFilename=startPointsGeojsonFilename, endCoordinatesGeojsonFilename=endPointsGeojsonFilename, costAttribute=impedances[key], outputFolderPath=outputFolder, outputFilename=prefix + "dijsktraCostMetroAccessDigiroadSummary")