Test Util C0 Coverage Information - RCov

/home/masa/ywesee/oddb.org/src/util/exporter.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
/home/masa/ywesee/oddb.org/src/util/exporter.rb 321 307
96.88%
96.74%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 #!/usr/bin/env ruby
2 # Exporter -- oddb -- 30.07.2003 -- hwyss@ywesee.com 
3 
4 require 'plugin/oddbdat_export'
5 require 'plugin/fipdf'
6 require 'plugin/yaml'
7 require 'plugin/csv_export'
8 require 'plugin/patinfo_invoicer'
9 require 'plugin/fachinfo_invoicer'
10 require 'plugin/download_invoicer'
11 require 'plugin/ouwerkerk'
12 require 'plugin/xls_export'
13 require 'plugin/swissmedic'
14 require 'util/log'
15 require 'util/logfile'
16 require 'util/schedule'
17 
18 module ODDB
19 	class Exporter
20     include Util::Schedule
21 		EXPORT_SERVER = DRbObject.new(nil, EXPORT_URI)
22 		EXPORT_DIR = File.expand_path('../../data/downloads',
23 																	File.dirname(__FILE__))
24 		FileUtils.mkdir_p(EXPORT_DIR)
25 		class SessionStub
26 			attr_accessor :language, :flavor, :lookandfeel
27 			alias :default_language :language
28 		end
29 		def initialize(app)
30 			@app = app
31 		end
32     def run
33       ## restart the export server
34       EXPORT_SERVER.clear
35       sleep(30)
36       #
37       mail_patinfo_invoices
38       mail_fachinfo_log
39       run_on_monthday(1) {
40         mail_download_invoices
41       }
42       run_on_monthday(15) {
43         mail_download_invoices
44       }
45       run_on_weekday(0) {
46         mail_download_stats
47         mail_feedback_stats
48         #mail_notification_stats
49       }
50       export_sl_pcodes
51       export_yaml
52       export_oddbdat
53       export_csv
54       export_doc_csv
55       export_index_therapeuticus_csv
56       export_price_history_csv
57 =begin # inoperable atm.
58       run_on_monthday(1) {
59         export_fachinfo_pdf
60       }
61 =end
62       nil
63     end
64     def export_helper(name)
65       EXPORT_SERVER.remote_safe_export(EXPORT_DIR, name) { |path|
66         yield path
67       }
68     end
69     def export_all_csv
70       export_csv
71       export_doc_csv
72       export_index_therapeuticus_csv
73       export_price_history_csv
74     end
75 		def export_competition_xls(company, db_path=nil)
76 			plug = XlsExportPlugin.new(@app)
77 			plug.export_competition(company, db_path)
78 			plug
79 		end
80     def export_csv
81       plug = CsvExportPlugin.new(@app)
82       safe_export 'oddb.csv' do
83         plug.export_drugs
84       end
85       safe_export 'oddb.csv' do
86         plug.export_drugs_extended
87       end
88       EXPORT_SERVER.clear
89       sleep(30)
90     end
91 		def export_analysis_csv
92 			plug = CsvExportPlugin.new(@app)
93 			plug.export_analysis
94 			EXPORT_SERVER.clear
95 			sleep(30)
96 		end
97 		def export_doc_csv
98       safe_export 'doctors.csv' do
99         plug = CsvExportPlugin.new(@app)
100         plug.export_doctors
101       end
102       EXPORT_SERVER.clear
103       sleep(30)
104 		end
105     def export_fachinfo_pdf(langs = [:de, :fr])
106       plug = FiPDFExporter.new(@app)
107       langs.each { |lang|
108         name = "fachinfos_#{lang}.pdf"
109         safe_export name do
110           path = File.join(EXPORT_DIR, name)
111           plug.write_pdf(lang, path)
112           EXPORT_SERVER.compress(EXPORT_DIR, name)
113         end
114       }
115     end
116 		def export_generics_xls
117 			plug = XlsExportPlugin.new(@app)
118 			plug.export_generics
119 			plug
120 		end
121 		def export_swissdrug_xls(date = @@today, opts={})
122 			plug = OuwerkerkPlugin.new(@app, "swissdrug update")
123 			plug.export_xls opts
124 			name = 'swissdrug-update.xls'
125 			path = File.join(EXPORT_DIR, name)
126 			FileUtils.cp(plug.file_path, path)
127 			EXPORT_SERVER.compress(EXPORT_DIR, name)
128 			plug
129 		end
130     def export_index_therapeuticus_csv
131       safe_export 'index_therapeuticus' do
132         plug = CsvExportPlugin.new(@app)
133         plug.export_index_therapeuticus
134       end
135       EXPORT_SERVER.clear
136       sleep(30)
137     end
138 		def export_migel_csv
139 			plug = CsvExportPlugin.new(@app)
140 			plug.export_migel
141 			EXPORT_SERVER.clear
142 			sleep(30)
143 		end
144 		def export_narcotics_csv
145 			plug = CsvExportPlugin.new(@app)
146 			plug.export_narcotics
147 			EXPORT_SERVER.clear
148 			sleep(30)
149 		end
150 		def export_oddbdat
151           dose_missing_list = []
152       safe_export 'oddbdat' do
153         exporter = OdbaExporter::OddbDatExport.new(@app)
154         dose_missing_list = exporter.export
155         EXPORT_SERVER.clear
156         sleep(30)
157         run_on_weekday(1) {
158           exporter.export_fachinfos
159           EXPORT_SERVER.clear
160           sleep(30)
161         }
162 
163         # here to raise warning if package.parts is empty
164         if !dose_missing_list.empty?
165 			log = Log.new(@@today)
166 			log.report = [
167 				"Warning: Dose data (ODDB::Package.parts, Array of ODDB::Dose instances) is empty.",
168 				"Message: export_oddbdat succeeded but the following package(s) do not have Dose data.",
169 				"Package(s):",
170                 dose_missing_list.collect do |list|
171                   list[0].to_s + ", " + \
172                   "http://#{SERVER_NAME}/de/gcc/resolve/pointer/%3A!registration%2C" + list[1].to_s + \
173                   "!sequence%2C" + list[2].to_s + "!package%2C" + list[3].to_s + ".\n"
174                 end
175 			].join("\n")
176 			log.notify("Warning Export: oddbdat")
177         end
178       end
179 		end
180 		def export_pdf
181 			FiPDFExporter.new(@app).run
182 		end
183 		def export_sl_pcodes
184       safe_export 'sl_pcodes.txt' do
185         path = File.expand_path('../../data/txt/sl_pcodes.txt',
186           File.dirname(__FILE__))
187         File.open(path, 'w') { |fh|
188           @app.each_package { |pac|
189             if(pac.sl_entry && pac.pharmacode)
190               fh.puts(pac.pharmacode)
191             end
192           }
193         }
194       end
195 		end
196     def export_patents_xls
197       plug = XlsExportPlugin.new(@app)
198       plug.export_patents
199       plug
200     end
201 		def export_yaml
202 			exporter = YamlExporter.new(@app)
203       safe_export 'oddb.yaml' do
204         exporter.export
205       end
206       safe_export 'atc.yaml' do
207         exporter.export_atc_classes
208       end
209       safe_export 'interactions.yaml' do
210         exporter.export_interactions
211       end
212       safe_export 'narcotics.yaml' do
213         exporter.export_narcotics
214       end
215       safe_export 'price_history.yaml' do
216         exporter.export_prices
217       end
218 			run_on_weekday(2) {
219         safe_export 'fachinfo.yaml' do
220           exporter.export_fachinfos
221         end
222 			}
223 			run_on_weekday(3) {
224         safe_export 'patinfo.yaml' do
225           exporter.export_patinfos
226         end
227 			}
228 			run_on_weekday(4) {
229         safe_export 'doctors.yaml' do
230           exporter.export_doctors
231         end
232 			}
233 			EXPORT_SERVER.clear
234 			sleep(30)
235 		end
236 		def mail_download_stats
237       safe_export 'Mail Download-Statistics' do
238         mail_stats('download')
239       end
240 		end
241 		def mail_download_invoices
242       safe_export 'Mail Download-Invoices' do
243         DownloadInvoicer.new(@app).run
244       end
245 		end
246 		def mail_fachinfo_log(day = @@today)
247       safe_export 'Mail Fachinfo-Invoices' do
248         plug = FachinfoInvoicer.new(@app)
249         plug.run(day)
250         if report = plug.report
251           log = Log.new(day)
252           log.date_str = day.strftime("%d.%m.%Y")
253           log.report = report
254           log.notify("Fachinfo-Uploads")
255         end
256       end
257 		end
258 		def mail_feedback_stats
259       safe_export 'Mail Feedback-Statistics' do
260         mail_stats('feedback')
261       end
262 		end
263 		def mail_notification_stats
264 			file = @app.notification_logger.create_csv(@app)
265 			headers = {
266 				:filename => 'notifications.csv',
267 				:mime_type => 'text/csv',
268 				:subject => 'Täglicher CSV-Export der Notifications', 
269 			}
270 			Log.new(@@today).notify_attachment(file, headers)
271 		end
272 		def mail_patinfo_invoices
273       safe_export 'Mail Patinfo-Invoices' do
274         PatinfoInvoicer.new(@app).run
275       end
276 		end
277     def export_price_history_csv
278       safe_export 'price_history.csv' do
279         plug = CsvExportPlugin.new(@app)
280         plug.export_price_history
281       end
282       EXPORT_SERVER.clear
283       sleep(30)
284     end
285 		def mail_stats(key)
286 			date = @@today
287 			if(date.mday < 8)
288 				date = date << 1
289 			end
290 			log = Log.new(date)
291 			begin
292 				log.report = File.read(LogFile.filename(key, date))
293 			rescue StandardError => e
294 				log.report = ([
295 					"Nothing to Report.",
296 					nil, 
297 					e.class,
298 					e.message 
299 				] + e.backtrace).join("\n")
300 			end
301 			log.notify("#{key.capitalize}-Statistics")
302 		end
303     def mail_swissmedic_notifications
304       SwissmedicPlugin.new(@app).mail_notifications
305     end
306     def safe_export subject, &block
307       block.call
308 		rescue StandardError => e
309       EXPORT_SERVER.clear rescue nil
310 			log = Log.new(@@today)
311 			log.report = [
312 				"Error: #{e.class}",
313 				"Message: #{e.message}",
314 				"Backtrace:",
315 				e.backtrace.join("\n"),
316 			].join("\n")
317 			log.notify("Error Export: #{subject}")
318       sleep(30)
319     end
320 	end
321 end

Generated on Tue Feb 08 09:09:41 +0100 2011 with rcov 0.9.8