<< | Index | >>
Goal/Estimate/Evaluation:
Review
def migel_search if migel_code = @session.user_input(:migel_code) and product = @session.search_migel_products(migel_code).first 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))
class Items attr_reader :price, :qty, :unit, :pointer_descr def initialize(product, sortvalue = nil, reverse = nil) if product and items = product.items @sortvalue = sortvalue @list = items.values @reverse = reverse end ... def sort_by # This is called at the first time when a search result is shown @list.sort_by do |record| if @sortvalue if @sortvalue == 'ppub' record.ppub.to_f else record.send(@sortvalue.to_sym).to_s end else record.pharmacode end end end
class SearchedList < HtmlGrid::List def sort_link(header_key, matrix, component) link = HtmlGrid::Link.new(header_key, @model, @session, self) sort = @session.user_input(:sortvalue) ? :reverse : :sortvalue link.href = @lookandfeel._event_url(:migel_search, [:migel_code, @model.first.migel_code.gsub('.',''), sort, component.to_s]) link end
STRINGS = [ ... :reverse, ...
Access
works
Result
Experiment
def sort_by # This is called at the first time when a search result is shown if @reverse @list.sort_by do |record| if @sortvalue if @sortvalue == 'ppub' record.ppub.to_f else record.send(@sortvalue.to_sym).to_s end else record.pharmacode end end else @list.sort_by do |record| if @sortvalue if @sortvalue == 'ppub' record.ppub.to_f else record.send(@sortvalue.to_sym).to_s end else record.pharmacode end end.reverse end end
Access
Note
Next
Problem
Idea
Experiment
def sort_link(header_key, matrix, component) sortvalue = @session.user_input(:sortvalue) || @session.user_input(:reverse) sort_way = @session.user_input(:sortvalue) ? :sortvalue : :reverse sort_way = if sort_way == :sortvalue and component.to_s == sortvalue :reverse else :sortvalue end link = HtmlGrid::Link.new(header_key, @model, @session, self) if search_query = @session.user_input(:search_query) args = [:zone, @session.zone, :search_query, @session.user_input(:search_query), sort_way, component.to_s] #args = [:search_query, @session.user_input(:search_query), sort_way, component.to_s] link.href = @lookandfeel._event_url(@session.event, args) else sortvalue = @session.user_input(:sortvalue) || @session.user_input(:reverse) sort_way = @session.user_input(:sortvalue) ? :sortvalue : :reverse sort_way = if sort_way == :sortvalue and component.to_s == sortvalue :reverse else :sortvalue end link.href = @lookandfeel._event_url(:migel_search, [:migel_code, @model.first.migel_code.gsub('.',''), sort_way, component.to_s]) end link end
module ODDB module State class Global < SBSM::State class StubProduct attr_reader :items def initialize(items) @items = items end end ... 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)) #State::Migel::Items.new(@session, result)
Access
works
works
Note
Next
Experiment
def sort_model block = self::class::SORT_DEFAULT if(block && (@session.event != :sort)) begin if(block == :self) @model = @model.sort else unless(block.is_a?(Proc)) block = Proc.new { |item| begin item.send(self::class::SORT_DEFAULT) rescue RuntimeError => e item.to_s end } end @model = @model.sort_by(&block) p @model.map{|m| m.pharmacode} @model end
Access (sort and reverse)
Result
["4091488", "3390852", "3390823", "3390786", "3390740", "3390734", "3389234", "3191259", "3191213", "3184319", "3184294", "3184207", "1821147", "1821130"] ["4091488", "3390852", "3390823", "3390786", "3390740", "3390734", "3389234", "3191259", "3191213", "3184319", "3184294", "3184207", "1821147", "1821130"] ["1821130", "1821147", "3184207", "3184294", "3184319", "3191213", "3191259", "3389234", "3390734", "3390740", "3390786", "3390823", "3390852", "4091488"]
Note
Experiment
# Grouping products with migel_code
migel_code_group = {}
model.each do |product|
(migel_code_group[product.migel_code] ||= []) << product
end
# list up items
#migel_code_group.keys.each do |migel_code|
migel_code_group.keys.sort.each do |migel_code|
offset_length = migel_code_group[migel_code].length
compose_subheader(migel_code_group[migel_code][0], offset)
super(migel_code_group[migel_code], offset)
offset[1] += offset_length
end
Access
Note
Total coverage
Experiment
def reimport_missing_data(langauge = 'de', estimate = false, output_filename = nil) migel_codes = migel_code_list.select do |migel_code| migelid = Migel::Model::Migelid.find_by_migel_code(migel_code) and !migelid.products.empty? and migelid.products.first.article_name.send(langauge).to_s.empty? end total = migel_codes.length start_time = Time.now migel_codes.each_with_index do |migel_code, count| update_products_by_migel_code(migel_code, language) puts estimate_time(start_time, total, count+1) if estimate end if output_filename File.open(output_filename, 'w') do |out| out.print migel_codes.join("\n"), "\n" end end migel_codes end
Log
1 / 52 Estimate total: 11.74 [m] It will be done in: 11.52 [m] 2 / 52 Estimate total: 8.41 [m] It will be done in: 8.09 [m] 3 / 52 Estimate total: 27.40 [m] It will be done in: 25.82 [m] 4 / 52 Estimate total: 20.94 [m] It will be done in: 19.33 [m] 5 / 52 Estimate total: 17.10 [m] It will be done in: 15.46 [m] ...
Note
Result