From fc3f2b52ad98e1baf84d0aa39e85bbc368354c37 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 16 Mar 2024 23:15:44 +0100 Subject: [PATCH] Set default timespan equal to 1 month to date --- Makefile | 6 +- README.md | 127 +----------------- app/controllers/points_controller.rb | 22 +-- app/javascript/controllers/maps_controller.js | 2 + app/views/points/index.html.erb | 2 +- 5 files changed, 22 insertions(+), 137 deletions(-) diff --git a/Makefile b/Makefile index b0885ec2..551969cc 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,6 @@ production_migrate: ssh dokku_frey 'dokku run dawarich bundle exec rails db:migrate' build_and_push: - docker build . -t dawarich --platform=linux/amd64 - docker tag dawarich registry.chibi.rodeo/dawarich - docker push registry.chibi.rodeo/dawarich + docker build . -t dawarich:$(version) --platform=linux/amd64 + docker tag dawarich:$(version) registry.chibi.rodeo/dawarich:$(version) + docker push registry.chibi.rodeo/dawarich:$(version) diff --git a/README.md b/README.md index 444a4fc2..c1d96c21 100644 --- a/README.md +++ b/README.md @@ -23,130 +23,9 @@ Press `Ctrl+C` to stop the app. Dockerized with https://betterprogramming.pub/rails-6-development-with-docker-55437314a1ad -## Deployment (1st time) +## Deployment -0. Set variables in Homelab repo -1. `make dokku_new_app` -2. `make dokku_setup_backups` -3. `make dokku_add_domain` -4. Create certificates files in Homelab repo -5. `make dokku_add_ssl` -6. Set SSL/TLS mode to Full in Cloudflare -7. `git remote add dokku dokku@DOKKU_SERVER_UP:APP_NAME` -8. `git push dokku master` -9. Add app.json to the repo: +`make build_and_push version=0.0.5` to build and push the docker image to the registry -```json - { - "scripts": { - "predeploy": "dokku ps:stop wardu" - }, - "formation": { - "web": { - "quantity": 1 - }, - "worker": { - "quantity": 1 - } - } - } -``` +Then go to Portainer and update the service to use the new image - -{ - "cog": 271, - "batt": 41, - "lon": 2.29513, - "acc": 5, - "vel": 61, - "vac": 21, - "lat": 48.85833, - "t": "u", - "tst": 1497508651, - "alt": 167, - "_type": "location", - "topic": "owntracks/jane/iphone", - "p": 71, - "tid": "JJ" -} - -{"bs"=>1, # battery status -"p"=>102.818, # ping -"batt"=>100, # battery -"_type"=>"location", # type -"tid"=>"RO", # Tracker ID used to display the initials of a user (iOS,Android/string/optional) required for http mode -"topic"=>"owntracks/Frey/iPhone 12 Pro", -"alt"=>36, -"lon"=>13.504178, -"vel"=>0, # velocity -"t"=>"u", -"BSSID"=>"b0:f2:8:45:94:33", -"SSID"=>"FRITZ!Box 6660 Cable LQ", -"conn"=>"w", # connection, w = wifi, m = mobile, o = offline -"vac"=>3, # vertical accuracy -"acc"=>5, # horizontal accuracy -"tst"=>1702662679, Timestamp at which the beacon was seen (iOS/integer/epoch) -"lat"=>52.445526, -"m"=>1, # mode, significant = 1, move = 2 -"inrids"=>["5f1d1b"], # contains a list of region IDs the device is currently in (e.g. ["6da9cf","3defa7"]). Might be empty. (iOS,Android/list of strings/optional) -"inregions"=>["home"], -"point"=>{"bs"=>1, -"p"=>102.818, -"batt"=>100, -"_type"=>"location", -"tid"=>"RO", -"topic"=>"owntracks/Frey/iPhone 12 Pro", -"alt"=>36, -"lon"=>13.504178, -"vel"=>0, -"t"=>"u", -"BSSID"=>"b0:f2:8:45:94:33", -"SSID"=>"FRITZ!Box 6660 Cable LQ", -"conn"=>"w", -"vac"=>3, -"acc"=>5, -"tst"=>1702662679, -"lat"=>52.445526, -"m"=>1, -"inrids"=>["5f1d1b"], -"inregions"=>["home"]}} -18:51:18 web.1 | #1, -"p"=>102.818, -"batt"=>100, -"_type"=>"location", -"tid"=>"RO", -"topic"=>"owntracks/Frey/iPhone 12 Pro", -"alt"=>36, -"lon"=>13.504178, -"vel"=>0, -"t"=>"u", -"BSSID"=>"b0:f2:8:45:94:33", -"SSID"=>"FRITZ!Box 6660 Cable LQ", -"conn"=>"w", -"vac"=>3, -"acc"=>5, -"tst"=>1702662679, -"lat"=>52.445526, -"m"=>1, -"inrids"=>["5f1d1b"], -"inregions"=>["home"], -"point"=>{"bs"=>1, -"p"=>102.818, -"batt"=>100, -"_type"=>"location", -"tid"=>"RO", -"topic"=>"owntracks/Frey/iPhone 12 Pro", -"alt"=>36, -"lon"=>13.504178, -"vel"=>0, -"t"=>"u", -"BSSID"=>"b0:f2:8:45:94:33", -"SSID"=>"FRITZ!Box 6660 Cable LQ", -"conn"=>"w", -"vac"=>3, -"acc"=>5, -"tst"=>1702662679, -"lat"=>52.445526, -"m"=>1, -"inrids"=>["5f1d1b"], -"inregions"=>["home"]}} permitted: false> diff --git a/app/controllers/points_controller.rb b/app/controllers/points_controller.rb index 41550ada..f9c1f88b 100644 --- a/app/controllers/points_controller.rb +++ b/app/controllers/points_controller.rb @@ -2,17 +2,21 @@ class PointsController < ApplicationController before_action :authenticate_user! def index - start_at = params[:start_at]&.to_datetime.to_i - end_at = params[:end_at]&.to_datetime.to_i - - @points = - if start_at.positive? && end_at.positive? - Point.where('timestamp >= ? AND timestamp <= ?', start_at, end_at) - else - Point.all - end.order(timestamp: :asc) + @points = Point.where('timestamp >= ? AND timestamp <= ?', start_at, end_at).order(timestamp: :asc) @countries_and_cities = @points.group_by(&:country).transform_values { _1.pluck(:city).uniq.compact } @coordinates = @points.pluck(:latitude, :longitude).map { [_1.to_f, _2.to_f] } end + + def start_at + return 1.month.ago.beginning_of_day.to_i if params[:start_at].nil? + + params[:start_at].to_datetime.to_i + end + + def end_at + return Date.today.end_of_day.to_i if params[:end_at].nil? + + params[:end_at].to_datetime.to_i + end end diff --git a/app/javascript/controllers/maps_controller.js b/app/javascript/controllers/maps_controller.js index 28765665..7167d220 100644 --- a/app/javascript/controllers/maps_controller.js +++ b/app/javascript/controllers/maps_controller.js @@ -9,6 +9,7 @@ export default class extends Controller { console.log("Map controller connected") var markers = JSON.parse(this.element.dataset.coordinates) var center = markers[0] + var lastMarker = markers[markers.length - 1] var center = (center === undefined) ? [52.516667, 13.383333] : center; var map = L.map(this.containerTarget).setView(center, 14); @@ -25,6 +26,7 @@ export default class extends Controller { L.circleMarker([lat, lon], {radius: 3}).addTo(map); } + L.marker(lastMarker).addTo(map); L.polyline(markers).addTo(map); } diff --git a/app/views/points/index.html.erb b/app/views/points/index.html.erb index 5026529f..276d5eaf 100644 --- a/app/views/points/index.html.erb +++ b/app/views/points/index.html.erb @@ -23,6 +23,6 @@ <% end %>
-
+