Files
mapknitter/app/models/export.rb
Alicia Paz d2d45dbf42 Migrate from Travis to GitHub Actions for CI (#1534)
* Try migrating from Travis to GitHub Actions for CI

* Update actions.yml and tests.yml

* Add ruby version

* Update config/database.yml.example

* Try rubocop and docker jobs

* Fix indentation

* Update tests.yml

* Update tests.yml

* Update gemfile

* Update rubocop job and Gemfile

* Update .rubocop_shopify_styleguide.yml

* Update gemfile

* Update .rubocop_todo.yml

* Update rubocop configuration and styleguides

* Fix rubocop offenses

* Update .rubocop.yml

* Update .rubocop.yml

* Udate .codeclimate.yml

* Update .codeclimate.yml

* Update .codeclimate.yml

* Update .codeclimate.yml

* Setup unit tests

* Update find_verified_user method in connection.rb

* Add yarn cache and install to setup

* install exporter dependencies; gdal/imagemagick

* Introduce Gitpod to migration work (#1538)

* Add CORS headers (#1536)

* Create .gitpod.dockerfile

* Create .gitpod.yml

* Create database.yml.gitpod

* Update .gitpod.yml

* ruby 2.4.6 in gitpod.dockerfile

* Update .gitpod.yml

* Update database.yml.gitpod

Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org>
Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>

* Install gdal and use egordm for yarn cache

* Delete unnecessary query and fix layout

* Run script with verbose output

* Try installing package in action.yml

* Setup controllers job

* Fix indentation

* Setup system tests job

* Setup docker development build job

* Fix identifiers

* Fix path to action.yml

* Update development dockerfile

* Setup docker production build job

* Update tests.yml

* Setup assets precompilation job

* Setup production environment

* Update tests.yml

* Update action.yml for production

* Try with test setup

* Remove action.yml for production

* Change names of jobs for friendliness and clarity

* Update .github/workflows/tests.yml

Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>

* Move dockerfiles to directory and change docker job names for clarity

* Update docker job names

Co-authored-by: Jeffrey Warren <jeff@unterbahn.com>
Co-authored-by: Sebastian Silva <sebastian@fuentelibre.org>
2021-09-20 18:50:31 -04:00

64 lines
1.5 KiB
Ruby

class Export < ApplicationRecord
belongs_to :map, optional: true
belongs_to :user, optional: true
# currently exporting?
def running?
!%w(complete none failed).include?(status)
end
def self.average_cm_per_pixel
e = Export.where('cm_per_pixel != "" AND cm_per_pixel < 500')
sum = 0
e.each do |export|
sum += export.cm_per_pixel
end
if !e.empty?
sum / e.length
else
0
end
end
def self.histogram_cm_per_pixel
e = Export.where('cm_per_pixel != "" AND cm_per_pixel < 500')
.order('cm_per_pixel DESC')
if !e.empty?
hist = []
(0..e.first.cm_per_pixel.to_i).each do |bin|
hist[bin] = 0
end
e.each do |export|
hist[export.cm_per_pixel.to_i] += 1
end
hist
else
[]
end
end
def self.histogram_cm_per_pixel_in_tens
e = Export.where('cm_per_pixel != "" AND cm_per_pixel < 500')
.order('cm_per_pixel desc')
hist = []
(0..e.first.cm_per_pixel / 10.to_i).each do |bin|
hist[bin] = 0
end
e.each do |export|
hist[export.cm_per_pixel / 10.to_i] += 1
end
hist
end
def self.export_count
Export.where('status != "failed" AND status != "complete" AND status != "none" AND updated_at > ?',
(DateTime.now - 24.hours).to_s(:db)).count
end
# all exports currently running
def self.exporting
Export.where('status != "failed" AND status != "complete" AND status != "none" AND updated_at > ?',
(DateTime.now - 24.hours).to_s(:db))
end
end