Improved www.ttss.krakow.pl
Jacek Kowalski
2019-05-04 ca42d38139f52d8edf6e0792b8cfb5b6404d9112
Normalize stop names (add space after period)
7 files modified
40 ■■■■■ changed files
common.js 4 ●●●● patch | view | raw | blame | history
index.html 4 ●●●● patch | view | raw | blame | history
index.js 4 ●●●● patch | view | raw | blame | history
map.html 4 ●●●● patch | view | raw | blame | history
map.js 10 ●●●● patch | view | raw | blame | history
stops/common.php 8 ●●●●● patch | view | raw | blame | history
stops/index.php 6 ●●●● patch | view | raw | blame | history
common.js
@@ -115,6 +115,10 @@
 * PARSING *
 ***********/
function normalizeName(string) {
    return string.replace('.', '. ').replace('  ', ' ');
}
function parseStatus(status) {
    switch(status.status) {
        case 'STOPPING':
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>
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);
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>
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);
        }
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'));
}
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,
        ];