Browse Source

add autodetection of GP and its colors by Premek Hnilica

tkas 2 years ago
parent
commit
05e3aed981
4 changed files with 263 additions and 1 deletions
  1. 1 1
      Makefile
  2. 6 0
      detect/Makefile
  3. 255 0
      detect/index.php
  4. 1 0
      index.html

+ 1 - 1
Makefile

@@ -13,4 +13,4 @@ install:
 	make -C tables
 	make -C map
 	make -C gp
-
+	make -C detect

+ 6 - 0
detect/Makefile

@@ -0,0 +1,6 @@
+WEB?=/var/www/html/OsmHiCheck/detect
+
+PHP_FILES=index.php
+
+install: 
+	rsync -vap $(PHP_FILES) $(WEB)/

+ 255 - 0
detect/index.php

@@ -0,0 +1,255 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="UTF-8">
+        <title>Porovnání rozcestníků: OSM vs foto</title>
+    </head>
+    <style>
+td { 
+  border: 1px solid black;
+}
+.ok { background-color:#b0ffa0; }
+.bad { background-color:#ffa090; }
+.cor { background-color:#ff5010; }
+.red{
+    width:10px;
+    height:10px;
+    background:red;
+    float: left;
+    margin-left: 2px;
+    border: 1px solid black;
+}
+.green{
+    width:10px;
+    height:10px;
+    background:green;
+    float: left;
+    margin-left: 2px;
+    border: 1px solid black;
+}
+.blue{
+    width:10px;
+    height:10px;
+    background:blue;
+    float: left;
+    margin-left: 2px;
+    border: 1px solid black;
+}
+.yellow{
+    width:10px;
+    height:10px;
+    background:yellow;
+    float: left;
+    margin-left: 2px;
+    border: 1px solid black;
+}
+table { 
+  border-collapse: collapse;
+  font-size: 9pt;
+}
+</style>
+    <body>
+<?php
+
+function getColorsForGuidepost() {
+    return "red";
+}
+
+function print_table($class, $no_osm, $error, $guidepostID, $photoIDs, $osmColors, $photoColors, $d_colors){
+    echo '<tr class="'.$class.'">';
+    echo '<td class="'.$no_osm.'"><a href="http://openstreetmap.org/node/'.$guidepostID.'">'.$guidepostID.'</a></td>';// guidepost ID
+    echo '<td>';
+    foreach ($osmColors as $value) { // colors in OSM
+        echo '<span class="'.$d_colors[$value].'"></span>';
+    }
+    echo '</td>';
+    echo '<td>';
+//    var_dump($photoIDs);
+    foreach ($photoIDs as $photoId) {
+        echo '<a href="http://api.openstreetmap.cz/table/id/'.$photoId.'">'.$photoId.'</a> '; // photo ID
+    }
+    echo '</td>';
+    echo '<td>';
+    foreach ($photoColors as $value) {
+        echo '<span class="'.$d_colors[$value].'"></span>';
+    }
+    echo $error;
+    echo '</td>';
+    echo '</tr>';
+}
+
+function load_html($url){
+    # Use the Curl extension to load a page
+    $ch = curl_init();
+    $timeout = 55;
+    curl_setopt($ch, CURLOPT_URL, $url);
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
+    $html = curl_exec($ch);
+    curl_close($ch);
+    $dom = new DOMDocument;
+    @$dom->loadHTML($html);
+    return $dom;
+}
+
+if(!in_array($_GET['p'],['all', 'wrong_osm', 'check_ok', 'check_nok', 'missing_data'])){
+    $_GET['p'] = 'all';
+}
+
+if(!in_array($_GET['orig'],['all', 'cor', 'bad', 'ok'])){
+    $_GET['orig'] = 'cor';
+}
+
+$def_colors = [
+    "r" => "red",
+    "g" => "green",
+    "b" => "blue",
+    "y" => "yellow",
+];
+
+$dom_fit = load_html('https://osm.fit.vutbr.cz/OsmHiCheck/gp/?'.$_GET['orig']);
+# parse the table
+$tables = $dom_fit->getElementsByTagName('table');
+$rows = $tables->item(0)->getElementsByTagName('tr');
+
+// parse csv file
+$csv = array_map('str_getcsv', file('out_11tis.csv'));
+$photos = [];
+foreach ($csv as $value) {
+    $photos[$value[0]] = ['r'=>intval($value[1]), 'g'=>intval($value[2]),'b'=>intval($value[3]),'y'=>intval($value[4])];
+}
+
+?>
+        <h2>Porovnání rozcestníků: OSM vs foto</h2>
+        <p>Můžete vypsat:</p>
+<ul>
+<li><a href="./?p=all">všechny rozcestníky</a> které mají fotku</li>
+<li><a href="./?p=wrong_osm">chybně data OSM</a></li>
+<li><a href="./?p=check_ok">souhlasí</a> údaje v OSM DB a rozpoznané na snímku</li>
+<li><a href="./?p=check_nok">NEsouhlasí</a> údaje v OSM DB a rozpoznané na snímku</li>
+<li><a href="./?p=missing_data">chybí rozpoznané informace ze snímku</a></li>
+</ul>
+        
+        <table>
+            <tr>
+                <th width="7%">Guidepost ID</th><th width="8%">Colors in OSM</th><th width="12%">Photo ID</th><th width="10%">Colors from photos</th>
+            </tr>
+            <?php
+            
+            $first_line = True; # for skipping first row of original table (headers)
+            foreach ($rows as $row) {
+                if ($first_line){
+                    # skip first row
+                    $first_line = False;
+                    continue;
+                }else{
+                    $cols = $row->getElementsByTagName('td'); // get each guidepost
+//                    echo '<tr><td><a href="http://openstreetmap.org/node/'.$cols->item(0)->nodeValue.'">'.$cols->item(0)->nodeValue.'</a></td>'; // guidepost id
+//                    echo"<td>";
+                    $xml = simplexml_load_file('http://www.openstreetmap.org/api/0.6/node/'.$cols->item(0)->nodeValue.'/relations');
+                    
+                    $colors_osm = [];
+                    foreach ($xml as $relation) {
+                        foreach ($relation->tag as $tag) {
+                            if($tag['k'] == 'kct_red'){
+//                                echo 'red<br>';
+                                $colors_osm[] = 'r';
+                            }
+                            if($tag['k'] == 'kct_green'){
+//                                echo 'green<br>';
+                                $colors_osm[] = 'g';
+                            }
+                            if($tag['k'] == 'kct_blue'){
+//                                echo 'blue<br>';
+                                $colors_osm[] = 'b';
+                            }
+                            if($tag['k'] == 'kct_yellow'){
+//                                echo 'yellow<br>';
+                                $colors_osm[] = 'y';
+                            }
+                        }
+                    }
+//                    echo "</td><td>";
+                    $photoLinks = $cols->item(3)->getElementsByTagName('a');
+                    $colors = ['r'=>0, 'g'=>0, 'b'=>0, 'y'=>0];
+                    $error  = "";
+                    $colors_csv = [];
+                    $photo_IDs = [];
+                    foreach ($photoLinks as $photoId) { # loop for every photo
+                        $filename = $photoId->nodeValue;
+                        if(file_exists('csv/'.$filename.'.csv')){
+                            $photo_IDs[] = $filename;
+                            $csv = array_map('str_getcsv', file('csv/'.$filename.'.csv'));
+//                            echo $csv[1][0].'<br>';
+                            $colors['r'] += $csv[1][1];
+                            $colors['g'] += $csv[1][2];
+                            $colors['b'] += $csv[1][3];
+                            $colors['y'] += $csv[1][4];
+                        }else{
+                          $error .= $filename." not found<br>";
+                        }
+
+                        //echo var_dump($photos[$filename]);
+                        
+//                        echo "<br>";
+                    }
+//                  echo "</td><td>";
+                    $result_of_comp = True;
+                    if(strlen($error) == 0){
+                        foreach ($colors as $key => $value) {
+    //                        echo $key." : ".$value."<br>";
+                            if($value != 0){
+                                $colors_csv[] = $key;
+                            }
+                        }
+                    }  else {
+//                    echo $error;
+                    }
+
+//              PRINT OUT WHOLE ROW:
+//                var_dump($photo_IDs);
+
+                if ($colors_csv == $colors_osm){
+                    $class = 'ok';
+                    
+                }else{
+                    $class = 'bad';
+                }
+                
+                $no_osm = 'different';
+                if(!$colors_osm){
+                    $no_osm = 'cor';
+                    $class = 'different';
+                }
+                if(strlen($error) > 0 and $no_osm != 'cor'){
+                    $class = 'different';
+                    if($_GET['p'] == 'all' or $_GET['p'] == 'missing_data'){
+                        print_table($class, $no_osm, $error, $cols->item(0)->nodeValue, $photo_IDs, $colors_osm, $colors_csv, $def_colors);
+                    }
+                }
+                
+                if($class == 'ok'){
+                    if($_GET['p'] == 'all' or $_GET['p'] == 'check_ok'){
+                        print_table($class, $no_osm, $error, $cols->item(0)->nodeValue, $photo_IDs, $colors_osm, $colors_csv, $def_colors);
+                    }
+                }
+                
+                if($class == 'bad'){
+                    if($_GET['p'] == 'all' or $_GET['p'] == 'check_nok'){
+                        print_table($class, $no_osm, $error, $cols->item(0)->nodeValue, $photo_IDs, $colors_osm, $colors_csv, $def_colors);
+                    }
+                }
+                
+                if($no_osm == 'cor'){
+                    if($_GET['p'] == 'all' or $_GET['p'] == 'wrong_osm'){
+                        print_table($class, $no_osm, $error, $cols->item(0)->nodeValue, $photo_IDs, $colors_osm, $colors_csv, $def_colors);
+                    }
+                }
+                
+
+                }    
+            }
+            ?>
+        </table>
+    </body>
+</html>

+ 1 - 0
index.html

@@ -14,6 +14,7 @@
             <a href="map"><div class="image image-map"><div>Mapa</div></div></a>
             <a href="tables"><div class="image image-none"><div>Tabulky</div></div></a>
             <a href="gp"><div class="image image-none"><div>Rozcestníky</div></div></a>
+            <a href="detect"><div class="image image-none"><div>Detekce z fotek</div></div></a>
         </div>
     </div>
 </body>