Skip to content

Commit

Permalink
Merge pull request #1664 from asalani93/asalani_latitude_longitude_auto
Browse files Browse the repository at this point in the history
Detect properly named latitude and longitude fields
  • Loading branch information
NatTuck committed Aug 1, 2014
2 parents 7c614e6 + bc59671 commit f8e899b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/views/projects/templateUpload.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
<select name="headers[<%=header%>]", class="form-control">
<%=options_for_select(@options,get_field_type('Timestamp'))%>
</select>
<%elsif @types['latitude'].include? header%>
<select name="headers[<%=header%>]", class="form-control">
<%=options_for_select(@options,get_field_type('Latitude'))%>
</select>
<%elsif @types['longitude'].include? header%>
<select name="headers[<%=header%>]", class="form-control">
<%=options_for_select(@options,get_field_type('Longitude'))%>
</select>
<%else%>
<select name="headers[<%=header%>]", class="form-control">
<%=options_for_select(@options,get_field_type('Number'))%>
Expand Down
6 changes: 6 additions & 0 deletions lib/file_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def get_probable_types(data_obj)
types = {}
types['text'] = []
types['timestamp'] = []
types['latitude'] = []
types['longitude'] = []

regex = %r{.(?<year>\d{4})(-|\/)(?<month>\d{1,2})(-|\/)(?<day>\d{1,2})}

Expand All @@ -155,6 +157,10 @@ def get_probable_types(data_obj)
types['timestamp'].push column[0]
elsif !(column[1]).map { |dp| valid_float?(dp) }.reduce(:&)
types['text'].push column[0]
elsif column[0].casecmp('LATITUDE') == 0 or column[0].casecmp('LAT') == 0
types['latitude'].push column[0]
elsif column[0].casecmp('LONGITUDE') == 0 or column[0].casecmp('LON') == 0
types['longitude'].push column[0]
end
end
types
Expand Down

0 comments on commit f8e899b

Please sign in to comment.