From 12e3bcaa80cb8abf0e10482e1b59624f5553d6b9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 20 Oct 2015 11:31:08 +0200 Subject: [PATCH 1/2] Fixed timing issues. --- app/controllers/reports_controller.rb | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 52eaa5e72..2ae053ef0 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -23,9 +23,9 @@ class ReportsController < ApplicationController created = aggs(start, stop, 'minute', 'created_at') closed = aggs(start, stop, 'minute', 'close_time') elsif params[:timeRange] == 'day' - start = Date.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}").iso8601 - start = "#{start}T00:00:00Z" - stop = "#{start}T23:59:59Z" + date = Date.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}").to_s + start = "#{date}T00:00:00Z" + stop = "#{date}T23:59:59Z" created = aggs(start, stop, 'hour', 'created_at') closed = aggs(start, stop, 'hour', 'close_time') elsif params[:timeRange] == 'week' @@ -61,9 +61,9 @@ class ReportsController < ApplicationController start = (Time.zone.now - 60.minutes).iso8601 stop = Time.zone.now.iso8601 elsif params[:timeRange] == 'day' - start = Date.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}").iso8601 - start = "#{start}T00:00:00Z" - stop = "#{start}T23:59:59Z" + date = Date.parse("#{params[:year]}-#{params[:month]}-#{params[:day]}").to_s + start = "#{date}T00:00:00Z" + stop = "#{date}T23:59:59Z" elsif params[:timeRange] == 'week' start = Date.commercial(params[:year], params[:week]).iso8601 stop = Date.parse(start).end_of_week @@ -86,10 +86,14 @@ class ReportsController < ApplicationController end def aggs(range_start, range_end, interval, field) + interval_es = interval + if interval == 'week' + interval_es = 'day' + end result = SearchIndexBackend.aggs( { }, - [range_start, range_end, field, interval], + [range_start, range_end, field, interval_es], ['Ticket'], ) data = [] @@ -119,12 +123,13 @@ class ReportsController < ApplicationController end next if !item['doc_count'] next if item['key_as_string'] !~ /#{start_string}/ + next if match match = true data.push [counter, item['doc_count']] if interval == 'month' start = start.next_month elsif interval == 'week' - start = start.next_week + start = start.next_day elsif interval == 'day' start = start.next_day elsif interval == 'hour' @@ -138,7 +143,7 @@ class ReportsController < ApplicationController if interval == 'month' start = start.next_month elsif interval == 'week' - start = start.next_week + start = start.next_day elsif interval == 'day' start = start + 1.day elsif interval == 'hour' From 6af54e9d358121d9d26bcd9ad4ef4adc708d11a0 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 20 Oct 2015 11:44:26 +0200 Subject: [PATCH 2/2] Fixed initial setups. --- db/migrate/20151019000001_create_report.rb | 42 +++------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/db/migrate/20151019000001_create_report.rb b/db/migrate/20151019000001_create_report.rb index a72935f60..2e41fbbd1 100644 --- a/db/migrate/20151019000001_create_report.rb +++ b/db/migrate/20151019000001_create_report.rb @@ -10,6 +10,9 @@ class CreateReport < ActiveRecord::Migration end add_index :report_profiles, [:name], unique: true + # return if it's a new setup + return if !Setting.find_by(name: 'system_init_done') + Report::Profile.create_if_not_exists( name: '-all-', condition: {}, @@ -17,44 +20,7 @@ class CreateReport < ActiveRecord::Migration updated_by_id: 1, created_by_id: 1, ) - - Role.create_if_not_exists( name: 'Report', created_by_id: 1, updated_by_id: 1 ) - Translation.create_if_not_exists( - locale: 'de-de', - source: 'Ticket Count', - target: 'Ticket Anzahl', - updated_by_id: 1, - created_by_id: 1, - ) - Translation.create_if_not_exists( - locale: 'de-de', - source: 'Ticket Count', - target: 'Ticket Anzahl', - updated_by_id: 1, - created_by_id: 1, - ) - Translation.create_if_not_exists( - locale: 'de-de', - source: 'Create Channels', - target: 'Erstellkanäle', - updated_by_id: 1, - created_by_id: 1, - ) - Translation.create_if_not_exists( - locale: 'de-de', - source: 'Times', - target: 'Zeiten', - updated_by_id: 1, - created_by_id: 1, - ) - Translation.create_if_not_exists( - locale: 'de-de', - source: 'Communication', - target: 'Kommunikation', - updated_by_id: 1, - created_by_id: 1, - ) - + Role.create_if_not_exists(name: 'Report', created_by_id: 1, updated_by_id: 1) end def down