-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj_parser.rb
More file actions
67 lines (51 loc) · 1.38 KB
/
j_parser.rb
File metadata and controls
67 lines (51 loc) · 1.38 KB
1
2
3
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
require 'json'
require 'fileutils'
require 'builder'
require 'date'
file = File.open("workout.json", 'r')
contents = ""
file.each {|line|
contents << line
}
array = JSON.parse(contents)
#navigo array
workout = array['workout']
data = workout['workout_date']
#puts data
#INIZIALIZZAZIONE TEMPI ----
tempo0 = DateTime.strptime(data, "%F %T CST%:z")
tempo0_time = tempo0.to_time
laps = workout['laps']
@prova = ""
builder = Builder::XmlMarkup.new(:target => @prova, :indent => 1)
builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
#<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="NikePlus" version="1.1">
builder.gpx(:xmlns=>"http://www.topografix.com/GPX/1/1", :creator=>"nicolaosc", :version=>"1.1") do
builder.trk do
builder.trkseg do
laps.each do |n|
numero = n['data_points']
numero.each do |x|
latlng = x['latlng']
#puts latlng
time = x['time']
#aggiungi secondi segnati in quel punto
time_tag = tempo0_time + time
# primo giro non c'e' speed
elevation = x['elevation']
builder.trkpt(:lat => latlng[0], :lon => latlng[1]) do
#elevazione
# <ele>48.2530232204</ele>
builder.ele elevation
#time
# <time>2010-09-09T07:18:04Z</time>
builder.time time_tag.strftime("%FT%TZ")
end
end
end
end
end
end
puts @prova
result = File.open("prova.gpx.xml", 'w+')
result.write @prova