Skip to content

Instantly share code, notes, and snippets.

@devifr
Last active February 3, 2020 18:40

Revisions

  1. devifr revised this gist Feb 3, 2020. No changes.
  2. devifr revised this gist Feb 3, 2020. 1 changed file with 8 additions and 23 deletions.
    31 changes: 8 additions & 23 deletions test printerous
    Original file line number Diff line number Diff line change
    @@ -118,7 +118,6 @@
    item_name = itm[:name]
    item_qty = itm[:quantity]
    item_max_price = itm[:price]
    item_min_price = 10000
    item_start_time = itm[:start_time]
    item_end_time = itm[:end_time]
    range_time = (item_start_time..item_end_time).to_a
    @@ -133,32 +132,18 @@
    next if biddings.nil?
    get_data = biddings[time]
    next if get_data.nil?
    if get_data[:price] <= item_max_price && get_data[:price] >= item_min_price
    get_binding << {price: get_data[:price], name: name, date: time, total: (get_data[:price] * item_qty)}
    if get_data[:price] <= item_max_price
    get_binding_new[name] = {price: get_data[:price], name: name, date: time, total: (get_data[:price] * item_qty)}
    end
    end
    end
    # sort
    sort_get_binding = get_binding.sort {|a,b| a[:price] <=> b[:price]}

    # sort by duplicate partner
    new_sort = []
    sort_get_binding.each do |get|
    if get_binding_new.keys.include?(get[:name])
    if (get[:price] < get_binding_new[get[:name]][:price] && !get_price.include?(get[:price]))
    get_binding_new[get[:name]] = get
    get_price << get[:price]
    end
    elsif !get_price.include?(get[:price])
    get_binding_new[get[:name]] = {price: get[:price], name: get[:name], date: get[:date], total: (get[:price] * item_qty)}
    get_price << get[:price]
    end
    end
    # Print
    get_binding_new.each.with_index(1) do |p,i|
    name_p = p.first
    data_p = p.last
    # sort by price
    sort_binding = get_binding_new.sort_by {|k,v| v[:price]}
    sort_binding.each.with_index(1) do |data,i|
    name_p = data.first
    data_p = data.last
    puts "#{i}. #{name_p} #{data_p[:date]} #{data_p[:price]} #{data_p[:total]}"
    end
    puts
    end
    end
  3. devifr created this gist Feb 3, 2020.
    164 changes: 164 additions & 0 deletions test printerous
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,164 @@
    @items = [
    {
    name: 'item-a', # Nama Item
    price: 70000, # Harga Maximum
    quantity: 1000, # Jumlah item yang akan dikerjakan
    production_time: 8, # Lama pengerjaan dalam hari
    start_time: '2017-11-14 10:00', # Mulai bidding
    end_time: '2017-11-14 12:00' # Akhir bidding
    },
    {
    name: 'item-b',
    price: 50000,
    quantity: 2000,
    production_time: 10,
    start_time: '2017-11-14 12:00',
    end_time: '2017-11-14 15:00'
    }
    ]

    @submissions = [
    {
    name: 'Wili', # Nama Partner
    bidding: {
    'item-a' => {
    '2017-11-14 10:00' => { # Tanggal submit
    price: 65000, # Harga yang ditawarkan
    production_time: 9 # Waktu pengerjaan dalam hari
    },
    '2017-11-14 12:00' => {
    price: 68000,
    production_time: 9
    },
    '2017-11-14 10:30' => {
    price: 71000,
    production_time: 9
    },
    '2017-11-14 12:30' => {
    price: 10000,
    production_time: 9
    }
    },

    'item-b' => {
    '2017-11-14 14:30' => {
    price: 40000,
    production_time: 9
    },
    '2017-11-14 12:30' => {
    price: 50000,
    production_time: 9
    }
    }
    }
    },

    {
    name: 'Lita',
    bidding: {
    'item-b' => {
    '2017-11-14 13:30' => {
    price: 45000,
    production_time: 9
    },
    '2017-11-14 15:01' => {
    price: 35000,
    production_time: 9
    },
    '2017-11-14 12:30' => {
    price: 48000,
    production_time: 9
    }
    }
    }
    },

    {
    name: 'Sabar',
    bidding: {
    'item-a' => {
    '2017-11-14 11:50' => {
    price: 65000,
    production_time: 9
    },
    '2017-11-14 11:30' => {
    price: 68000,
    production_time: 9
    },
    '2017-11-14 11:00' => {
    price: 69000,
    production_time: 9
    }
    }
    }
    },

    {
    name: 'Makmur',
    bidding: {
    'item-a' => {
    '2017-11-14 12:00' => {
    price: 50000,
    production_time: 9
    },
    '2017-11-14 11:00' => {
    price: 5000,
    production_time: 9
    }
    }
    }
    }
    ]

    @items.each do |itm|
    get_binding = []
    get_binding_new = {}
    get_price = []
    get_name = []
    item_name = itm[:name]
    item_qty = itm[:quantity]
    item_max_price = itm[:price]
    item_min_price = 10000
    item_start_time = itm[:start_time]
    item_end_time = itm[:end_time]
    range_time = (item_start_time..item_end_time).to_a
    puts "# #{item_name}: #{item_qty} - #{item_max_price}"
    puts "Start Time: #{item_start_time}"
    puts "End Time: #{item_end_time}"
    puts "Peserta (1):"
    range_time.each do |time|
    @submissions.each do |data|
    name = data[:name]
    biddings = data[:bidding][item_name]
    next if biddings.nil?
    get_data = biddings[time]
    next if get_data.nil?
    if get_data[:price] <= item_max_price && get_data[:price] >= item_min_price
    get_binding << {price: get_data[:price], name: name, date: time, total: (get_data[:price] * item_qty)}
    end
    end
    end
    # sort
    sort_get_binding = get_binding.sort {|a,b| a[:price] <=> b[:price]}

    # sort by duplicate partner
    new_sort = []
    sort_get_binding.each do |get|
    if get_binding_new.keys.include?(get[:name])
    if (get[:price] < get_binding_new[get[:name]][:price] && !get_price.include?(get[:price]))
    get_binding_new[get[:name]] = get
    get_price << get[:price]
    end
    elsif !get_price.include?(get[:price])
    get_binding_new[get[:name]] = {price: get[:price], name: get[:name], date: get[:date], total: (get[:price] * item_qty)}
    get_price << get[:price]
    end
    end
    # Print
    get_binding_new.each.with_index(1) do |p,i|
    name_p = p.first
    data_p = p.last
    puts "#{i}. #{name_p} #{data_p[:date]} #{data_p[:price]} #{data_p[:total]}"
    end
    puts
    end