Module: CartoCSSHelper

Defined in:
lib/cartocss_helper.rb,
lib/cartocss_helper.rb,
lib/cartocss_helper/git.rb,
lib/data/testing_locations.rb,
lib/cartocss_helper/heuristic.rb,
lib/cartocss_helper/validator.rb,
lib/cartocss_helper/tag_lister.rb,
lib/cartocss_helper/image_generator.rb,
lib/cartocss_helper/notes_downloader.rb,
lib/cartocss_helper/renderer_handler.rb,
lib/cartocss_helper/data_file_handling.rb,
lib/cartocss_helper/overpass_downloader.rb,
lib/cartocss_helper/overpass_query_generator.rb,
lib/cartocss_helper/style_specific/style_specific.rb,
lib/cartocss_helper/style_specific/default_osm_style.rb,
lib/cartocss_helper/visualise_changes_diff_from_images.rb,
lib/cartocss_helper/visualise_changes_image_generation.rb

Defined Under Namespace

Modules: Configuration, Git, Heuristic, StyleDataForDefaultOSM, Validator Classes: DataFileGenerator, DataFileLoader, FullSetOfComparedImages, ImageForComparison, Info, NotesDownloader, OverpassDownloader, OverpassQueryGenerator, PairOfComparedImages, RendererFailedToGenerateFile, RendererHandler, Scene, StyleSpecificData, TagRenderingStatus, VisualDiff

Class Method Summary collapse

Class Method Details

.add_common_secondary_tags(tags) ⇒ Object



54
55
56
57
# File 'lib/cartocss_helper.rb', line 54

def self.add_common_secondary_tags(tags)
  added_tags = { 'name' => 'ÉÉÉÉÉÉ ÉÉÉÉÉÉ', 'ref' => '1', 'ele' => '8000', 'operator' => 'ÉÉ ÉÉ ÉÉ operator', 'brand' => 'ÉÉ ÉÉ ÉÉ brand' }
  return tags.merge(added_tags)
end

.download_remote_file(url, clear_cache = false) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/cartocss_helper.rb', line 106

def self.download_remote_file(url, clear_cache = false)
  filename = get_place_of_storage_of_resource_under_url(url)
  if clear_cache
    File.delete(filename) if File.exist?(filename)
  end
  unless File.exist?(filename)
    url = url
    timeout = 600
    downloader = GenericCachedDownloader.new(timeout: timeout)
    return downloader.get_specified_resource(url, filename)
  end
end

.get_latitude_longitude_from_url(url) ⇒ Object



79
80
81
82
83
84
# File 'lib/cartocss_helper.rb', line 79

def self.get_latitude_longitude_from_url(url)
  lat_lon = url.scan(/[\/=]((-|)\d+(\.\d+))/)
  latitude = lat_lon[0][0].to_f
  longitude = lat_lon[1][0].to_f
  return latitude, longitude
end

.get_list_of_testing_locationsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/data/testing_locations.rb', line 4

def self.get_list_of_testing_locations
  return [
    [50.1, 19.9], # Krakow
    [53.2, -1.8], # rural uk
    [36.1, 140.7], # Japan
    [54.8, 31.7], # Russia
    [21.3, 39.5], # Mecca
    [41.4, 44.5], # Georgia
    [51.5, -0.1], # London
    # TODO: solve problems with response too big to store in memory
    # [52.09, 5.11], #Utrecht

    # http://overpass-turbo.eu/s/ar4
    # capital locations
    [-41.2887639, 174.7772239],
    [37.9841493, 23.7279843],
    [46.0498650, 14.5068921],
    [55.6867243, 12.5700724],
    [28.6138967, 77.2159562],
    [33.6945756, 73.0643744],
    [48.2083537, 16.3725042],
    # [48.8565056, 2.3521334], TODO: solve problems with rest-client crashing and blabbing about negative integers
    [46.9482713, 7.4514512],
    [45.4210328, -75.6900219],
    [59.9132694, 10.7391112],
    [33.3024248, 44.3787992],
    [40.4167047, -3.7035825],
    [-35.2819367, 149.1288940],
    [34.5197058, 69.1624302],
    [39.9059093, 116.3913489],
    [-25.7250000, 28.1847222],
    [39.9220794, 32.8537580],
    [59.3251172, 18.0710935],
    [35.6861720, 51.4223519],
    [50.4501071, 30.5240501],
    [53.9023386, 27.5619023],
    [23.1379911, -82.3658562],
    [56.9493977, 24.1051846],
    [-4.3217055, 15.3125974],
    [54.6843135, 25.2853984],
    [55.1598408, 61.4025547],
    [42.8766343, 74.6070116],
    [41.3123363, 69.2787079],
    [38.5762757, 68.7863940],
    [47.9184676, 106.9177016],
    [51.1282789, 71.4305478],
    [13.5248339, 2.1098226],
    [-8.8271656, 13.2436665],
    [12.6500083, -8.0000014],
    [36.8001077, 10.1847938],
    [6.3280343, -10.7977882],
    [4.3909085, 18.5505422],
    [-15.4166967, 28.2813812],
    [12.3681481, -1.5270853],
    [12.1191543, 15.0502758],
    [14.6930042, -17.4470260],
    [8.4790017, -13.2680158],
    [9.5171253, -13.6999235],
    [0.3900022, 9.4540009],
    [9.0107934, 38.7612525],
    [5.5600141, -0.2057437],
    [-25.9662133, 32.5674498],
    [11.5936649, 43.1472403],
    [-1.2832533, 36.8172449],
    [-18.9100122, 47.5255809],
    [15.5933247, 32.5356502],
    [14.9160169, -23.5096132],
    [62.0120000, -6.7680000],
    [31.7774287, 35.2247239],
    [59.4372155, 24.7453688],
    [-29.3100536, 27.4782219],
    [-24.6585857, 25.9084905],
    [39.0196396, 125.7525841],
    [36.5658725, 53.0585690],
    [-33.9289049, 18.4172485],
    [-22.5744184, 17.0791233],
    [-15.7934036, -47.8823172],
    [2.0427779, 45.3385636],
    [26.2235041, 50.5822436],
    [-33.4377968, -70.6504451],
    [12.5268736, -70.0356845],
    [12.1091242, -68.9316546],
    [12.1471741, -68.2740783],
    [6.9342870, 79.8532704],
    [49.6112768, 6.1297990],
    [18.4652988, -66.1166657],
    [17.9712148, -76.7928128],
    [-0.2201687, -78.5120913],
    [42.5069391, 1.5212467],
    [-12.0458271, -77.0304845],
    [-1.9508511, 30.0615075],
    [44.8178787, 20.4568089],
    [-3.3638125, 29.3675028],
    [27.7087963, 85.3202438],
    [41.8933439, 12.4830718],
    [21.0292095, 105.8524700],
    [-34.6128690, -58.4459789],
    [47.4983815, 19.0404707],
    [-6.1791181, 35.7468174],
    [43.4930746, 43.6193570],
    [44.4361390, 26.1027436],
    [4.8472017, 31.5951655],
    [-17.7414972, 168.3150163],
    [25.0783456, -77.3383331],
    [17.9640988, 102.6133707],
    [42.4415238, 19.2621081],
    [47.0122737, 28.8605936],
    [40.1776121, 44.5125849],
    [38.8949549, -77.0366456],
    [41.6509502, 41.6360085],
    [41.9960424, 21.4316707],
    [12.1461244, -86.2737170],
    [17.2960919, -62.7223010],
    [9.9325612, -84.0795739],
    [13.6977587, -89.1930100],
    [14.5906216, 120.9799696],
    [23.5997857, 58.5451305],
    [-9.4797487, 147.1503589],
    [15.2984622, -61.3875049],
    [52.5170365, 13.3888599],
    [50.2796448, 57.2124606],
    [-20.1637281, 57.5045331],
    [-26.3257447, 31.1446630],
    [39.5089040, 54.3631062],
    [12.0535331, -61.7518050],
    [13.1561653, -61.2248777],
    [14.0095719, -60.9903195],
    [13.1018264, -59.6188480],
    [18.0794011, -15.9780393],
    [13.4553495, -16.5756457],
    [-25.2960638, -57.6311446],
    [11.8613244, -15.5830554],
    [15.3421010, 44.2005197],
    [24.4747961, 54.3705762],
    [-8.5536809, 125.5784093],
    [15.3389974, 38.9326725],
    [35.6823815, 139.7530053],
    [18.0250713, -63.0483073],
    [38.7130574, -9.1380056],
    [-21.2074736, -159.7708145],
    [52.3710088, 4.9001115],
    [-7.7441461, 113.2158401],
    [30.0488185, 31.2436663],
    [48.4814020, 135.0769400],
    [18.3411365, -64.9327890],
    [43.9363996, 12.4466991],
    [5.8216198, -55.1771974],
    [17.2502830, -88.7694263],
    [-17.8317726, 31.0456859],
    [18.5473270, -72.3395928],
    [33.8959203, 35.4784300],
    [3.7528278, 8.7800610],
    [6.8025766, -58.1628612],
    [0.3389242, 6.7313031],
    [-34.9059039, -56.1913569],
    [21.4607723, -71.1399956],
    [34.0223602, -6.8390357],
    [14.0931919, -87.2012631],
    [-19.0478620, -65.2596023],
    [18.4801972, -69.9421110],
    [24.6319692, 46.7150648],
    [19.7540045, 96.1344976],
    [6.8091068, -5.2732628],
    [3.8689867, 11.5213344],
    [-11.6931255, 43.2543044],
    [7.0909924, 171.3816354],
    [-13.8343691, -171.7692793],
    [41.9034912, 12.4528349],
    [17.1184569, -61.8448509],
    [52.2319237, 21.0067265],
    [-4.2694407, 15.2712256],
    [-19.0534159, -169.9191992],
    [14.6417889, -90.5132239],
    [17.1393977, -62.6216154],
    [48.1535383, 17.1096711],
    [1.2904527, 103.8520380],
    [29.3797091, 47.9735629],
    [11.5682710, 104.9224426],
    [-8.5211767, 179.1976747],
    [4.5980478, -74.0760867],
    [16.7053047, -62.2130447],
    [1.3497964, 173.0277185],
    [6.9207440, 158.1627143],
    [7.4966382, 134.6349089],
    [0.3177137, 32.5813539],
    [19.2869856, -81.3717001],
    [-9.4312971, 159.9552773],
    [-2.2100307, 113.9267408],
    [64.1750290, -51.7355386],
    [-21.1343401, -175.2018085],
    [33.5130695, 36.3095814],
    [25.0375167, 121.5637000],
    [8.9500000, 38.7666700],
    [8.9707433, -79.5344539],
    [60.1666277, 24.9435079],
    [27.4730932, 89.6296788],
    [35.8987546, 14.5134889],
    [45.8131545, 15.9770298],
    [50.0874401, 14.4212556],
    [41.6934350, 44.8014979],
    [13.7529438, 100.4941219],
    [50.8465565, 4.3516970],
    [31.9515694, 35.9239625],
    [6.4990718, 2.6253361],
    [25.2856329, 51.5264162],
    [55.7516335, 37.6187042],
    [4.8895453, 114.9417574],
    [32.8966720, 13.1777923],
    [42.6977211, 23.3225964],
    [43.7311966, 7.4196400],
    [37.9396678, 58.3874263],
    [11.1852893, -60.7350240],
    [41.3279457, 19.8185323],
    [3.1570976, 101.7009528],
    [35.1739302, 33.3647260],
    [37.5666791, 126.9782914],
    [47.1392862, 9.5227962],
    [-14.2753717, -170.7048530],
    [15.1759138, 145.7432916],
    [18.2108070, -63.0535045],
    [26.3544056, -9.5741765],
    [43.8515421, 18.3886246],
    [-2.9888297, 104.7568570],
    [64.1459810, -21.9422367],
    [40.3754289, 49.8328549],
    [6.1258594, 1.2248504],
    [54.1497740, -4.4779021],
    [-18.1415884, 178.4421662],
    [46.8516039, 29.6349435],
    [38.3716205, 26.1342054],
    [49.1855551, -2.1098279],
    [10.6572142, -61.5180297],
    [-1.6141280, 103.5796708],
    [42.6636827, 21.1639418],
    [-13.9734560, 33.7878122],
    [43.7311424, 7.4197576],
    [6.9031663, 79.9091644],
    [-8.5202604, 179.1974823],
    [4.1779879, 73.5107387],
    [53.3497645, -6.2602732],
  ]
end

.get_maxn_for_nth_locationObject



46
47
48
# File 'lib/cartocss_helper.rb', line 46

def self.get_maxn_for_nth_location
  return get_list_of_testing_locations.length - 1
end

.get_nth_location(n) ⇒ Object



50
51
52
# File 'lib/cartocss_helper.rb', line 50

def self.get_nth_location(n)
  return get_list_of_testing_locations[n]
end

.get_place_of_storage_of_resource_under_url(url) ⇒ Object



102
103
104
# File 'lib/cartocss_helper.rb', line 102

def self.get_place_of_storage_of_resource_under_url(url)
  return CartoCSSHelper::Configuration.get_path_to_folder_for_overpass_cache + '.manual.cache' + FileHelper.make_string_usable_as_filename(url)
end

.probe(tags, new_branch, old_branch = 'master', zlevels = Configuration.get_min_z..Configuration.get_max_z, types = ['node', 'closed_way', 'way'], test_on_water = false) ⇒ Object



72
73
74
75
76
77
# File 'lib/cartocss_helper.rb', line 72

def self.probe(tags, new_branch, old_branch = 'master', zlevels = Configuration.get_min_z..Configuration.get_max_z, types = ['node', 'closed_way', 'way'], test_on_water = false)
  syn_tags = add_common_secondary_tags(tags)
  types.each do |type|
    CartoCSSHelper::VisualDiff.visualise_on_synthethic_data(syn_tags, type, test_on_water, zlevels, new_branch, old_branch)
  end
end

.test(tags, new_branch, old_branch = 'master', zlevels = Configuration.get_min_z..Configuration.get_max_z, types = ['node', 'closed_way', 'way'], test_on_water = false) ⇒ Object



66
67
68
69
70
# File 'lib/cartocss_helper.rb', line 66

def self.test(tags, new_branch, old_branch = 'master', zlevels = Configuration.get_min_z..Configuration.get_max_z, types = ['node', 'closed_way', 'way'], test_on_water = false)
  puts "processing #{VisualDiff.tag_dict_to_string(tags)}"
  test_tag_on_sythetic_data(tags, new_branch, old_branch, zlevels, types, test_on_water)
  test_tag_on_real_data(tags, new_branch, old_branch, zlevels, types)
end

.test_tag_on_real_data(tags, new_branch, old_branch, zlevels, types = ['node', 'closed_way', 'way'], min = 4, skip = 0) ⇒ Object



22
23
24
25
26
# File 'lib/cartocss_helper.rb', line 22

def self.test_tag_on_real_data(tags, new_branch, old_branch, zlevels, types = ['node', 'closed_way', 'way'], min = 4, skip = 0)
  types.each do |type|
    test_tag_on_real_data_for_this_type(tags, new_branch, old_branch, zlevels, type, min, skip)
  end
end

.test_tag_on_real_data_for_this_type(tags, new_branch, old_branch, zlevels, type, min = 4, skip = 0) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cartocss_helper.rb', line 28

def self.test_tag_on_real_data_for_this_type(tags, new_branch, old_branch, zlevels, type, min = 4, skip = 0)
  type = type[0] if type.is_a?(Array)
  generated = 0

  n = 0
  max_n = CartoCSSHelper.get_maxn_for_nth_location
  max_n -= skip
  skip_string = ''
  skip_string = " (#{skip} locations skipped)" if skip > 0
  while generated < min
    location = CartoCSSHelper.get_nth_location(n + skip)
    generated += 1 if CartoCSSHelper::VisualDiff.visualise_on_overpass_data(tags, type, location[0], location[1], zlevels, new_branch, old_branch)
    n += 1
    return if n > max_n
    puts "#{n}/#{max_n} locations checked #{skip_string}. #{generated}/#{min} testing location found"
  end
end

.test_tag_on_sythetic_data(tags, new_branch, old_branch = 'master', zlevels = Configuration.get_min_z..Configuration.get_max_z, types = ['node', 'closed_way', 'way'], test_on_water = false) ⇒ Object



59
60
61
62
63
64
# File 'lib/cartocss_helper.rb', line 59

def self.test_tag_on_sythetic_data(tags, new_branch, old_branch = 'master', zlevels = Configuration.get_min_z..Configuration.get_max_z, types = ['node', 'closed_way', 'way'], test_on_water = false)
  syn_tags = add_common_secondary_tags(tags)
  types.each do |type|
    CartoCSSHelper::VisualDiff.visualise_on_synthethic_data(syn_tags, type, test_on_water, zlevels, new_branch, old_branch)
  end
end

.visualise_place_by_file(filename, latitude, longitude, zlevels, new_branch, old_branch = 'master', header = nil, bb = 0.04, image_size = 350) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/cartocss_helper.rb', line 125

def self.visualise_place_by_file(filename, latitude, longitude, zlevels, new_branch, old_branch = 'master', header = nil, bb = 0.04, image_size = 350)
  raise "#{filename} does not exists" unless File.exist?(filename)
  raise "#{latitude} is not a number" unless latitude.is_a? Numeric
  raise "#{longitude} is not a number" unless longitude.is_a? Numeric
  raise "#{zlevels} is not a range" unless zlevels.class == Range
  raise "#{new_branch} is not a string" unless new_branch.class == String
  raise "#{old_branch} is not a string" unless old_branch.class == String
  raise "#{header} is not a string" unless header.class == String
  raise "#{bb} is not a number" unless bb.is_a? Numeric
  raise "#{image_size} is not a integer" unless image_size.is_a? Integer

  header = filename if header == nil
  header += ' ' + old_branch + '->' + new_branch + '[' + latitude.to_s + ',' + longitude.to_s + ']' + ' ' + image_size.to_s + 'px'
  CartoCSSHelper::VisualDiff.visualise_for_location_from_file(filename, latitude, longitude, zlevels, header, new_branch, old_branch, bb, image_size)
end

.visualise_place_by_remote_file(url, latitude, longitude, zlevels, new_branch, old_branch = 'master', header = nil, bb = 0.04, image_size = 350) ⇒ Object



119
120
121
122
123
# File 'lib/cartocss_helper.rb', line 119

def self.visualise_place_by_remote_file(url, latitude, longitude, zlevels, new_branch, old_branch = 'master', header = nil, bb = 0.04, image_size = 350)
  download_remote_file(url)
  filename = get_place_of_storage_of_resource_under_url(url)
  visualise_place_by_file(filename, latitude, longitude, zlevels, new_branch, old_branch, header, bb, image_size)
end

.visualise_place_by_url(url, zlevels, new_branch, old_branch = 'master', header = nil, download_bbox_size = 0.04, image_size = 350) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cartocss_helper.rb', line 86

def self.visualise_place_by_url(url, zlevels, new_branch, old_branch = 'master', header = nil, download_bbox_size = 0.04, image_size = 350)
  header = url if header == nil

  raise "#{url} is not a string, it is #{url.class}" unless url.class == String
  raise "#{zlevels} is not a range, it is #{zlevels.class}" unless zlevels.class == Range
  raise "#{new_branch} is not a string, it is #{new_branch.class}" unless new_branch.class == String
  raise "#{old_branch} is not a string, it is #{old_branch.class}" unless old_branch.class == String
  raise "#{header} is not a string, it is #{header.class}" unless header.class == String
  raise "#{download_bbox_size} is not a number" unless download_bbox_size.is_a? Numeric
  raise "#{image_size} is not a integer" unless image_size.is_a? Integer

  latitude, longitude = get_latitude_longitude_from_url(url)
  header += ' ' + old_branch + '->' + new_branch + ' ' + zlevels.to_s + ' ' + image_size.to_s + 'px'
  CartoCSSHelper::VisualDiff.visualise_for_location(latitude, longitude, zlevels, header, new_branch, old_branch, download_bbox_size, image_size)
end