From ca42d38139f52d8edf6e0792b8cfb5b6404d9112 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 04 May 2019 12:23:02 +0000
Subject: [PATCH] Normalize stop names (add space after period)

---
 stops/common.php |    8 ++++++++
 index.js         |    4 ++--
 map.js           |   10 +++++-----
 common.js        |    4 ++++
 stops/index.php  |    6 +++---
 index.html       |    4 ++--
 map.html         |    4 ++--
 7 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/common.js b/common.js
index b434bf1..0bf165e 100644
--- a/common.js
+++ b/common.js
@@ -115,6 +115,10 @@
  * PARSING *
  ***********/
 
+function normalizeName(string) {
+	return string.replace('.', '. ').replace('  ', ' ');
+}
+
 function parseStatus(status) {
 	switch(status.status) {
 		case 'STOPPING':
diff --git a/index.html b/index.html
index b9c9fa1..1929c1e 100644
--- a/index.html
+++ b/index.html
@@ -135,7 +135,7 @@
 		</div>
 		<script src="https://polyfill.io/v3/polyfill.min.js?features=Promise,XMLHttpRequest"></script>
 		<script type="text/javascript" src="lang_pl.js?v8" id="lang_script"></script>
-		<script type="text/javascript" src="common.js?v8"></script>
-		<script type="text/javascript" src="index.js?v7"></script>
+		<script type="text/javascript" src="common.js?v9"></script>
+		<script type="text/javascript" src="index.js?v8"></script>
 	</body>
 </html>
diff --git a/index.js b/index.js
index 28e4a4c..924e93c 100644
--- a/index.js
+++ b/index.js
@@ -115,8 +115,8 @@
 			+ '&mode=departure'
 	).done(function(data) {
 		setText(times_stop_type, lang.types['s' + prefix]);
-		setText(times_stop_name, data.stopName);
-		setText(page_title, lang.page_title_stop_name.replace('$stop', data.stopName));
+		setText(times_stop_name, normalizeName(data.stopName));
+		setText(page_title, lang.page_title_stop_name.replace('$stop', normalizeName(data.stopName)));
 		deleteChildren(times_alerts);
 		deleteChildren(times_table);
 		//deleteChildren(times_lines);
diff --git a/map.html b/map.html
index cfe2a8d..b5f5aa5 100644
--- a/map.html
+++ b/map.html
@@ -24,7 +24,7 @@
 <script src="https://polyfill.io/v3/polyfill.min.js?features=Array.prototype.forEach,Array.prototype.includes,Array.prototype.map,Element.prototype.classList,Promise,String.prototype.startsWith,XMLHttpRequest,requestAnimationFrame"></script>
 <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v5.3.0/build/ol.js" integrity="sha384-iQkGyyH4ioz3m+maM3s9MX1Oq67mACa4B9Z3ovUv3Sv37LJ96fx3WnZfLoiC3Wfl" crossorigin="anonymous"></script>
 <script tyle="text/javascript" src="lang_pl.js?v8" id="lang_script"></script>
-<script tyle="text/javascript" src="common.js?v8"></script>
-<script tyle="text/javascript" src="map.js?v20"></script>
+<script tyle="text/javascript" src="common.js?v9"></script>
+<script tyle="text/javascript" src="map.js?v21"></script>
 </body>
 </html>
diff --git a/map.js b/map.js
index ff7d3a3..c6f8bdc 100644
--- a/map.js
+++ b/map.js
@@ -278,7 +278,7 @@
 			
 			var vehicle_name_space = vehicle.name.indexOf(' ');
 			vehicle.line = vehicle.name.substr(0, vehicle_name_space);
-			vehicle.direction = vehicle.name.substr(vehicle_name_space+1);
+			vehicle.direction = normalizeName(vehicle.name.substr(vehicle_name_space+1));
 			if(special_directions[vehicle.direction]) {
 				vehicle.line = special_directions[vehicle.direction];
 			}
@@ -401,7 +401,7 @@
 		for(var i = 0, il = all_departures.length; i < il; i++) {
 			tr = document.createElement('tr');
 			addCellWithText(tr, all_departures[i].actualTime || all_departures[i].plannedTime);
-			addCellWithText(tr, all_departures[i].stop_seq_num + '. ' + all_departures[i].stop.name);
+			addCellWithText(tr, all_departures[i].stop_seq_num + '. ' + normalizeName(all_departures[i].stop.name));
 			
 			if(i >= data.old.length) {
 				stopsToMark.push('s' + ttss_type + all_departures[i].stop.id);
@@ -446,7 +446,7 @@
 		for(var i = 0, il = all_departures.length; i < il; i++) {
 			tr = document.createElement('tr');
 			addCellWithText(tr, all_departures[i].patternText);
-			dir_cell = addCellWithText(tr, all_departures[i].direction);
+			dir_cell = addCellWithText(tr, normalizeName(all_departures[i].direction));
 			vehicle = parseVehicle(all_departures[i].vehicleId);
 			dir_cell.appendChild(displayVehicle(vehicle));
 			status = parseStatus(all_departures[i]);
@@ -489,7 +489,7 @@
 	var div = document.createElement('div');
 	
 	var typeName;
-	var name = feature.get('name');
+	var name = normalizeName(feature.get('name'));
 	var additional;
 	var table = document.createElement('table');
 	var thead = document.createElement('thead');
@@ -654,7 +654,7 @@
 			
 			addElementWithText(a, 'span', typeName).className = 'small';
 			a.appendChild(document.createTextNode(' '));
-			addElementWithText(a, 'span', feature.get('name'));
+			addElementWithText(a, 'span', normalizeName(feature.get('name')));
 			
 			div.appendChild(p);
 		}
diff --git a/stops/common.php b/stops/common.php
index 54fdfdd..8cf4642 100644
--- a/stops/common.php
+++ b/stops/common.php
@@ -15,3 +15,11 @@
 	
 	return array_values($words);
 }
+
+function normalize_name($string) {
+	return strtr(strtr($string, ['.' => '. ']), ['  ' => ' ']);
+}
+
+function normalize_name_cmp($string) {
+	return normalize_name(mb_strtolower($string, 'UTF-8'));
+}
diff --git a/stops/index.php b/stops/index.php
index 5795afa..2b7658b 100644
--- a/stops/index.php
+++ b/stops/index.php
@@ -48,11 +48,11 @@
 	
 	// Build a structure for the UI
 	$stop_list = [];
-	$query_lower = mb_strtolower($_GET['query'], 'UTF-8');
+	$query_lower = normalize_name_cmp($_GET['query']);
 	foreach($ids as $id) {
 		similar_text(
 			$query_lower,
-			mb_strtolower($stops[$id], 'UTF-8'),
+			normalize_name_cmp($stops[$id]),
 			$percent
 		);
 		// -5 due to UTF-8
@@ -61,7 +61,7 @@
 		}
 		$stop_list[] = [
 			'id' => $id,
-			'name' => $stops[$id],
+			'name' => normalize_name($stops[$id]),
 			'type' => 'stop',
 			'relevance' => $percent,
 		];

--
Gitblit v1.9.1