index.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Porovnání rozcestníků: OSM vs foto</title>
  6. </head>
  7. <style>
  8. td {
  9. border: 1px solid black;
  10. }
  11. .ok { background-color:#b0ffa0; }
  12. .bad { background-color:#ffa090; }
  13. .cor { background-color:#ff5010; }
  14. .red{
  15. width:10px;
  16. height:10px;
  17. background:red;
  18. float: left;
  19. margin-left: 2px;
  20. border: 1px solid black;
  21. }
  22. .green{
  23. width:10px;
  24. height:10px;
  25. background:green;
  26. float: left;
  27. margin-left: 2px;
  28. border: 1px solid black;
  29. }
  30. .blue{
  31. width:10px;
  32. height:10px;
  33. background:blue;
  34. float: left;
  35. margin-left: 2px;
  36. border: 1px solid black;
  37. }
  38. .yellow{
  39. width:10px;
  40. height:10px;
  41. background:yellow;
  42. float: left;
  43. margin-left: 2px;
  44. border: 1px solid black;
  45. }
  46. table {
  47. border-collapse: collapse;
  48. font-size: 9pt;
  49. }
  50. </style>
  51. <body>
  52. <?php
  53. $time_start = microtime(true);
  54. $def_colors = array (
  55. "r" => "red",
  56. "g" => "green",
  57. "b" => "blue",
  58. "y" => "yellow",
  59. );
  60. $fody_url = "https://osm.fit.vutbr.cz/fody/";
  61. require_once dirname(__FILE__).'/../db_conf.php';
  62. $db = pg_connect("host=".SERVER." dbname=".DATABASE." user=".USERNAME." password=".PASSWORD);
  63. function print_table($class, $no_osm, $error, $guidepostID, $photoIDs, $osmColors, $photoColors){ //{{{
  64. global $def_colors;
  65. global $fody_url;
  66. ksort($osmColors);
  67. ksort($photoColors);
  68. echo '<tr class="'.$class.'">'."\n";
  69. echo '<td class="'.$no_osm.'"><a href="http://openstreetmap.org/node/'.$guidepostID.'">'.$guidepostID.'</a></td>';// guidepost ID
  70. echo '<td>';
  71. foreach ($osmColors as $value => $v) { // colors in OSM
  72. echo '<span class="'.$def_colors[$value].'"></span>';
  73. }
  74. echo '</td>';
  75. echo '<td>';
  76. foreach ($photoIDs as $photoId) {
  77. echo '<a href="'.$fody_url.'?id='.$photoId.'">'.$photoId.'</a>, '; // photo ID
  78. }
  79. echo '</td>';
  80. echo '<td>';
  81. foreach ($photoColors as $value => $v) {
  82. echo '<span class="'.$def_colors[$value].'"></span>';
  83. }
  84. echo $error;
  85. echo '</td>';
  86. echo '</tr>'."\n";
  87. } //}}}
  88. function load_html($url){ //{{{
  89. # Use the Curl extension to load a page
  90. $ch = curl_init();
  91. $timeout = 55;
  92. curl_setopt($ch, CURLOPT_URL, $url);
  93. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  94. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  95. $html = curl_exec($ch);
  96. curl_close($ch);
  97. $dom = new DOMDocument;
  98. @$dom->loadHTML($html);
  99. return $dom;
  100. } //}}}
  101. if(!isset($_GET['p']) || !in_array($_GET['p'],array ('all', 'wrong_osm', 'check_ok', 'check_nok', 'missing_data', 'corrupted'))){
  102. $_GET['p'] = 'all';
  103. }
  104. ?>
  105. <h2>Porovnání rozcestníků: OSM vs foto</h2>
  106. <p>Můžete vypsat:</p>
  107. <ul>
  108. <li><a href="./?p=all">všechny rozcestníky</a> které mají fotku</li>
  109. <li><a href="./?p=wrong_osm">chybně data OSM</a></li>
  110. <li><a href="./?p=check_ok">souhlasí</a> údaje v OSM DB a rozpoznané na snímku</li>
  111. <li><a href="./?p=check_nok">NEsouhlasí</a> údaje v OSM DB a rozpoznané na snímku</li>
  112. <li><a href="./?p=missing_data">chybí</a> rozpoznané informace ze snímku</li>
  113. <li><a href="./?p=corrupted">problematické</a> snímky ve Fody</li>
  114. </ul>
  115. <?php
  116. $db_time=trim(file_get_contents("../last_update.txt"));
  117. $detect_time = date ("d.m.Y H:i.", filemtime('csv/update.log'));
  118. echo "<p>Data from $db_time, photos analyze last run $detect_time</p>\n";
  119. $query="SELECT nodeid, ref, ST_AsText(geom) AS geom, img FROM hicheck.analyze_cache WHERE img != '' AND tags LIKE '%information:guidepost'";
  120. $res = pg_query($query);
  121. printf("<p>Using %d entries from analyze run</p>\n", pg_num_rows($res));
  122. $count_ok = 0;
  123. $count_bad = 0;
  124. $count_cor = 0;
  125. $count_dif = 0;
  126. if ($_GET['p'] != 'corrupted') {
  127. echo '<table>';
  128. echo ' <tr>';
  129. echo ' <th width="7%">node ID</th><th width="8%">colors OSM</th><th width="12%">images</th><th width="10%">colors photos</th>';
  130. echo ' </tr>';
  131. }
  132. while ($row = pg_fetch_object($res)) {
  133. //find colors from OSM relations
  134. $query="SELECT r.tags AS tags
  135. FROM public.relations AS r JOIN public.relation_members AS r_m ON r.id = r_m.relation_id
  136. WHERE r_m.member_id = $row->nodeid;";
  137. $res2 = pg_query($db, $query);
  138. $rel = array();
  139. while ($data = pg_fetch_object($res2)) {
  140. $rel[] = json_decode('{' . str_replace('"=>"', '":"', $data->tags) . '}', true);
  141. }
  142. pg_free_result($res2);
  143. $colors_osm = array();
  144. foreach ($rel as $relation) {
  145. if(isset($relation['kct_red'] )){ $colors_osm['r'] = 1; }
  146. if(isset($relation['kct_green'] )){ $colors_osm['g'] = 1; }
  147. if(isset($relation['kct_blue'] )){ $colors_osm['b'] = 1; }
  148. if(isset($relation['kct_yellow'])){ $colors_osm['y'] = 1; }
  149. }
  150. //find colors from photo detection
  151. $error = "";
  152. $colors_csv = array();
  153. $photo_IDs = array();
  154. foreach(explode('|', $row->img) as $i){
  155. if($i == "") continue;
  156. list($imgid,$dist,$imgref) = explode(':', $i);
  157. $photo_IDs[] = $imgid;
  158. if(is_readable('csv/'.$imgid.'.csv')){
  159. $csv = array_map('str_getcsv', file('csv/'.$imgid.'.csv'));
  160. if($csv[1][1]) $colors_csv['r'] = 1;
  161. if($csv[1][2]) $colors_csv['g'] = 1;
  162. if($csv[1][3]) $colors_csv['b'] = 1;
  163. if($csv[1][4]) $colors_csv['y'] = 1;
  164. }else{
  165. $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$imgid;
  166. $photo = json_decode(file_get_contents($url));
  167. if($photo->features[0]->properties->enabled != 't')
  168. $error .= ", ".$imgid.".csv not found";
  169. }
  170. }
  171. //proces gathered data from OSM and photos
  172. if ($colors_csv == $colors_osm){
  173. $class = 'ok';
  174. }else{
  175. $class = 'bad';
  176. }
  177. $no_osm = 'different';
  178. if(!$colors_osm){
  179. $no_osm = 'cor';
  180. $class = 'different';
  181. }
  182. if(strlen($error) > 0 and $no_osm != 'cor'){
  183. $count_dif++;
  184. $class = 'different';
  185. if($_GET['p'] == 'all' or $_GET['p'] == 'missing_data'){
  186. print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
  187. }
  188. }
  189. if($class == 'ok'){
  190. $count_ok++;
  191. if($_GET['p'] == 'all' or $_GET['p'] == 'check_ok'){
  192. print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
  193. }
  194. }
  195. if($class == 'bad'){
  196. $count_bad++;
  197. if($_GET['p'] == 'all' or $_GET['p'] == 'check_nok'){
  198. print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
  199. }
  200. }
  201. if($no_osm == 'cor'){
  202. $count_cor++;
  203. if($_GET['p'] == 'all' or $_GET['p'] == 'wrong_osm'){
  204. print_table($class, $no_osm, $error, $row->nodeid, $photo_IDs, $colors_osm, $colors_csv);
  205. }
  206. }
  207. }
  208. if ($_GET['p'] != 'corrupted') echo ' </table>'."\n";
  209. 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);
  210. pg_free_result($res);
  211. pg_close($db);
  212. if($_GET['p'] == 'all' or $_GET['p'] == 'corrupted'){
  213. //show blurry photos
  214. $img_ids = explode("\n", trim(file_get_contents('csv/images-blurry.txt')));
  215. echo '<p>Blurry photos ('. count($img_ids)." total, show enabled only): ";
  216. foreach($img_ids as $i){
  217. $id = basename($i, '.jpg');
  218. $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$id;
  219. $photo = json_decode(file_get_contents($url));
  220. if($photo->features[0]->properties->enabled == 't' && strpos($photo->features[0]->properties->tags, 'necitelne') === false){
  221. echo '<a href="'.$fody_url.'?id='.$id.'">'.$id."</a>, \n";
  222. }
  223. }
  224. echo "</p>\n";
  225. //show small photos
  226. $img_ids = explode("\n", trim(file_get_contents('csv/images-small.txt')));
  227. echo '<p>Too small photos ('. count($img_ids)." total, show enabled only): ";
  228. foreach($img_ids as $i){
  229. $id = basename($i, '.jpg');
  230. $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$id;
  231. $photo = json_decode(file_get_contents($url));
  232. if($photo->features[0]->properties->enabled == 't'){
  233. echo '<a href="'.$fody_url.'?id='.$id.'">'.$id."</a>, \n";
  234. }
  235. }
  236. echo "</p>\n";
  237. //show corrupted photos
  238. $img_ids = explode("\n", trim(file_get_contents('csv/images-corrupted.txt')));
  239. echo '<p>Corrupted photos ('. count($img_ids)." total, show enabled only): ";
  240. foreach($img_ids as $i){
  241. $id = basename($i, '.jpg');
  242. $url = 'https://osm.fit.vutbr.cz/fody/api/show?disabled&id='.$id;
  243. $photo = json_decode(file_get_contents($url));
  244. if($photo->features[0]->properties->enabled == 't'){
  245. echo '<a href="'.$fody_url.'?id='.$id.'">'.$id."</a>, \n";
  246. }
  247. }
  248. echo "</p>\n";
  249. }
  250. $time_end = microtime(true);
  251. printf("<p>Total execution time: %.04fs</p>\n",($time_end - $time_start));
  252. ?>
  253. </body>
  254. </html>