view · edit · sidebar · attach · print · history

20110722-replace-user-stock-ids-bbmb

<< | Index | >>


  1. Replace stock ids
  2. Adjust import process for new customer file format
  3. Adjust import process for new product file format
  4. Summary

Goal/Estimate/Evaluation
  • Replace user and stock ids / 90% /
Milestones
  • prepare the mapping file for the new data
  • replace stock ids
    1. make a replacement method
    2. run and check result
  • adjust the import method for the new customer file format
  • adjust the import method for the new product file format
Summary
Commits

Replace stock ids

Email

Prepare the mapping file for the new stock ids

1. Pickup gag, ean, and allo ids Attach:pickup_gag_ean_allo_ids.rb.20110722.txt

 ruby pickup_gag_ean_allo_ids.rb > gag_ena_allo_ids.csv

2. Pickup actual allo ids Attach:pickup_actual_allo_ids.rb.20110722.txt

 ruby pickup_actual_allo_ids.rb > actual_allo_ids.csv

3. Pickup actual gag, ean, and allo ids Attach:pickup_actual_gag_ean_allo_ids.rb.20110722.txt

 ruby pickup_actual_gag_ean_allo_ids.rb > actual_gag_ean_allo_ids.csv

Design of the replacement algorithm

Review

Experiment

  • src/model/stock.rb
    def update_products2(values)
      p values
      values.each { |value|
        key = value[:old_uid]
        product = @products[key]
        #value.delete(:uid)
        product.update(value)
        begin
          @products.store(product.uid, product)
          @products.delete(key)
        rescue MissingDataException
          @errors << product
        end
      } if values
    end
  • src/util/bbmbapp.rb
  def update_stock(gid, updates)
    #@prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand.new(gid, updates)))
    @prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand2.new(gid, updates)))
  end
  • src/transaction/stock.rb
class UpdateStockCommand2
  def initialize(gid, values)
    @values = values
    @gid = gid
  end
  def execute(app)
    reseller = app.resellers[@gid]
    reseller.update_products2(@values)
  end
end
  • src/model/reseller.rb
    def update_products2(values)
      stock.adjust(product_key, searchable)
      stock.update_products2(values)
    end

Run

masa@masa ~/ywesee/bbmb.ch $ bin/admin
ch.bbmb.globopharm> update_stock('1', [{:old_id => '946005', :uid => '123456', :article_number => '123456'}])
-> 0

Result (Check the searching of product by using a customer id)

  • Looks good

Confirmation

Before update

ch.bbmb.globopharm> resellers['1'].product('53000002').uid
-> undefined method `uid' for nil:NilClass
ch.bbmb.globopharm> resellers['1'].product('946005').uid
-> 946005
ch.bbmb.globopharm> resellers['1'].product('946005').article_descr
-> Tysabri

After update

ch.bbmb.globopharm> resellers['1'].product('946005').uid
-> undefined method `uid' for nil:NilClass
ch.bbmb.globopharm> resellers['1'].product('53000002').uid
-> 53000002
ch.bbmb.globopharm> resellers['1'].product('53000002').article_descr
-> Tysabri

Replace method

src/util/bbmbapp.rb

  def replace_article_ids_gag_to_alloga(map_file = nil, reseller_gid = '1')
    unless map_file
      return 'set the path to the mapping file'
    end
    count = 0
    File.readlines(map_file).each do |line|
      ids = line.chomp.split(/;/)
      gag_id    = ids[0]
      ean_code  = ids[1]
      alloga_id = ids[2]
      if resellers[reseller_gid].product(gag_id) and alloga_id
          updates = [{:old_uid => gag_id, :uid => alloga_id, :article_number => alloga_id, :article_ean13 => ean_code}]
          update_stock(reseller_gid, updates)
          count += 1
      end
    end
    count
  end

Run

masa@masa ~/ywesee/bbmb.ch $ bin/admin
ch.bbmb.globopharm> replace_article_ids_gag_to_alloga '/home/masa/work/new_data/actual_gag_ean_allo_ids.csv'
-> 284

Note

  • Looks good
  • The archive data shows still old ids but the bookmark and the order shows the new article ids

Adjust import process for new customer file format

Experiment

  • src/custom/behavior.rb
    USER_MAP = {
      0   =>  :customer_id,
      1   =>  :customer_ean13,
      2   =>  :group_short,
      3   =>  :organisation,
      4   =>  :drtitle,
      5   =>  :address1,
      7   =>  :plz,
      8   =>  :location,
      9   =>  :phone_business,
      10  =>  :fax,
      11  =>  :email,
    }

Run

  • restore all the files in log/mnemonic
  • restart bin/bbmbd
  • replace user id and update_users
masa@masa ~/ywesee/bbmb.ch $ bin/admin
ch.bbmb.globopharm> replace_user_ids_gag_to_alloga '/home/masa/work/new_data/gagallkd_new.csv'
-> 169
ch.bbmb.globopharm> update

Result

  • Not completely succeeded

Confirmation

  • A customer (hospital user) cannot login the system with the same password

Adjust import process for new product file format

  • src/custome/behavior.rb
    ARTICLE_MAP = {
      1   =>  :article_number,
      2   =>  :article_ean13,
      3   =>  :article_descr,
      8   =>  :article_price,
    }

Run

  • restore all the files in log/mnemonic
  • restart bin/bbmbd
  • replace user id and update_users
masa@masa ~/ywesee/bbmb.ch $ bin/admin
ch.bbmb.globopharm> replace_article_ids_gag_to_alloga '/home/masa/work/new_data/actual_gag_ean_allo_ids.csv'
ch.bbmb.globopharm> update

Summary

Log

1. restore log files

masa@masa ~/ywesee/bbmb.ch/log/mnemonic $ rm *.*
masa@masa ~/ywesee/bbmb.ch/log/mnemonic $ cp ~/work/mnemonic_local_update_all_kund_bak/*.* .

2. Run bin/bbmbd

3. Switch update method for stock

  def update_stock(gid, updates)
    @prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand.new(gid, updates)))
    #@prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand2.new(gid, updates)))
  end

4. Replace new ids of user and stock

ch.bbmb.globopharm> replace_customer_ids_gag_to_alloga '/home/masa/work/new_data/gagallkd_new.csv'
-> 169
ch.bbmb.globopharm> replace_article_ids_gag_to_alloga '/home/masa/work/new_data/actual_gag_ean_allo_ids.csv'
-> 284

5. Switch update method for stock

  def update_stock(gid, updates)
    #@prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand.new(gid, updates)))
    @prevalence.executeTransaction(BBMB::Transaction.new(UpdateStockCommand2.new(gid, updates)))
  end

6. Restart bin/bbmbd

7. Replace new user and stock files on the ftp server

8. Update

ch.bbmb.globopharm> update
  • patch file

Attach:git_diff.20110722.txt

Note

  • Login with the same password failed after the updating of the new user and stock file (Customers.csv, Items.csv) (this should be resolved next week)
  • all the :supplier_name is replaced to :company_name
  • :company_name is the data that belongs to Stock class (:supplier_name belongs to Supplier class)
  • The Supplier class is no more used, which is replaced by the :company_name
  • The update method for stock should be updated more smartly
view · edit · sidebar · attach · print · history
Page last modified on July 22, 2011, at 05:03 PM