123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <!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
- $time_start = microtime(true);
- $def_colors = array (
- "r" => "red",
- "g" => "green",
- "b" => "blue",
- "y" => "yellow",
- );
- $fody_url = "https://osm.fit.vutbr.cz/fody/";
- require_once dirname(__FILE__).'/../db_conf.php';
- $db = pg_connect("host=".SERVER." dbname=".DATABASE." user=".USERNAME." password=".PASSWORD);
- function print_table($class, $no_osm, $error, $guidepostID, $photoIDs, $osmColors, $photoColors){ //{{{
- global $def_colors;
- global $fody_url;
- ksort($osmColors);
- ksort($photoColors);
- echo '<tr class="'.$class.'">'."\n";
- echo '<td class="'.$no_osm.'"><a href="http://openstreetmap.org/node/'.$guidepostID.'">'.$guidepostID.'</a></td>';// guidepost ID
- echo '<td>';
- foreach ($osmColors as $value => $v) { // colors in OSM
- echo '<span class="'.$def_colors[$value].'"></span>';
- }
- echo '</td>';
- echo '<td>';
- foreach ($photoIDs as $photoId) {
- echo '<a href="'.$fody_url.'?id='.$photoId.'">'.$photoId.'</a>, '; // photo ID
- }
- echo '</td>';
- echo '<td>';
- foreach ($photoColors as $value => $v) {
- echo '<span class="'.$def_colors[$value].'"></span>';
- }
- echo $error;
- echo '</td>';
- echo '</tr>'."\n";
- } //}}}
- 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(!isset($_GET['p']) || !in_array($_GET['p'],array ('all', 'wrong_osm', 'check_ok', 'check_nok', 'missing_data', 'corrupted'))){
- $_GET['p'] = 'all';
- }
- ?>
- <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í</a> rozpoznané informace ze snímku</li>
- <li><a href="./?p=corrupted">problematické</a> snímky ve Fody</li>
- </ul>
-
- <?php
- $db_time=trim(file_get_contents("../last_update.txt"));
- $detect_time = date ("d.m.Y H:i.", filemtime('csv/update.log'));
- echo "<p>Data from $db_time, photos analyze last run $detect_time</p>\n";
- $query="SELECT nodeid, ref, ST_AsText(geom) AS geom, img FROM hicheck.analyze_cache WHERE img != '' AND tags LIKE '%information:guidepost'";
- $res = pg_query($query);
- printf("<p>Using %d entries from analyze run</p>\n", pg_num_rows($res));
-
- $count_ok = 0;
- $count_bad = 0;
- $count_cor = 0;
- $count_dif = 0;
- if ($_GET['p'] != 'corrupted') {
- echo '<table>';
- echo ' <tr>';
- echo ' <th width="7%">node ID</th><th width="8%">colors OSM</th><th width="12%">images</th><th width="10%">colors photos</th>';
- echo ' </tr>';
- }
- while ($row = pg_fetch_object($res)) {
- //find colors from OSM relations
- $query="SELECT r.tags AS tags
- FROM public.relations AS r JOIN public.relation_members AS r_m ON r.id = r_m.relation_id
- WHERE r_m.member_id = $row->nodeid;";
- $res2 = pg_query($db, $query);
- $rel = array();
- while ($data = pg_fetch_object($res2)) {
- $rel[] = json_decode('{' . str_replace('"=>"', '":"', $data->tags) . '}', true);
- }
- pg_free_result($res2);
- $colors_osm = array();
- foreach ($rel as $relation) {
- if(isset($relation['kct_red'] )){ $colors_osm['r'] = 1; }
- if(isset($relation['kct_green'] )){ $colors_osm['g'] = 1; }
- if(isset($relation['kct_blue'] )){ $colors_osm['b'] = 1; }
- if(isset($relation['kct_yellow'])){ $colors_osm['y'] = 1; }
- }
-
- //find colors from photo detection
- $error = "";
- $colors_csv = array();
- $photo_IDs = array();
- foreach(explode('|', $row->img) as $i){
- if($i == "") continue;
- list($imgid,$dist,$imgref) = explode(':', $i);
- $photo_IDs[] = $imgid;
- if(is_readable('csv/'.$imgid.'.csv')){
- $csv = array_map('str_getcsv', file('csv/'.$imgid.'.csv'));
- if($csv[1][1]) $colors_csv['r'] = 1;
- if($csv[1][2]) $colors_csv['g'] = 1;
- if($csv[1][3]) $colors_csv['b'] = 1;
- if($csv[1][4]) $colors_csv['y'] = 1;
- }else{
- $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$imgid;
- $photo = json_decode(file_get_contents($url));
- if($photo->features[0]->properties->enabled != 't')
- $error .= ", ".$imgid.".csv not found";
- }
- }
-
- //proces gathered data from OSM and photos
- 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'){
- $count_dif++;
- $class = 'different';
- if($_GET['p'] == 'all' or $_GET['p'] == 'missing_data'){
- print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
- }
- }
-
- if($class == 'ok'){
- $count_ok++;
- if($_GET['p'] == 'all' or $_GET['p'] == 'check_ok'){
- print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
- }
- }
-
- if($class == 'bad'){
- $count_bad++;
- if($_GET['p'] == 'all' or $_GET['p'] == 'check_nok'){
- print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
- }
- }
-
- if($no_osm == 'cor'){
- $count_cor++;
- if($_GET['p'] == 'all' or $_GET['p'] == 'wrong_osm'){
- print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
- }
- }
- }
-
- if ($_GET['p'] != 'corrupted') echo ' </table>'."\n";
- printf("<p>Guideposts: <span class=\"ok\">%d</span> OK, <span class=\"bad\">%d</span> different colors, <span class=\"cor\">%d</span> no color in OSM, %d OSM color OK and no photo</p>\n", $count_ok, $count_bad, $count_cor, $count_dif);
- pg_free_result($res);
- pg_close($db);
- if($_GET['p'] == 'all' or $_GET['p'] == 'corrupted'){
- //show blurry photos
- $img_ids = explode("\n", trim(file_get_contents('csv/images-blurry.txt')));
- echo '<p>Blurry photos ('. count($img_ids)." total, show enabled only): ";
- foreach($img_ids as $i){
- $id = basename($i, '.jpg');
- $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$id;
- $photo = json_decode(file_get_contents($url));
- if($photo->features[0]->properties->enabled == 't' && strpos($photo->features[0]->properties->tags, 'necitelne') === false){
- echo '<a href="'.$fody_url.'?id='.$id.'">'.$id."</a>, \n";
- }
- }
- echo "</p>\n";
- //show small photos
- $img_ids = explode("\n", trim(file_get_contents('csv/images-small.txt')));
- echo '<p>Too small photos ('. count($img_ids)." total, show enabled only): ";
- foreach($img_ids as $i){
- $id = basename($i, '.jpg');
- $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$id;
- $photo = json_decode(file_get_contents($url));
- if($photo->features[0]->properties->enabled == 't'){
- echo '<a href="'.$fody_url.'?id='.$id.'">'.$id."</a>, \n";
- }
- }
- echo "</p>\n";
-
- //show corrupted photos
- $img_ids = explode("\n", trim(file_get_contents('csv/images-corrupted.txt')));
- echo '<p>Corrupted photos ('. count($img_ids)." total, show enabled only): ";
- foreach($img_ids as $i){
- $id = basename($i, '.jpg');
- $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$id;
- $photo = json_decode(file_get_contents($url));
- if($photo->features[0]->properties->enabled == 't'){
- echo '<a href="'.$fody_url.'?id='.$id.'">'.$id."</a>, \n";
- }
- }
- echo "</p>\n";
- }
- $time_end = microtime(true);
- printf("<p>Total execution time: %.04fs</p>\n",($time_end - $time_start));
- ?>
- </body>
- </html>
|