jzimmek-reportme 0.0.12 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/reportme/report_factory.rb +58 -42
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
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
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
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
|
-
|
183
|
-
|
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
|
-
|
186
|
-
|
202
|
+
_von = period[:von]
|
203
|
+
_bis = period[:bis]
|
187
204
|
|
188
|
-
|
205
|
+
von = _von.strftime("%Y-%m-%d 00:00:00")
|
206
|
+
bis = _bis.strftime("%Y-%m-%d 23:59:59")
|
189
207
|
|
190
|
-
|
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
|
-
|
196
|
-
|
197
|
-
|
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
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
-
|
240
|
+
|
241
|
+
|
226
242
|
end
|
227
243
|
|
228
244
|
end
|