show_image_old_working.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <!doctype html>
  2. <head>
  3. <title>Dimension Extraction</title>
  4. <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
  5. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  6. <script src="https://unpkg.com/pdfjs-dist@latest/build/pdf.min.js"></script>
  7. </head>
  8. <body>
  9. <!--<div class="split left">-->
  10. <div class="container">
  11. <div class="column column-one">
  12. <h1>Drawing</h1>
  13. <p> <a href="http://localhost:5000/"> Upload another drawing </a> </p>
  14. <table style='text-align:left'>
  15. {% for link in links %}
  16. <tr>
  17. {% set l=links[link] %}
  18. <td style='text-align:left'> <a href=" {{ url_for('static', filename=l) }}" > {{ link }} </a> </td>
  19. </tr>
  20. {% endfor %}
  21. {% for iso in isos_names %}
  22. <tr>
  23. <td style='text-align:left'> {{ iso }}</td>
  24. </tr>
  25. {% endfor %}
  26. </table>
  27. {% if filename %}
  28. <div class="images">
  29. <img id="drawing" src="{{ url_for('send_file', filename=filename) }}">
  30. </div>
  31. {% else %}
  32. <h1>no image for whatever reason</h1>
  33. {% endif %}
  34. </div>
  35. <!--<div class="split middle">-->
  36. <div class="column column-two" id="measurements">
  37. <h1>Extracted Measurements</h1>
  38. <font size="3" face="Courier New" >
  39. <form>
  40. <table>
  41. <tr>
  42. <td style="text-align:center"><h3>Key Value</h3></td>
  43. <td style="text-align:center"><h3>Target Value</h3></td>
  44. <td style="text-align:center"><h3>Actual Value</h3></td>
  45. <td style="text-align:center"><h3>Relevant Isos</h3></td>
  46. </tr>
  47. {{ text | safe}}
  48. <!-- {% for key in dims %}
  49. <td><h4> {{key}} </h4></td>
  50. {% for d in dims[key] %}
  51. <tr>
  52. <td style="text-align:center"><input type="checkbox" name="relevant[]" value="checked"></td>
  53. <td style="text-align:center"> {{ d }}</td>
  54. <td style="text-align:center"><input type="text" name="{{ d }}" size="10"></td>
  55. </tr>
  56. {% endfor %}
  57. {% endfor %}-->
  58. </table>
  59. </form>
  60. </font>
  61. <!-- </div> <div id="result">Result {{ number }}</div>-->
  62. <!--<div class="split right">
  63. <div class="column column-three">
  64. <h1>Additional Infos</h1>
  65. <table>
  66. {% for link in links %}
  67. <tr>
  68. {% set l=links[link] %}
  69. <td> <h3> <a href=" {{ url_for('static', filename=l) }}" > {{ link }} </a> </h3> </td>
  70. </tr>
  71. {% endfor %}
  72. </table>
  73. </div>
  74. </div>
  75. <script>
  76. function set_redis(key, value) {
  77. $.ajax({
  78. type: "POST",
  79. url: "/redis/set/" + key,
  80. data: JSON.stringify({ value: value }),
  81. dataType: "json",
  82. contentType: "json",
  83. success: function(data)
  84. {
  85. (data.GET);
  86. }
  87. });
  88. }
  89. function get_redis(key) {
  90. $.ajax({
  91. type: "GET",
  92. url: "redis/get/" + key,
  93. data: "format=json",
  94. dataType: "text",
  95. success: function(data)
  96. {
  97. $("#result").text(data.GET);
  98. }
  99. });
  100. function split_string(string) {
  101. var string = str.split(" ",2);
  102. return string;
  103. });
  104. </script>
  105. <script>
  106. $(document).ready(function(){
  107. $("input[type=number]").on("change keyup input", function(){
  108. var array_value = [];
  109. array_value[0] = $(this).attr('name');
  110. array_value[1] = $(this).val();
  111. var key = 'last' + "_" +'{{og_filename}}';
  112. //console.log({{ dim }});
  113. set_redis(key, array_value);
  114. });
  115. $("input[type=checkbox]").change(function(){
  116. // Print entered value in a div box
  117. $("#result").text($(this).attr('name'));
  118. var key1 = 'last' + "_" +'{{og_filename}}';
  119. var array_value1 = [];
  120. if ($(this).is(':checked')) {
  121. console.log($(this).attr('name') + ' is now checked');
  122. array_value1[0] = 'relevant.' + $(this).attr('name');
  123. array_value1[1] = true;
  124. } else {
  125. console.log($(this).attr('name') + ' is now unchecked');
  126. array_value1[0] = $(this).attr('name');
  127. array_value1[1] = false;
  128. }
  129. set_redis(key1, array_value1);
  130. });
  131. $("input[type=number]").focus(function(){
  132. // highlight values, does not work so far
  133. var number = $(this).attr('name');
  134. var coords = $(this).attr('data-coords');
  135. highlight_areas(coords, "red");
  136. var detail = $(this).attr('data-details');
  137. console.log(detail, "green");
  138. highlight_details(detail, "green");
  139. });
  140. $("input[type=number]").blur(function(){
  141. $("div").removeClass("red");
  142. $("div").removeClass("green");
  143. });
  144. function highlight_areas(coords, color){
  145. let w = {{w}}
  146. let h = {{h}}
  147. let pos = $("#drawing").position();
  148. let drawing_x = pos.left;
  149. let drawing_y = pos.top;
  150. let array_coords = coords.split(",");
  151. let coords_x = parseFloat(array_coords[0]);
  152. let coords_xmax = parseFloat(array_coords[2]);
  153. let coords_y = parseFloat(array_coords[1]);
  154. let coords_ymax = parseFloat(array_coords[3]);
  155. let coords_width = (coords_xmax - coords_x);
  156. let coords_height = (coords_ymax - coords_y);
  157. let width = $("#drawing").width();
  158. let height = $("#drawing").height();
  159. let rel_width = coords_width/h*width*1.4;
  160. let rel_height = coords_height/w*height*1.4;
  161. let x = width*(coords_x*height/width/w);
  162. let y = height*(coords_y*width/height/h);
  163. console.log(w, h, rel_width, rel_height,x,y);
  164. let $point1 = jQuery("<div class="+color+"/>").css({top: (drawing_y + y -5) + 'px', left: (drawing_x + x-5) + 'px', width: rel_width , height: rel_height});
  165. $(".images").append($point1);
  166. };
  167. function highlight_details(coords, color){
  168. let w = {{w}}
  169. let h = {{h}}
  170. let pos = $("#drawing").position();
  171. let drawing_x = pos.left;
  172. let drawing_y = pos.top;
  173. let array_coords = coords.split(",");
  174. let coords_x = parseFloat(array_coords[0]);
  175. let coords_y = parseFloat(array_coords[1]);
  176. let width_div = (parseFloat(array_coords[2]) - parseFloat(array_coords[0]));
  177. let height_div = (parseFloat(array_coords[3]) - parseFloat(array_coords[1]));
  178. let width = $("#drawing").width();
  179. let rel_width = width_div/h*width;
  180. let height = $("#drawing").height();
  181. let rel_height = height*height_div/w;
  182. let x = width*(coords_x*height/width/w);
  183. let y= height*(coords_y*width/height/h);
  184. console.log(rel_width, rel_height);
  185. if (array_coords[3] > 10000) {
  186. rel_height = height - y;
  187. }
  188. let $point = jQuery("<div class="+color+"/>").css({top: (drawing_y + y) + 'px', left: (drawing_x + x) + 'px', width: (rel_width) + 'px', height: (rel_height) + 'px'});
  189. $(".images").append($point);
  190. };
  191. });
  192. </script>
  193. </body>