seshbot-packing 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/seshbot/packing/package.rb +14 -12
- data/lib/seshbot/packing/recipe.rb +3 -69
- data/lib/seshbot/packing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1df1737c878348a458089c20c950a5a2c0a8fdd501736904f8a4c89cc83e92ad
|
4
|
+
data.tar.gz: bb96a3429acfbda5e066652600df576f6cf3a0a4e303ee3c6a68a1841eb984e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8557f78b9e1092f5ea8d776399d2ebc9b1163cd184a45e28482abf2635788b57e27f7dc6fd7d32e7b6b013eb62f86dddb71f3ff64c77f74e71c36278a24e6403
|
7
|
+
data.tar.gz: 52d32265eedae66704b42a43a6183a47bf4268007b463a6cc2529cc291b09c10ef5353b15b725add93931d7f273053fbfc46700a70e43091218b8106017f9e4d
|
data/Gemfile.lock
CHANGED
@@ -6,7 +6,9 @@ module Seshbot
|
|
6
6
|
class Error < StandardError; end
|
7
7
|
class << self
|
8
8
|
def logger
|
9
|
-
Logger.new(STDERR)
|
9
|
+
logger = Logger.new(STDERR)
|
10
|
+
logger.level = 1
|
11
|
+
logger
|
10
12
|
end
|
11
13
|
|
12
14
|
def filter_by_sku(items, sku_fragment, inverse: false)
|
@@ -52,7 +54,7 @@ module Seshbot
|
|
52
54
|
result
|
53
55
|
end
|
54
56
|
|
55
|
-
def bundle_items(items, fulfilled_at: nil)
|
57
|
+
def bundle_items(recipes, items, fulfilled_at: nil)
|
56
58
|
logger.debug "***** BUNDLING"
|
57
59
|
logger.debug "Bundling Items: #{items}. Fulfilled at: #{fulfilled_at || '(no fulfillment date)'}"
|
58
60
|
if !fulfilled_at.nil? && fulfilled_at < DateTime.new(2020, 1, 14, 8, 0, 0, Time.new.zone)
|
@@ -63,8 +65,8 @@ module Seshbot
|
|
63
65
|
cans = filter_by_sku(items, '-C')
|
64
66
|
unless cans.empty?
|
65
67
|
product_type_counts = count_product_types(cans)
|
66
|
-
product_type_counts = unpack(product_type_counts)
|
67
|
-
product_type_counts = pack(product_type_counts)
|
68
|
+
product_type_counts = unpack(recipes, product_type_counts)
|
69
|
+
product_type_counts = pack(recipes, product_type_counts)
|
68
70
|
new_can_items = product_type_counts.map { |k, v| { 'sku' => "BUND-#{k}", 'quantity' => v, 'price' => 0 } }
|
69
71
|
# separate out all the C324s
|
70
72
|
separated_c324s = filter_by_sku(new_can_items, '-C324')
|
@@ -89,9 +91,9 @@ module Seshbot
|
|
89
91
|
# get a hash of {pack_6: 5, pack_12: 1}
|
90
92
|
product_type_counts = count_product_types(remaining_items)
|
91
93
|
# dismantle packages into individual units (e.g., {pack_6: 7})
|
92
|
-
product_type_counts = unpack(product_type_counts)
|
94
|
+
product_type_counts = unpack(recipes, product_type_counts)
|
93
95
|
# repackage into the 'best' packaging we can figure out (e.g., {pack_12: 2})
|
94
|
-
product_type_counts = pack(product_type_counts)
|
96
|
+
product_type_counts = pack(recipes, product_type_counts)
|
95
97
|
new_remaining_items = product_type_counts.map { |k,v| { "sku" => "BUND-#{k}", "quantity" => v, "price" => 0} }
|
96
98
|
|
97
99
|
separated_c324s ||= []
|
@@ -103,11 +105,11 @@ module Seshbot
|
|
103
105
|
end
|
104
106
|
|
105
107
|
|
106
|
-
def unpack(product_type_counts)
|
108
|
+
def unpack(recipes, product_type_counts)
|
107
109
|
final_result = product_type_counts
|
108
110
|
|
109
111
|
while true
|
110
|
-
new_result = pack_single_step(final_result, unpacking: true)
|
112
|
+
new_result = pack_single_step(recipes, final_result, unpacking: true)
|
111
113
|
break if new_result == final_result
|
112
114
|
|
113
115
|
final_result = new_result
|
@@ -115,10 +117,10 @@ module Seshbot
|
|
115
117
|
final_result
|
116
118
|
end
|
117
119
|
|
118
|
-
def pack_single_step(product_type_counts, unpacking:)
|
120
|
+
def pack_single_step(recipes, product_type_counts, unpacking:)
|
119
121
|
result = Hash.new(0)
|
120
122
|
product_type_counts.each do |sku_fragment, qty|
|
121
|
-
recipe = Recipe::find_best_recipe(sku_fragment, qty, unpacking: unpacking)
|
123
|
+
recipe = Recipe::find_best_recipe(recipes, sku_fragment, qty, unpacking: unpacking)
|
122
124
|
if recipe.nil?
|
123
125
|
result[sku_fragment] += qty
|
124
126
|
next
|
@@ -133,12 +135,12 @@ module Seshbot
|
|
133
135
|
end
|
134
136
|
|
135
137
|
|
136
|
-
def pack(product_type_counts)
|
138
|
+
def pack(recipes, product_type_counts)
|
137
139
|
final_result = product_type_counts
|
138
140
|
|
139
141
|
# keep trying to 'pack' until it stabilises (e.g., 6x6pack => 1x24pack+2x6pack => 1x24pack+1x12pack)
|
140
142
|
while true
|
141
|
-
new_result = pack_single_step(final_result, unpacking: false)
|
143
|
+
new_result = pack_single_step(recipes, final_result, unpacking: false)
|
142
144
|
# no changes, break out
|
143
145
|
break if new_result == final_result
|
144
146
|
final_result = new_result
|
@@ -2,73 +2,8 @@ module Seshbot
|
|
2
2
|
module Packing
|
3
3
|
module Recipe
|
4
4
|
class << self
|
5
|
-
def
|
6
|
-
|
7
|
-
"bottles_forty_eight_pack_8"=>{
|
8
|
-
"input_fragment"=>"B306",
|
9
|
-
"input_quantity"=>8,
|
10
|
-
"output_fragment"=>"B348",
|
11
|
-
"output_quantity"=>1
|
12
|
-
},
|
13
|
-
"bottles_twenty_four_pack_4"=>{
|
14
|
-
"input_fragment"=>"B306",
|
15
|
-
"input_quantity"=>4,
|
16
|
-
"output_fragment"=>"B324",
|
17
|
-
"output_quantity"=>1
|
18
|
-
},
|
19
|
-
"bottles_twenty_four_pack_3"=>{
|
20
|
-
"input_fragment"=>"B306",
|
21
|
-
"input_quantity"=>3,
|
22
|
-
"output_fragment"=>"B318",
|
23
|
-
"output_quantity"=>1
|
24
|
-
},
|
25
|
-
"bottles_twelve_pack"=>{
|
26
|
-
"input_fragment"=>"B306",
|
27
|
-
"input_quantity"=>2,
|
28
|
-
"output_fragment"=>"B312",
|
29
|
-
"output_quantity"=>1
|
30
|
-
},
|
31
|
-
"bottles_six_pack"=>{
|
32
|
-
"input_fragment"=>"B301",
|
33
|
-
"input_quantity"=>6,
|
34
|
-
"output_fragment"=>"B306",
|
35
|
-
"output_quantity"=>1
|
36
|
-
},
|
37
|
-
"cans_forty_eight_pack_8"=>{
|
38
|
-
"input_fragment"=>"C306",
|
39
|
-
"input_quantity"=>8,
|
40
|
-
"output_fragment"=>"C348",
|
41
|
-
"output_quantity"=>1
|
42
|
-
},
|
43
|
-
"cans_twenty_four_pack_4"=>{
|
44
|
-
"input_fragment"=>"C306",
|
45
|
-
"input_quantity"=>4,
|
46
|
-
"output_fragment"=>"C324",
|
47
|
-
"output_quantity"=>1
|
48
|
-
},
|
49
|
-
"cans_twenty_four_pack_3"=>{
|
50
|
-
"input_fragment"=>"C306",
|
51
|
-
"input_quantity"=>3,
|
52
|
-
"output_fragment"=>"C318",
|
53
|
-
"output_quantity"=>1
|
54
|
-
},
|
55
|
-
"cans_twelve_pack"=>{
|
56
|
-
"input_fragment"=>"C306",
|
57
|
-
"input_quantity"=>2,
|
58
|
-
"output_fragment"=>"C312",
|
59
|
-
"output_quantity"=>1
|
60
|
-
},
|
61
|
-
"cans_six_pack"=>{
|
62
|
-
"input_fragment"=>"C301",
|
63
|
-
"input_quantity"=>6,
|
64
|
-
"output_fragment"=>"C306",
|
65
|
-
"output_quantity"=>1
|
66
|
-
}
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
def find_best_recipe(sku_fragment, qty, unpacking: false)
|
71
|
-
recipes = find_recipes(sku_fragment, qty, unpacking: unpacking)
|
5
|
+
def find_best_recipe(recipes_hash, sku_fragment, qty, unpacking: false)
|
6
|
+
recipes = find_recipes(recipes_hash, sku_fragment, qty, unpacking: unpacking)
|
72
7
|
# we want the recipe that is 'best' (packaging into as few items as possible, or unpacaging into as many as possible)
|
73
8
|
best_recipe_quantities = nil
|
74
9
|
recipes.each do |name, recipe|
|
@@ -89,8 +24,7 @@ module Seshbot
|
|
89
24
|
best_recipe_quantities[:recipe] if best_recipe_quantities
|
90
25
|
end
|
91
26
|
|
92
|
-
def find_recipes(sku_fragment, qty, unpacking: false)
|
93
|
-
recipes = get_recipes
|
27
|
+
def find_recipes(recipes, sku_fragment, qty, unpacking: false)
|
94
28
|
recipes = reverse_recipes(recipes) if unpacking
|
95
29
|
recipes.select do |name, recipe|
|
96
30
|
recipe["input_fragment"] == sku_fragment && qty >= recipe["input_quantity"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: seshbot-packing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shaun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|