<< Masa.20110224-export-order-xls-bbmb | 2011 | Masa.20110222-testcases-updater-oddb_org >>
Goal
Emails from Davatz-san
In order to execute bin/admin in bbmb
$#!/usr/bin/env ruby $: << File.expand_path('../lib', File.dirname(__FILE__))
Run bin/bbmbd
masa@masa ~/ywesee/bbmb $ bin/bbmbd config="config.yml"
(in order to login it locally, bin/yusd bin/yusd server_url="druby://localhost:12001")
Result
masa@masa ~/ywesee/bbmb $ bin/admin ch.bbmb>
Note
Memo
Experiment
def masa "masamasa" end
Result
masa@masa ~/ywesee/bbmb $ bin/admin ch.bbmb> masa -> masamasa
Experiment (output the number of orders)
def export_all_order BBMB.persistence.all(Model::Order).length end
Result
ch.bbmb> export_all_order -> 18945
Note
Necessary information for the xls file
Experiment (output all the order information)
def export_all_order t = Time.now commits = [] count = 0 open("/home/masa/work/test.dat", "w") do |f| BBMB.persistence.all(Model::Order).each_with_index do |order, i| if customer = order.customer && order.commit_time && order.commit_time >= Time.local(2010,1,1) order.each do |position| #commits << [order.commit_time, position.article_number, position.description, order.customer_id, customer.organisation] commits << [order.commit_time, position.article_number, position.description, '', ''] end count += 1 end =begin if customer = order.customer commits << [order.commit_time, customer.customer_id, customer.organisation] else commits << [order.commit_time, '', ''] end =end #count = i #p count if count%100==0 break if count==10 end #f.print commits.select{|x| x != nil}.sort.join("\n") new_commits = [] commits.each do |x| temp = "" if date = x[0] temp << date.strftime("%Y%m%d") + "\t" else temp << "00000000\t" end temp << x[1].to_s + "\t" + x[2].to_s + "\t" + x[3].to_s + "\t" + x[4].to_s + "\n" new_commits << temp end f.print new_commits.sort.reverse # f.print commits.map{|x| x[0].strftime("%Y%m%d") + ", " + x[1].to_s + ", " + x[2].to_s}.join("\n"), "\n" end return (Time.now.to_f - t.to_f).to_i.to_s + " " + count.to_s =begin BBMB.persistence.all(Model::Order).select do |order| end end =end end alias :ex :export_all_order
Result
20101202 44019215 LADONNA ... 20101202 44018300 Losartan ... 20101202 44014764 FELODIPIN ... ...
Note
suspend
Goal
Procedure
$: << File.expand_path("../lib", File.dirname(__FILE__))
---
domain: ch.bbmb.xmlconv.masa
log_level: DEBUG
db_name: xxx_xmlconv
db_user: xxx
default_filename: "s_%s.txt"
server_url: "druby://localhost:12006"
masa@masa ~/ywesee/xmlconv $ bin/xmlconvd config="etc/xmlconv.yml"
Result
... I, [2011-02-23T11:27:18.881560 #6376] INFO -- XmlConv2: drb-service listening on druby://localhost:12006
Note
Experiment (test bin/admin command)
masa@masa ~/ywesee/xmlconv $ bin/admin /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:42:in `method_missing': undefined method `domain' for #<RCLConf::RCLConf:0x7f77cf495888> (NoMethodError) from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:42:in `fetch' from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:42:in `method_missing' from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:41:in `fetch' from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:41:in `method_missing' from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:40:in `fetch' from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:40:in `method_missing' from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:39:in `fetch' from /usr/lib64/ruby/site_ruby/1.8/rclconf/rclconf.rb:39:in `method_missing' from bin/admin:23
Update
defaults = { 'domain' => 'ch.xmlconv', ...
Restart xmlconvd
masa@masa ~/ywesee/xmlconv $ bin/xmlconvd config="etc/xmlconv.yml"
Run bin/admin
masa@masa ~/ywesee/xmlconv $ bin/admin ch.xmlconv>
Note
Experiment (add a new command to bin/admin)
def masa 'masamasa' end
Restart xmlconvd
Result
masa@masa ~/ywesee/xmlconv $ bin/admin server_url="druby://localhost:12006" ch.xmlconv> masa -> masamasa
Note
Experiment
def masa open("/home/masa/work/test.dat", "w") do |f| self.transactions.reverse.each do |t| if t.commit_time >= Time.local(2010,1,1) f.print t.output end end end end
xmlconv.sort.rb
File.readlines('test.dat').collect{|x| ret = "" if x =~ /(,\d+,)(\d\d)(\d\d)(2010)(,.+,)$/\ or x =~ /(,\d+,)(\d\d)(\d\d)(2011)(,.+,)$/ ret = $1 + $4 + $3 + $2 + $5 end ret + "\n" }.sort.each do |line| print line end
add_kunden_artikel.rb
kunden1 = {} kunden2 = {} File.readlines('txt2xls/backup/Kunden.txt').each do |line| x = line.split(/\t/) # print x[0], ",", x[1], ",", x[6], "\n" kunden1[x[0].to_i] = x[6] kunden2[x[0].to_i] = x[6] end artikel1 = {} artikel2 = {} File.readlines('txt2xls/backup/Artikel.txt').each do |line| x = line.split(/\t/) #print x[0], ",", x[3], ",", x[2], "\n" artikel1[x[4].to_i] = x[2] artikel2[x[3].to_i] = x[2] end File.readlines('xmlconv.sorted.dat').each do |line| x = line.split(/,/) kunden = "" if kunden1.keys.include?(x[1].to_i) kunden = kunden1[x[1].to_i] else kunden2.keys.include?(x[1].to_i) kunden = kunden2[x[1].to_i] end artikel = "" if artikel1.keys.include?(x[4].to_i) artikel = artikel1[x[4].to_i] else artikel2.keys.include?(x[5].to_i) artikel = artikel2[x[5].to_i] end x.map!{|z| z || ""} artikel ||="" kunden ||="" print "," + x[1] + "," + kunden + "," +\ x[2] + "," + x[3] + "," + x[4] + "," + artikel + "," + \ "," + x[5] + "," + x[6] + "," + x[7] + "," + x[8] +\ "," + x[9] + "," + x[10] end