diff --git a/README.md b/README.md index c1d96c21..05328b73 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,8 @@ Dockerized with https://betterprogramming.pub/rails-6-development-with-docker-55 Then go to Portainer and update the service to use the new image +## Environment variables + +`MINIMUM_POINTS_IN_CITY` — minimum number of points in a city to consider it as a city visited, eg. `10` +`MAP_CENTER` — default map center, e.g. `55.7558,37.6176` +`TIME_ZONE` — time zone, e.g. `Europe/Berlin` diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 351bc31c..8e385128 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -32,6 +32,8 @@ class ImportsController < ApplicationController end end + StatCreatingJob.perform_later(current_user.id) + redirect_to imports_url, notice: "#{imports.size} import files were imported successfully", status: :see_other rescue StandardError => e imports.each { |import| import&.destroy! } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 42ffb140..df49c727 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,11 +8,18 @@ module ApplicationHelper end end - def url_time(stat) + def month_timespan(stat) month = DateTime.new(stat.year, stat.month).in_time_zone(Time.zone) start_at = month.beginning_of_month.to_time.strftime('%Y-%m-%dT%H:%M') end_at = month.end_of_month.to_time.strftime('%Y-%m-%dT%H:%M') { start_at:, end_at: } end + + def year_timespan(year) + start_at = DateTime.new(year).beginning_of_year.to_time.strftime('%Y-%m-%dT%H:%M') + end_at = DateTime.new(year).end_of_year.to_time.strftime('%Y-%m-%dT%H:%M') + + { start_at: start_at, end_at: end_at } + end end diff --git a/app/jobs/stat_creating_job.rb b/app/jobs/stat_creating_job.rb new file mode 100644 index 00000000..6ca0f9fe --- /dev/null +++ b/app/jobs/stat_creating_job.rb @@ -0,0 +1,7 @@ +class StatCreatingJob < ApplicationJob + queue_as :default + + def perform(user_id) + CreateStats.new(user_id).call + end +end diff --git a/app/views/stats/_stat.html.erb b/app/views/stats/_stat.html.erb index 9a39d96a..c3b946a4 100644 --- a/app/views/stats/_stat.html.erb +++ b/app/views/stats/_stat.html.erb @@ -1,7 +1,7 @@