From 76a898fe8f344ea5325714a0f3cc7c78a5de0fa5 Mon Sep 17 00:00:00 2001 From: Jeffrey Warren Date: Fri, 8 Feb 2019 17:54:39 -0500 Subject: [PATCH] basic map unit tests (#334) * basic map unit tests * try to run entire map.run_export * parameter consolidation --- app/models/map.rb | 10 ++++---- test/unit/map_test.rb | 54 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/app/models/map.rb b/app/models/map.rb index 30267d817..1e7a0252d 100755 --- a/app/models/map.rb +++ b/app/models/map.rb @@ -228,7 +228,8 @@ def run_export(user,resolution) pxperm = 100/(resolution).to_f || self.average_scale # pixels per meter puts '> distorting warpables' - origin = self.distort_warpables(pxperm) + + origin = self.distort_warpables(pxperm, self.placed_warpables, self.latest_export) warpable_coords = origin.pop export = self.export @@ -279,19 +280,20 @@ def run_export(user,resolution) end # distort all warpables, returns upper left corner coords in x,y - def distort_warpables(scale) - export = self.latest_export + def distort_warpables(scale, warpables, export) + puts '> generating geotiffs of each warpable in GDAL' lowest_x=0 lowest_y=0 warpable_coords = [] - warpables = self.placed_warpables current = 0 warpables.each do |warpable| current += 1 + export.status = 'warping '+current.to_s+' of '+warpables.length.to_s puts 'warping '+current.to_s+' of '+warpables.length.to_s export.save + my_warpable_coords = warpable.generate_perspectival_distort(scale,self.slug) puts '- '+my_warpable_coords.to_s warpable_coords << my_warpable_coords diff --git a/test/unit/map_test.rb b/test/unit/map_test.rb index 93e791c37..b6bdfa090 100644 --- a/test/unit/map_test.rb +++ b/test/unit/map_test.rb @@ -3,9 +3,12 @@ class MapTest < ActiveSupport::TestCase test "basics" do + assert_not_nil Map.bbox(0,0,90,180) + assert_not_nil Map.authors + assert_not_nil Map.new_maps + map = Map.first assert_not_nil map.license_link - assert_not_nil map.grouped_images_histogram(10) assert_not_nil map.author assert_not_nil map.name assert_not_nil map.created_at @@ -20,6 +23,55 @@ class MapTest < ActiveSupport::TestCase assert_not_nil map.tags assert_not_nil map.comments assert_not_nil map.user + assert_not_nil map.private + assert_not_nil map.anonymous? + + assert_not_nil map.images_histogram + assert_not_nil map.grouped_images_histogram(10) + assert_not_nil map.nearby_maps(100) # in degrees lat/lon + end + + test "export functions" do + map = Map.first + assert_not_nil map.average_scale + assert_not_nil map.placed_warpables + assert_not_nil map.best_cm_per_pixel + assert_not_nil map.exporting? + assert_not_nil map.export + assert_not_nil map.latest_export + assert_not_nil map.nodes + assert_not_nil map.average_cm_per_pixel + + assert_not_nil map.run_export(users(:quentin), map.average_cm_per_pixel) + + # main issue will be that it creates and continuously updates an Export model. + # we could shift this to a polling model, either on the client side (eliminating the Export model) + # ... or some other way to make it possible to do many of these tasks without needing ActiveRecord + + # let's start at the bottom and factor this all out working upwards + + # refactor so that we pass in as much in parameters as possible, reducing in-model cross-references + + # creates an Export and sets initial values + # depends on: map.average_scale + # runs self.distort_warpables(pxperm) + # runs self.generate_composite_tiff(warpable_coords,origin) + # runs `identify` and assigns some values (height, width) to Export + # runs export.tms = true if self.generate_tiles + # runs export.zip = true if self.zip_tiles + # runs export.jpg = true if self.generate_jpg + # map.distort_warpables(scale) + # collects self.placed_warpables + # runs on each one: warpable.generate_perspectival_distort(scale,self.slug) + # map.generate_composite_tiff(coords,origin) + # collects self.placed_warpables + # runs gdal_warp on the output of each, flattening onto a single geotiff + # map.generate_tiles + # runs on composite tiff output: gdal2tiles = 'gdal2tiles.py -k -t "'+self.slug+'" -g "'+google_api_key+'" '+Rails.root.to_s+'/public/warps/'+self.slug+'/'+self.slug+'-geo.tif '+Rails.root.to_s+'/public/tms/'+self.slug+"/" + # map.zip_tiles + # map.generate_jpg + # runs convert on composite tiff + end test "tag basics" do