jzimmek-reportme 0.0.12 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/reportme/report_factory.rb +58 -42
  3. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.12
1
+ 0.1.0
@@ -168,61 +168,77 @@ module Reportme
168
168
  def run
169
169
 
170
170
  ensure_report_informations_table_exist
171
-
171
+
172
+ periods_queue = []
173
+
172
174
  while !@since.future?
173
-
174
175
  ReportFactory.periods(@since).each do |period|
176
+ periods_queue << period
177
+ end
178
+ @since += 1.day
179
+ end
175
180
 
176
- @reports.each do |r|
177
-
178
- period_name = period[:name]
179
-
180
- next unless r.wants_period?(period_name)
181
+
182
+ # we will generate all daily reports first.
183
+ # this will speed up generation of weekly and monthly reports.
184
+
185
+ periods_queue.reject{|p| p[:name] != :day}.each do |period|
186
+ report_period(period)
187
+ end
181
188
 
182
- _von = period[:von]
183
- _bis = period[:bis]
189
+ periods_queue.reject{|p| p[:name] == :day}.each do |period|
190
+ report_period(period)
191
+ end
192
+
193
+ end
194
+
195
+ def report_period(period)
196
+ @reports.each do |r|
197
+
198
+ period_name = period[:name]
199
+
200
+ next unless r.wants_period?(period_name)
184
201
 
185
- von = _von.strftime("%Y-%m-%d 00:00:00")
186
- bis = _bis.strftime("%Y-%m-%d 23:59:59")
202
+ _von = period[:von]
203
+ _bis = period[:bis]
187
204
 
188
- table_name = r.table_name(period_name)
205
+ von = _von.strftime("%Y-%m-%d 00:00:00")
206
+ bis = _bis.strftime("%Y-%m-%d 23:59:59")
189
207
 
190
- table_exist = r.table_exist?(period_name)
191
- sql = r.sql(von, bis, period_name)
192
-
193
- puts "report: #{r.table_name(period_name)} von: #{von}, bis: #{bis}"
208
+ table_name = r.table_name(period_name)
194
209
 
195
- ensure_report_table_exist(r, period_name)
196
-
197
- report_exists = report_exists?(table_name, von, bis)
198
-
199
- try_report_by_daily_reports(r, :week, _von, 6, 7) if period_name == :week && !report_exists
200
- try_report_by_daily_reports(r, :calendar_week, _von, 6, 7) if period_name == :calendar_week && !report_exists
201
-
202
- # TODO: implement monat by daily reports
203
- # try_report_by_daily_reports(r, :month, _von, 29 + (_von.end_of_month.day == 31 ? 1 : 0), 30) if period_name == :month && !report_exists
204
-
205
- try_report_by_daily_reports(r, :calendar_month, _von, _bis.day - _von.day, _bis.day) if period_name == :calendar_month && !report_exists
210
+ table_exist = r.table_exist?(period_name)
211
+ sql = r.sql(von, bis, period_name)
212
+
213
+ puts "report: #{r.table_name(period_name)} von: #{von}, bis: #{bis}"
206
214
 
207
- report_exists = report_exists?(table_name, von, bis)
208
-
209
- if !report_exists || period_name == :today
210
- ActiveRecord::Base.transaction do
211
- exec("insert into #{report_information_table_name} values ('#{table_name}', '#{von}', '#{bis}', now());") unless report_exists
212
-
213
- if period_name == :today
214
- exec("truncate #{table_name};")
215
- end
216
-
217
- exec("insert into #{table_name} #{sql};")
218
- end
219
- end
215
+ ensure_report_table_exist(r, period_name)
216
+
217
+ report_exists = report_exists?(table_name, von, bis)
218
+
219
+ try_report_by_daily_reports(r, :week, _von, 6, 7) if period_name == :week && !report_exists
220
+ try_report_by_daily_reports(r, :calendar_week, _von, 6, 7) if period_name == :calendar_week && !report_exists
221
+
222
+ # TODO: implement monat by daily reports
223
+ # try_report_by_daily_reports(r, :month, _von, 29 + (_von.end_of_month.day == 31 ? 1 : 0), 30) if period_name == :month && !report_exists
224
+
225
+ try_report_by_daily_reports(r, :calendar_month, _von, _bis.day - _von.day, _bis.day) if period_name == :calendar_month && !report_exists
220
226
 
227
+ report_exists = report_exists?(table_name, von, bis)
228
+
229
+ if !report_exists || period_name == :today
230
+ ActiveRecord::Base.transaction do
231
+ exec("insert into #{report_information_table_name} values ('#{table_name}', '#{von}', '#{bis}', now());") unless report_exists
221
232
 
233
+ if period_name == :today
234
+ exec("truncate #{table_name};")
235
+ end
236
+
237
+ exec("insert into #{table_name} #{sql};")
222
238
  end
223
239
  end
224
-
225
- @since += 1.day
240
+
241
+
226
242
  end
227
243
 
228
244
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jzimmek-reportme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek