Skip to content

Commit

Permalink
time to go postal
Browse files Browse the repository at this point in the history
  • Loading branch information
Arie committed Feb 28, 2015
1 parent 09cc0f0 commit aa3d6b4
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 117 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ gem 'american_date'
gem 'jbuilder'

gem 'ffi'
gem 'mysql2'
gem 'pg'
gem 'therubyracer'
gem 'oily_png'
gem 'sys-proctable', '~> 0.9.4', :require => 'sys/proctable'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ GEM
multi_test (0.1.2)
multi_xml (0.5.5)
multipart-post (1.2.0)
mysql2 (0.3.18)
net-http-digest_auth (1.4)
net-http-persistent (2.9.4)
net-scp (1.2.1)
Expand Down Expand Up @@ -276,6 +275,7 @@ GEM
multi_json (~> 1.0)
uuidtools (~> 2.1)
xml-simple
pg (0.18.1)
protected_attributes (1.0.8)
activemodel (>= 4.0.1, < 5.0)
pry (0.10.1)
Expand Down Expand Up @@ -502,14 +502,14 @@ DEPENDENCIES
logs_tf
mechanize
minitest
mysql2
net-sftp
net-ssh
net-ssh-simple
oily_png
omniauth-openid
omniauth-steam
paypal-sdk-rest
pg
protected_attributes
pry-nav
puma
Expand Down
16 changes: 12 additions & 4 deletions app/models/statistic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ def self.reservations_per_day
end

def self.reserved_hours_per_month
Rails.cache.fetch "reserved_hours_per_month_#{Date.current}", :expires_in => 1.hour do
result = ActiveRecord::Base.connection.execute("SELECT SUM(duration), YEAR(starts_at), MONTH(starts_at) FROM reservations GROUP BY YEAR(starts_at), MONTH(starts_at)")
result.to_a.map do |seconds, year, month|
Rails.cache.fetch "reserved_hours_per_month_#{Date.current}", :expires_in => 1.hour do
result = ActiveRecord::Base.connection.execute("SELECT TO_CHAR(starts_at, 'YYYY-MM') AS year_month,
SUM(duration) as duration
FROM reservations
GROUP BY 1
ORDER BY 1")
result.to_a.map do |duration_per_month|
year_month= duration_per_month["year_month"]
seconds = duration_per_month["duration"]
year = year_month.split("-").first.to_i
month = year_month.split("-").last.to_i
date = Date.new(year, month)
formatted_date = date.strftime("%b %Y")
[formatted_date, (seconds.to_f / 3600.0).round]
end
end
end
end


Expand Down
16 changes: 9 additions & 7 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: mysql2
adapter: postgresql
database: serveme_development
encoding: utf8mb4
username: serveme
encoding: unicode
pool: 5
timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test: &test
adapter: mysql2
adapter: postgresql
database: serveme_test
username: root
encoding: utf8mb4
username: serveme
encoding: unicode
pool: 5
timeout: 5000

production:
adapter: mysql2
adapter: postgresql
database: serveme_production
encoding: utf8mb4
username: serveme
encoding: unicode
pool: 5
timeout: 5000

Expand Down
24 changes: 12 additions & 12 deletions db/migrate/20131028193857_make_columns_mb4_compatible.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class MakeColumnsMb4Compatible < ActiveRecord::Migration
def up
execute "alter table groups modify name varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
execute "alter table users modify email varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
execute "alter table users modify reset_password_token varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
execute "alter table users modify name varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
execute "alter table users modify nickname varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
execute "alter table users modify logs_tf_api_key varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
# execute "alter table groups modify name varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
# execute "alter table users modify email varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
# execute "alter table users modify reset_password_token varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
# execute "alter table users modify name varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
# execute "alter table users modify nickname varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
# execute "alter table users modify logs_tf_api_key varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"
end

def down
execute "alter table groups modify name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
execute "alter table users modify email varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
execute "alter table users modify reset_password_token varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
execute "alter table users modify name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
execute "alter table users modify nickname varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
execute "alter table users modify logs_tf_api_key varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
# execute "alter table groups modify name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
# execute "alter table users modify email varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
# execute "alter table users modify reset_password_token varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
# execute "alter table users modify name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
# execute "alter table users modify nickname varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
# execute "alter table users modify logs_tf_api_key varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci"
end
end
Loading

0 comments on commit aa3d6b4

Please sign in to comment.