From fbf7e61a16cb31cda4c73da685a845a3fbc13d0b Mon Sep 17 00:00:00 2001 From: glax Date: Mon, 29 Jul 2024 05:08:31 +0200 Subject: [PATCH] Node map more log --- OSM_Regions/RegionLoader.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/OSM_Regions/RegionLoader.cs b/OSM_Regions/RegionLoader.cs index b34a554..a06a01b 100644 --- a/OSM_Regions/RegionLoader.cs +++ b/OSM_Regions/RegionLoader.cs @@ -12,7 +12,7 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo internal readonly string ImportFolderPath = Path.Join(importFolderPath ?? Environment.CurrentDirectory, regionSize.ToString(CultureInfo.InvariantCulture)); private const string NodesMapRegionFileName = "nodes.map"; private const string WayMapRegionFileName = "ways.map"; - private Dictionary? nodeRegionDict = null; + private Dictionary? _nodeRegionDict; public Graph.Graph? LoadRegionFromRegionId(long regionId) { @@ -82,9 +82,11 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo public Graph.Graph? LoadRegionFromNodeId(ulong nodeId) { logger?.LogDebug($"Loading Region for Node {nodeId}"); - if (nodeRegionDict is null) + if (_nodeRegionDict is null || _nodeRegionDict.Count < 1) { - nodeRegionDict = new(); + DateTime start = DateTime.Now; + logger?.LogInformation($"Loading Node map from {Path.Join(ImportFolderPath, NodesMapRegionFileName)}"); + _nodeRegionDict = new(); using StreamReader nodesMapFileStream = new(Path.Join(ImportFolderPath, NodesMapRegionFileName), Encoding.ASCII); while (!nodesMapFileStream.EndOfStream) { @@ -93,18 +95,21 @@ public class RegionLoader(float regionSize, string? importFolderPath = null, ILo continue; try { - ulong id = ulong.Parse(line.Split('-')[0]); - long regionId = long.Parse(line.Split('-')[1]); - nodeRegionDict.TryAdd(id, regionId); + string[] split = line.Split('-'); + ulong id = ulong.Parse(split[0]); + long regionId = long.Parse(split[1]); + logger?.LogTrace($"Adding node {id} {regionId}"); + _nodeRegionDict.TryAdd(id, regionId); } catch (Exception e) { logger?.LogError(e, "Error parsing Node-line."); } } + logger?.LogInformation($"Loading Nodemap took {DateTime.Now - start:mm\\:ss\\.fff}"); } - if (!nodeRegionDict.TryGetValue(nodeId, out long rId)) + if (_nodeRegionDict.TryGetValue(nodeId, out long rId)) return LoadRegionFromRegionId(rId); logger?.LogWarning($"Could not find Node {nodeId}"); return null;