jzimmek-reportme 0.0.9 → 0.0.10

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/reportme/report_factory.rb +66 -26
  3. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.9
1
+ 0.0.10
@@ -29,12 +29,14 @@ module Reportme
29
29
  when :day
30
30
  [today - 1.day, today - 1.day]
31
31
  when :week
32
- [today - 1.day - 1.week, today - 1.day]
32
+ # [today - 1.day - 1.week, today - 1.day]
33
+ [today - 1.week, today - 1.day]
33
34
  when :calendar_week
34
35
  n = today - 1.day
35
36
  [n - n.cwday + 1, n - n.cwday + 7]
36
37
  when :month
37
- [today - 1.day - 1.month, today - 1.day]
38
+ # [today - 1.day - 1.month, today - 1.day]
39
+ [today - 1.month, today - 1.day]
38
40
  when :calendar_month
39
41
  n = today - 1.month
40
42
  [n.beginning_of_month, n.end_of_month]
@@ -68,11 +70,21 @@ module Reportme
68
70
  end
69
71
  end
70
72
  end
71
-
72
- def run
73
-
74
- debug = false
73
+
74
+ def week_data_present?(report, von, bis)
75
+ puts "von: #{von} ... bis: #{bis}"
76
+ end
77
+
78
+ def ensure_report_table_exist(report, period)
79
+ unless report.table_exist?(period)
80
+ table_name = report.table_name(period)
81
+ sql = report.sql('0000-00-00 00:00:00', '0000-00-00 00:00:00', period)
82
+
83
+ exec("create table #{table_name} ENGINE=InnoDB default CHARSET=utf8 as #{sql} limit 0;")
84
+ end
85
+ end
75
86
 
87
+ def ensure_report_informations_table_exist
76
88
  unless report_information_table_name_exist?
77
89
  ddl = <<-SQL
78
90
  create
@@ -88,12 +100,40 @@ module Reportme
88
100
  SQL
89
101
  exec(ddl)
90
102
  end
103
+ end
91
104
 
92
- if debug
93
- # just for testing
94
- exec("truncate #{report_information_table_name};")
105
+ def try_weekly_report_by_daily_reports(report, _von, _bis)
106
+
107
+ table_name = report.table_name(:week)
108
+
109
+ von = _von.strftime("%Y-%m-%d 00:00:00")
110
+ bis = _bis.strftime("%Y-%m-%d 23:59:59")
111
+
112
+ existing_daily_reports = select_value(<<-SQL
113
+ select
114
+ count(1) cnt
115
+ from
116
+ #{report_information_table_name}
117
+ where
118
+ report = '#{report.table_name(:day)}'
119
+ and von between '#{von}' and '#{(_von + 6.days).strftime("%Y-%m-%d 23:59:59")}'
120
+ SQL
121
+ ).to_i
122
+
123
+ puts "weekly report depends on 7 daily reports ... #{existing_daily_reports} daily found"
124
+
125
+ if existing_daily_reports == 7
126
+ ActiveRecord::Base.transaction do
127
+ exec("insert into #{report_information_table_name} values ('#{table_name}', '#{von}', '#{bis}', now());")
128
+ exec("insert into #{table_name} select * from #{report.table_name(:day)} where von between '#{von}' and '#{(_von + 6.days).strftime("%Y-%m-%d 00:00:00")}';")
129
+ end
95
130
  end
131
+ end
96
132
 
133
+ def run
134
+
135
+ ensure_report_informations_table_exist
136
+
97
137
  while !@since.future?
98
138
 
99
139
  periods(@since).each do |period|
@@ -103,31 +143,31 @@ module Reportme
103
143
  period_name = period[:name]
104
144
 
105
145
  next unless r.wants_period?(period_name)
106
-
107
- von = period[:von].strftime("%Y-%m-%d 00:00:00")
108
- bis = period[:bis].strftime("%Y-%m-%d 23:59:59")
109
146
 
110
- table_name = r.table_name(period_name)
147
+ _von = period[:von]
148
+ _bis = period[:bis]
111
149
 
112
- # if debug
113
- # # drop and create table while in testing mode
114
- # exec("drop table if exists #{table_name};")
115
- # end
150
+ von = _von.strftime("%Y-%m-%d 00:00:00")
151
+ bis = _bis.strftime("%Y-%m-%d 23:59:59")
152
+
153
+ table_name = r.table_name(period_name)
116
154
 
117
155
  table_exist = r.table_exist?(period_name)
118
156
  sql = r.sql(von, bis, period_name)
119
- report_exist = report_exists?(table_name, von, bis)
120
157
 
121
158
  puts "report: #{r.table_name(period_name)} exist: #{table_exist}"
122
-
123
-
124
- unless table_exist
125
- exec("create table #{table_name} ENGINE=InnoDB default CHARSET=utf8 as #{sql} limit 0;")
126
- end
127
-
128
- if !report_exist || period_name == :today
159
+
160
+ ensure_report_table_exist(r, period_name)
161
+
162
+ report_exists = report_exists?(table_name, von, bis)
163
+
164
+ try_weekly_report_by_daily_reports(r, _von, _bis) if period_name == :week && !report_exists
165
+
166
+ report_exists = report_exists?(table_name, von, bis)
167
+
168
+ if !report_exists || period_name == :today
129
169
  ActiveRecord::Base.transaction do
130
- exec("insert into #{report_information_table_name} values ('#{table_name}', '#{von}', '#{bis}', now());") unless report_exist
170
+ exec("insert into #{report_information_table_name} values ('#{table_name}', '#{von}', '#{bis}', now());") unless report_exists
131
171
 
132
172
  if period_name == :today
133
173
  exec("truncate #{table_name};")
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.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Zimmek
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-23 00:00:00 -07:00
12
+ date: 2009-06-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15