Skip to content

Commit

Permalink
basic map unit tests (#334)
Browse files Browse the repository at this point in the history
* basic map unit tests

* try to run entire map.run_export

* parameter consolidation
  • Loading branch information
jywarren authored Feb 8, 2019
1 parent ddf5892 commit 76a898f
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
10 changes: 6 additions & 4 deletions app/models/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
54 changes: 53 additions & 1 deletion test/unit/map_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 76a898f

Please sign in to comment.