From 59a4d760bff4d6a070d66d1e845c49ac1614f7c4 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Mon, 21 Jul 2025 18:59:13 +0200 Subject: [PATCH] Fix owntracks points creation --- CHANGELOG.md | 2 ++ app/services/own_tracks/rec_parser.rb | 4 ++++ spec/fixtures/files/owntracks/2023-02_old.rec | 10 ++++++++++ spec/services/own_tracks/importer_spec.rb | 14 ++++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 spec/fixtures/files/owntracks/2023-02_old.rec diff --git a/CHANGELOG.md b/CHANGELOG.md index 9452c761..0b9b9fd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,6 +73,8 @@ end - Swagger documentation is now valid again. - Invalid owntracks points are now ignored. +- An older Owntrack's .rec format is now also supported. +- Course and course accuracy are now rounded to 8 decimal places to fix the issue with points creation. # [0.29.1] - 2025-07-02 diff --git a/app/services/own_tracks/rec_parser.rb b/app/services/own_tracks/rec_parser.rb index 7e3550af..74959460 100644 --- a/app/services/own_tracks/rec_parser.rb +++ b/app/services/own_tracks/rec_parser.rb @@ -9,8 +9,12 @@ class OwnTracks::RecParser def call file.split("\n").map do |line| + # Try tab-separated first, then fall back to whitespace-separated parts = line.split("\t") + # If tab splitting didn't work (only 1 part), try whitespace splitting + parts = line.split(/\s+/) if parts.size == 1 + Oj.load(parts[2]) if parts.size > 2 && parts[1].strip == '*' end.compact end diff --git a/spec/fixtures/files/owntracks/2023-02_old.rec b/spec/fixtures/files/owntracks/2023-02_old.rec new file mode 100644 index 00000000..a87c0aaf --- /dev/null +++ b/spec/fixtures/files/owntracks/2023-02_old.rec @@ -0,0 +1,10 @@ +2023-02-20T18:46:22Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918783,"lat":22.0687934,"lon":24.7941786,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918782,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:25Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":13,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918785,"lat":22.0687967,"lon":24.7941813,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918785,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:25Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":13,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918790,"lat":22.0687967,"lon":24.7941813,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918785,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:35Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918795,"lat":22.0687906,"lon":24.794195,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918795,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:40Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918800,"lat":22.0687967,"lon":24.7941859,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918800,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:45Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918805,"lat":22.0687946,"lon":24.7941883,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918805,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:50Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918810,"lat":22.0687912,"lon":24.7941837,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918810,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:55Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918815,"lat":22.0687927,"lon":24.794186,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918815,"vac":0,"vel":0,"_http":true} +2023-02-20T18:46:55Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918815,"lat":22.0687937,"lon":24.794186,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918815,"vac":0,"vel":0,"_http":true} +2023-02-20T18:47:00Z * {"_type":"location","BSSID":"6c:c4:9f:e0:bb:b1","SSID":"WiFi","acc":14,"alt":136,"batt":38,"bs":1,"conn":"w","created_at":1676918820,"lat":22.0687937,"lon":24.794186,"m":2,"tid":"l6","topic":"owntracks/pixel6/pixel99","tst":1676918820,"vac":0,"vel":0,"_http":true} diff --git a/spec/services/own_tracks/importer_spec.rb b/spec/services/own_tracks/importer_spec.rb index 0800d0b8..842883f8 100644 --- a/spec/services/own_tracks/importer_spec.rb +++ b/spec/services/own_tracks/importer_spec.rb @@ -78,5 +78,19 @@ RSpec.describe OwnTracks::Importer do expect(Point.first.velocity).to eq('1.4') end end + + context 'when file is old' do + let(:file_path) { Rails.root.join('spec/fixtures/files/owntracks/2023-02_old.rec') } + + it 'creates points' do + expect { parser }.to change { Point.count }.by(9) + end + + it 'correctly writes attributes' do + parser + + point = Point.first + end + end end end