view · edit · sidebar · attach · print · history

20110509-swissindex_plugin

<< | Index | >>


  1. update_package_trade_status log
  2. Add report process

Goal/Estimate/Evaluation
  • SwissindexPlugin / 90% / 90%
Milestones
  • Report process
Summary
Commits

update_package_trade_status log

Error

ch.oddb> Updater.new(self).update_package_trade_status_by_swissindex true
-> undefined local variable or method `pharmacode' for #<ODDB::SwissindexPlugin:0x7f6b130a0db8>
init system
init system: 4.21494
setup drb-delegation
reset
reset: 4.226361
system initialized
initialized: 4.226438
WARNING:  nonstandard use of \' in a string literal
LINE 3:         AND search_term = 'fraxiparine multi, 9\'500 u.i. an...
                                  ^
HINT:  Use '' to write quotes in strings, or use the escape string syntax (E'...').
failsafe rescued NameError < StandardError
undefined local variable or method `pharmacode' for #<ODDB::SwissindexPlugin:0x7f6b130a0db8>
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1418:in `_admin'
/home/masa/ywesee/oddb.org/src/plugin/swissindex.rb:117:in `each'
/home/masa/ywesee/oddb.org/src/plugin/swissindex.rb:117:in `update_pharmacode_by_swissindex'
/home/masa/ywesee/oddb.org/src/plugin/swissindex.rb:101:in `update_package_trade_status'
/home/masa/ywesee/oddb.org/src/util/updater.rb:505:in `update_package_trade_status_by_swissindex'
(eval):1:in `_admin'
/home/masa/ywesee/oddb.org/src/util/failsafe.rb:9:in `call'
/home/masa/ywesee/oddb.org/src/util/failsafe.rb:9:in `failsafe'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1417:in `_admin'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1415:in `initialize'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1415:in `new'
/home/masa/ywesee/oddb.org/src/util/oddbapp.rb:1415:in `_admin'
/usr/lib64/ruby/1.8/drb/drb.rb:1555:in `__send__'
/usr/lib64/ruby/1.8/drb/drb.rb:1555:in `perform_without_block'
/usr/lib64/ruby/1.8/drb/drb.rb:1515:in `perform'
/usr/lib64/ruby/1.8/drb/drb.rb:1589:in `main_loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1585:in `loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1585:in `main_loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1581:in `start'
/usr/lib64/ruby/1.8/drb/drb.rb:1581:in `main_loop'
/usr/lib64/ruby/1.8/drb/drb.rb:1430:in `run'
/usr/lib64/ruby/1.8/drb/drb.rb:1427:in `start'
/usr/lib64/ruby/1.8/drb/drb.rb:1427:in `run'
/usr/lib64/ruby/1.8/drb/drb.rb:1347:in `initialize'
/usr/lib64/ruby/1.8/drb/drb.rb:1627:in `new'
/usr/lib64/ruby/1.8/drb/drb.rb:1627:in `start_service'
bin/oddbd:38

Log

The error part (src/plugin/swissindex.rb#update_pharmacode_by_swissindex)

    def update_pharmacode_by_swissindex(update_pharmacode_list, delete_pharmacode_list, logging = false)
      log_dir  = File.expand_path('../../log/oddb/debug', File.dirname(__FILE__))
      log_file = File.join(log_dir, 'update_pharmacode_by_swissindex.log')
      log = open(log_file, 'w')
      if logging
        log.print Time.now, "\n"
        log.print "update_pharmacode\n"
      end
      update_pharmacode_list.each do |pack, pharmacode|
        @app.update(pack.pointer, {:pharmacode => pharmacode}, :bag)
        log.print pack.barcode, "\t", pharmacode, "\n" if logging
      end

      log.print "\ndelete_pharmacode\n" if logging
      delete_pharmacode_list.each do |pack|
        @app.update(pack.pointer, {:pharmacode => nil}, :bag)
        log.print pack.barcode, "\t", pharmacode, "\n" if logging
      end
      log.close
    end

Debug

    def update_pharmacode_by_swissindex(update_pharmacode_list, delete_pharmacode_list, logging = false)
      log_dir  = File.expand_path('../../log/oddb/debug', File.dirname(__FILE__))
      log_file = File.join(log_dir, 'update_pharmacode_by_swissindex.log')
      log = open(log_file, 'w')
      if logging
        log.print Time.now, "\n"
        log.print "update_pharmacode\n"
      end
      update_pharmacode_list.each do |pack, pharmacode|
        @app.update(pack.pointer, {:pharmacode => pharmacode}, :bag)
        log.print pack.barcode, "\t", pharmacode, "\n" if logging
      end

      log.print "\ndelete_pharmacode\n" if logging
      delete_pharmacode_list.each do |pack, pharmacode|
        @app.update(pack.pointer, {:pharmacode => nil}, :bag)
        log.print pack.barcode, "\t", pharmacode, "\n" if logging
      end
      log.close
    end

Check the algorithm again

      if(results.size == 0 && !pack.out_of_trade)
        update_package_data(pack, {:out_of_trade => true})
      elsif(results.size == 1 && pack.out_of_trade)
        data = {:out_of_trade => false, :refdata_override => false}
        update_package_data(pack, data)
      else

Logic

  • IF a search result is NOT FOUND AND 'out_of_trade' of the package in oddb is FALSE
    • the 'out_of_trade' becomes TRUE
  • IF a search result is FOUND AND 'out_of_trade' of the package in oddb is TRUE
    • the 'out_of_trade' becomes FALSE and 'refdata_override' becomes FALSE at the same time

Add report process

3 kinds of report methods are prepared in src/util/updater.rb

  1. update_immediate
  2. update_simple
  3. update_notify_simple

Note

  • The functions of the 3 methods above are almost the same. The 'update_notify_simple' can pass method's arguments to a plugin class.
  • The return value (Array) of 'report' method becomes a content of report mail in a plugin class

Updates

  • src/plugin/swissindex.rb
  • src/util/updater.rb

Run (It takes 6 hours)

 masa@masa ~/ywesee/oddb.org $ bin/admin
 ch.oddb> Updater.new(self).update_package_trade_status_by_swissindex true

Result

  • Email

Replace logging process

Sample (Logging class)

require 'fileutils'
class Logging
  @@flag = false
  def Logging.flag=(bool)
    @@flag = bool
  end
  def Logging.flag
    @@flag
  end
  def Logging.start(file)
    if @@flag
      FileUtils.mkdir_p(File.dirname(file))
      log_file = File.open(file, 'w')
      log_file.print "# ", Time.now, "\n"
      yield(log_file)
      log_file.close
    end
  end
  def Logging.append(file)
    if @@flag
      FileUtils.mkdir_p(File.dirname(file))
      log_file = File.open(file, 'a')
      yield(log_file)
      log_file.close
    end

  end
end

Logging.start('testdir/test.dat') do |log|
  log.print "test1\n"
end

Logging::flag = true

Logging.start('testdir/test.dat') do |log|
  log.print "test2\n"
end
Logging.append('testdir/test.dat') do |log|
  log.print "test3\n"
end

Result

masa@masa ~/work $ ruby test.rb
masa@masa ~/work $ cat testdir/test.dat 
# Mon May 09 13:56:20 +0200 2011
test2
test3

Updated

Run

  • bin/admin
 ch.oddb> Updater.new(self).update_package_trade_status true
 ch.oddb> Updater.new(self).migel_nonpharma 'home/masa/work/pharmacode_list.dat'

Note

  • If the log file for debug is not necessary, just execute it without argument
 ch.oddb> Updater.new(self).update_package_trade_status

Result

  • Email
  • Email

Testcases for SwissindexPlugin

view · edit · sidebar · attach · print · history
Page last modified on May 09, 2011, at 04:36 PM