<< | Index | >>
suspend
Goal/Estimate/Evaluation:
Mon Sep 19 11:40:59 2011: migel Migel::Util::Importer#save_all_products Saved file: /home/masa/ywesee/migel_dev/data/csv/hogehoge.csv Total 571 Migelids (Saved 356 / Unsaved 215): Saved 30742 Products: Save time length: 7.51 [h]
Note
Problem
Task
Experiment
def report(lang = 'de') lang = lang.downcase [ "Saved file: #{@saved_csv_file}", sprintf("Total %5i Migelids (%5i Migelids have products / %5i Migelids have no products)", migel_code_list.length, @migel_codes_with_products.length, @migel_codes_without_products.length), "Saved #{@saved_products} Products", "Save time length: #{@save_time_length}", ].concat([ '', "Migelids with products (#{@migel_codes_with_products.length})" ]).concat(@migel_codes_with_products.sort.map{|migel_code| "http://ch.oddb.org/#{lang}/gcc/migel_search/migel_product/#{migel_code}" }).concat([ '', "Migelids without products (#{@migel_codes_without_products.length})" ]).concat(@migel_codes_without_products.sort.map{|migel_code| "http://ch.oddb.org/#{lang}/gcc/migel_search/migel_product/#{migel_code}" }) end
Run
migel> Migel::Util::Importer.new.reported_save_all_products('test.csv', 'de', true) -> Array
Result (Short example)
Tue Sep 20 08:38:11 2011: migel Migel::Util::Importer#reported_save_all_products(de) Saved file: /home/masa/ywesee/migel_dev/data/csv/test.csv Total 571 Migelids ( 5 Migelids have products / 1 Migelids have no products) Saved 130 Products Save time length: 46.13 [m] Migelids with products (5) http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.01.00.1 http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.02.00.2 http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.02.02.2 http://ch.oddb.org/de/gcc/migel_search/migel_product/01.02.01.00.2 http://ch.oddb.org/de/gcc/migel_search/migel_product/01.02.01.01.1 Migelids without products (1) http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.02.01.2
Reference
Note
Experiment
def Mail.notify_admins_attached(subject, lines, file) config = Migel.config recipients = config.admins # Main part mail = TMail::Mail.new mail.subject = subject mail.date = Time.now mail.mime_version = '1.0' # Text part text = TMail::Mail.new text.set_content_type('text', 'plain', 'charset'=>'UTF-8') text.body = lines.join("\n") mail.parts.push text # File part attach = TMail::Mail.new attach.body = Base64.encode64 File.read(file) # attach.set_content_type('image','jpg','name' => file) attach.set_content_disposition('attachment', 'filename' => File.basename(file)) attach.transfer_encoding = 'base64' mail.parts.push attach sendmail(mail.encoded, config.smtp_user, recipients) end
Run
migel> Migel::Util::Mail.notify_admins_attached('Hoge', ['morning','hello','bye'], '/home/masa/work/hoge.gz') -> mhatakeyama@ywesee.com
Result
morning hello bye ---- hoge.gz hoge.gz 1K download
Reference
test.rb
require 'zlib' orig = 'hoge' Zlib::GzipWriter.open('hoge.gz', Zlib::BEST_COMPRESSION) do |gz| gz.mtime = File.mtime(orig) gz.orig_name = orig gz.puts File.open(orig, 'rb'){|f| f.read } end
Run
masa@masa ~/work $ cat > hoge hogehoge foobaa masa
masa@masa ~/work $ ruby test.rb
Result
masa@masa ~/work $ zcat hoge.gz hogehoge foobaa masa
Experiment
def reported_save_all_products(file_name = 'migel_products_de.csv', lang = 'de', estimate = false) @csv_file = File.join(@data_dir, file_name) lines = [ sprintf("%s: %s %s#reported_save_all_products(#{lang})", Time.now.strftime('%c'), Migel.config.server_name, self.class) ] save_all_products(@csv_file, lang, estimate) compressed_file = compress(@csv_file) lines.concat report(lang) rescue Exception => err lines.push(err.class.to_s, err.message, *err.backtrace) lines.concat report ensure subject = lines[0] #Mail.notify_admins(subject, lines) Mail.notify_admins_attached(subject, lines, compressed_file) end def compress(file) compressed_filename = file + '.gz' Zlib::GzipWriter.open(compressed_filename, Zlib::BEST_COMPRESSION) do |gz| gz.mtime = File.mtime(file) gz.orig_name = file gz.puts File.open(file, 'rb'){|f| f.read } end compressed_filename end
Run
migel> Migel::Util::Importer.new.reported_save_all_products('test.csv', 'de', true) -> Array
Result
Tue Sep 20 10:32:21 2011: migel Migel::Util::Importer#reported_save_all_products(de) Saved file: /home/masa/ywesee/migel_dev/data/csv/test.csv Total 571 Migelids ( 3 Migelids have products / 1 Migelids have no products) Saved 36 Products Save time length: 40.93 [m] Migelids with products (3) http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.01.00.1 http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.02.00.2 http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.02.02.2 Migelids without products (1) http://ch.oddb.org/de/gcc/migel_search/migel_product/01.01.02.01.2 ---- test.csv.gz test.csv.gz 2K download
Note
Testcases (keep in mind)
Problem
Task
There are two processes to search migel items
Note
The search process (search box)
def search ... when :migel if result = @session.search_migel_products(query) and !result.empty? State::Migel::Result.new(@session, result) elsif result = @session.app.search_migel_items(query, @session.language) and !result.empty? product = StubProduct.new(result) sort_key = @session.user_input(:sortvalue) || @session.user_input(:reverse) reverse = @session.user_input(:reverse) ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product, sort_key, reverse)) else State::Migel::Result.new(@session, []) end ...
Search order
Experiment
when :migel if result = @session.search_migel_products(query) and !result.empty? # masa p "@session.search_migel_products(query)" State::Migel::Result.new(@session, result) elsif result = @session.app.search_migel_items(query, @session.language) and !result.empty? p "@session.app.search_migel_items(query, @session.language)" p "result.length = " p result.length product = StubProduct.new(result) p "done StubProduct.new" sort_key = @session.user_input(:sortvalue) || @session.user_input(:reverse) reverse = @session.user_input(:reverse) p "before view" ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product, sort_key, reverse)) else State::Migel::Result.new(@session, []) end
Search 'SIGVARIS'
Note
Solution
Experiment
when :migel if result = @session.search_migel_products(query) and !result.empty? State::Migel::Result.new(@session, result) elsif result = @session.app.search_migel_items(query, @session.language) and !result.empty? #product = StubProduct.new(result) product = StubProduct.new(result[0,200]) sort_key = @session.user_input(:sortvalue) || @session.user_input(:reverse) reverse = @session.user_input(:reverse) ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product, sort_key, reverse)) else State::Migel::Result.new(@session, []) end
Search
Result
Problem
Experiment
def migel_search # masa start_time = Time.now p start_time if migel_code = @session.user_input(:migel_code) and product = @session.search_migel_products(migel_code).first p "products.length = " p product.products.length sort_key = @session.user_input(:sortvalue) || @session.user_input(:reverse) reverse = @session.user_input(:reverse) p "time = " p Time.now - start_time p "before view" ODDB::State::Migel::Items.new(@session, ODDB::Migel::Items.new(product, sort_key, reverse))
def article_name(model = @model, session = @session) p Time.now
Search
Result (Log)
1316519217 getin migel_search_by_migel_code products.length = 567 time = 0.003927 before view ... 1316519225 ... 1316519228 (end view)
Note
Hypothesis
Solution
Experiment
if product and items = product.items
@sortvalue = sortvalue
@list = items.values[0,200]
Search
Result (Log)
1316520431 "getin migel_search_by_migel_code" "products.length = " 567 "time = " 0.005834 "before view" 1316520433 ... 1316520435
Note
migel> open('/home/masa/work/test.dat','w'){|out| out.print migelids.values.map{|m| if products = m.products then m.migel_code + "\t" + products.length.to_s end}.join("\n")}
migel code list (over 300 products)
15.10.02.01.1 312 29.03.01.00.1 367 15.30.01.00.1 369 17.01.03.00.1 404 05.04.05.00.1 412 15.01.01.00.1 450 05.04.02.00.1 557 17.02.02.00.1 567 29.02.01.00.1 924 05.07.03.00.1 1051 29.01.01.00.1 1634 17.04.02.00.1 3293 17.01.02.00.1 3345 17.03.02.00.1 6920
Note
Reference
Experiment
def previous 'previous' end def next 'next' end
class SubHeader < HtmlGrid::Composite .. COMPONENTS = { ... [1,0] => :pages, ... def pages(model, session=@session) pages = [] args = {} View::Pager.new(pages, @session, self, :search, args) end
def page page = ODDB::State::PageFacade.new(0) page.model = @model end
Access
Result
Experiment
def pages(model, session=@session) pages = @session.state.pages args = {} View::Pager.new(pages, @session, self, :search, args) end
class Items < State::Migel::Global attr_reader :pages def init @pages = [] page = 0 count = 0 @model.each { |product| @pages[page] ||= ODDB::State::PageFacade.new(page) @pages[page].push(product) count += 1 if(count >= 2) page += 1 count = 0 end } end ... def page page = @pages[0] page.model = @model page end
Access
Result
Next
Experiment
def init @pages = [] page = 0 count = 0 @model.each { |product| @pages[page] ||= ODDB::State::PageFacade.new(page) @pages[page].push(product) count += 1 if(count >= 2) page += 1 count = 0 end }@filter = Proc.new { |model|
page()
}
end def pagepage = @pages[1]
page.model = @model page end
Access
Result