view · edit · sidebar · attach · print · history

20110818-import-drb-connection-migel-drb-server

<< | Index | >>


  1. Log update migel data last night
  2. Client for migel drb server
    1. Test DRb client to oddb.org
    2. Test DRb client to migeld
    3. Implement a client in oddb.org
    4. Replace ODDB::Migel::Items by Migel::Model::Product instances

Goal/Estimate/Evaluation
  • Migel drb client in oddb.org / 70% / 70%
Milestones
  • Refer to code de.oddb.org
  • Implement a client
    1. Replace all the migel methods in oddbapp.rb
    2. Wrap migel classes in oddb.org
Summary
Commits
ToDo Tomorrow
  • Importer.rb, accessor, multilingual update I have to change the other method if I change the model
  • prune_old_revision
  • The other language (fr)
  • Migel::Util::Swissindex.search_migel_table(pharmacode, language)
  • Refactoring (in particluar, attr_accessor)
  • Testcases oddb.org

Log update migel data last night

Note

  • It is still running
  • It will take more about 6 hours
...
389 / 571       Estimate total: 17.79 [h] It will be done in: 5.67 [h]
390 / 571       Estimate total: 17.77 [h] It will be done in: 5.63 [h]
391 / 571       Estimate total: 17.74 [h] It will be done in: 5.59 [h]
392 / 571       Estimate total: 17.70 [h] It will be done in: 5.55 [h]
393 / 571       Estimate total: 17.66 [h] It will be done in: 5.51 [h]

Client for migel drb server

Check code

masa@masa ~/ywesee/de.oddb.org $ grep -r DRb lib/
lib/oddb/html/state/drugs/global.rb:    block.call DRbObject.new(nil, uri)
lib/oddb/html/state/drugs/global.rb:        remote.remote_comparables(ODBA::DRbWrapper.new(package))
lib/oddb/html/state/drugs/global.rb:    if(pac = DRbObject._load(Marshal.dump([uri, ref])))

masa@masa ~/ywesee/de.oddb.org $ grep -r remote lib/
lib/oddb/remote/object.rb:      def initialize(source, remote)
lib/oddb/remote/object.rb:        @remote = remote

lib/oddb/config.rb:    'remote_databases'      => [],
lib/oddb/export/server.rb:        if uri = ODDB.config.remote_databases.first
...

Test DRb client

DRb experiment

  • oddb.org/src/util/oddbapp.rb
 def masa
   'masa'
  end
  • test.rb
require 'drb'

URI = 'druby://localhost:10000'  # oddbd
server = DRbObject.new_with_uri(URI)
p server.masa

Run

  • oddb.org/bin/oddbd

Result

$ ruby test.rb 
"masa"

Experiment

  • oddb.org/src/util/oddbapp.rb
  def masa
    ODBA::DRbWrapper.new(ODDB::Package.find_by_pharmacode('223332'))
  end
  • test.rb
require 'drb'

URI = 'druby://localhost:10000'  # oddbd
server = DRbObject.new_with_uri(URI)
p server.masa.pharmacode
p server.masa.name

Result

$ ruby test.rb 
DRb::DRbObject
"223332"
"Inderal 10 mg, Tabletten"

Test DRb client to migeld

Experiment

  • lib/migel/util/server.rb
      def group
        ODBA::DRbWrapper.new(Migel::Model::Group)
      end
      def subgroup
        ODBA::DRbWrapper.new(Migel::Model::Subgroup)
      end
      def migelid
        ODBA::DRbWrapper.new(Migel::Model::Migelid)
      end 
      def product
        ODBA::DRbWrapper.new(Migel::Model::Product)
      end
  • test.rb
require 'drb'

URI = 'druby://localhost:33000'   # migeld
migel = DRbObject.new_with_uri(URI)

p migel.group.all.length
p migel.group.find_by_code('01').subgroups[0].migelids[0].products[0].article_name
p migel.group.find_by_code('01').subgroups[0].migelids[0].products[0].pharmacode
p migel.product.find_by_pharmacode('1624501').article_name

Run

  • bin/migeld

Result

$ ruby test.rb 
20
"AMEDA Einhandmilchpumpe mit Flexishield"
"1624501"
"AMEDA Einhandmilchpumpe mit Flexishield"

Implement a client in oddb.org

Experiment

  • src/model/migel/group.rb
require 'drb'
module ODDB
  module Migel
    MIGEL_URI = 'druby://localhost:33000'
    REMOTE = DRbObject.new_with_uri(MIGEL_URI)
    class Group
...

      def migel_code
        @code
        REMOTE.group.find_by_code(@code).code
      end

Run

  • bin/oddbd
  • bin/migeld

Result

ch.oddb> migel_groups.values[0].migel_code
-> 99

Next

  • How to wrap a remote migel class
  • I should refer to de.oddb.org, Remote classes

Note

  • I should replace all the migel methods in oddbapp.rb
  • State and View classes currently depend on Migel classes in oddb.org

Replace migel methods in oddbapp.rb

  • src/util/oddbconf.rb
  MIGEL_URI = 'druby://localhost:33000'
  • src/util/oddbapp.rb
class OddbPrevalence
#  def migel_count
#    @migel_count ||= migel_products.size  
#  end
end

module ODDB
  class App < SBSM::DRbServer
...
    MIGEL_SERVER = DRb::DRbObject.new(nil, MIGEL_URI)
...
    def migel_count
      MIGEL_SERVER.migelid.all.length
    end

Run

  • bin/oddbd
  • bin/migeld

Result

ch.oddb> migel_count
-> 571

ToDo Next: (except for create_ and delete_ methods) replace methods in oddbapp.rb

  • migel_count
  • each_migel_product
  • migel_group
  • migel_product
  • migel_products
  • search_migel_alphabetical
  • search_migel_products

Replace ODDB::Migel::Items by Migel::Model::Product instances

  • oddb.org/src/util/oddbapp.rb
require 'remote/multilingual'
..
    def search_migel_products(query, lang)
      migel_code = query.split(/(\d\d)/).select{|s| !s.empty?}.join('.')
      MIGEL_SERVER.migelid.search_by_migel_code(migel_code)
    end
  • oddb.org/src/remote/multilingual.rb
  • migel/lib/migel/model/migelid.rb
# This is necessary for a drb client connection from ch.oddb.org
# because ODDB::Migel::Product@items is a Hash, not an Array.
class Array
  def values
    self
  end
end

module Migel
  module Model
    class Migelid < Migel::ModelSuper
..
     multilingual :unit
..
  • migel/lib/migel/importer.rb
    def update_migelid(id,  subgroup, row, language)
...
      multilingual_data = {
        :name            => name,
        :migelid_text    => (migelid_text unless migelid_text.empty?),
        :limitation_text => (limitation_text unless limitation_text.empty?),
        :unit => (unit unless unit.empty?),
      }
...

Result

  • success

Note

  • I need to reset migel database when I change migel class structure
  • I should refactor ODDB::Migel::Item

Next

  • Replace search method in oddb.org/src/state/global.rb (Search button function in oddb.org)

Note

  • /usr/lib64/ruby/1.8/delegate.rb
  def respond_to?(m, include_private = false)
    return true if super
if self.__getobj__.is_a?(DRb::DRbObject)
  return self.__getobj__.send(m)
else
    return self.__getobj__.respond_to?(m, include_private)
end
  end
view · edit · sidebar · attach · print · history
Page last modified on August 22, 2011, at 07:24 AM