Is there an easy way to calculate the required carton for an order with products? - calculator

For my order-system I need to determe which carton I need based on the order.
For example:
Order A has 3 items:
1x ProductA (size 15x10x5cm )
2x ProductB (size 20x10x5cm )
Order B has 2 items:
1x ProductA (size 15x10x5cm )
1x ProductB (size 20x10x5cm )
Available cartons have inner-dimensions:
CartonA (size 20x10x10cm)
CartonB (size 20x20x10cm)
CartonC (size 30x20x15cm)
Also calculate 0,5cm margin for each product/size
So ProductA will be 15,5x10,5x5,5cm and ProductB will be 20,5x10,5x5,5cm
Everybody will see now that we need CartonC for OrderA and CartonB will be enough for OrderB.
But how should we calculate this the fastest?
I know I can calculate the volume (LxWxH), but that will not always work.
$volumeA = $widthA*$heightA*lengthA;
Also just sum up all the sizes will not work:
$width = $widthA+$widthB; // return 36cm
while we can put them next to each other instead of behind each other.
Anybody an idea? Google showed only online calculators.
But I need a solution that gives me instant the right carton-type.
Thanks in advance!
$availableCarton = array("cartonA"=>array("length"=>20,"height"=>10,"width"=>10),"cartonB"=>array("length"=>20,"height"=>20,"width"=>10),"cartonC"=>array("length"=>30,"height"=>20,"width"=>15));
foreach($products as $product){
//do some maths here
}
echo $neededCarton;

I already found a solution: boxpacker.io
Boxpacker even shows us how item are positioned in the box.

Related

How can I merge two Mbtiles?

I have created 2 Mbtiles via QGIS: 1) one Mbtile is from zoom 0 until 10 & is a map of the whole world, 2) and another one from zoom 0 until 17 & is a detailed map of one country.
I would like to merge the two Mbtiles, and have the Mbtile of the detailed country overlapping the Mbtile of whole world. Also the merged result to be from zoom 0 til 17 (the whole world would disappear at zoom 10, but the country will remain until zoom 17).
What program/method should I use? Is it possible to merge them via QGIS?
I use Python to merge MBTiles files. Be sure to update the matadata table noting the min max zoom. They are just sqlite databases with a unique extension.
This example does not include data validation. I did not test this example -- as it is stripped down from where I batch process output from QGIS.
It is less problematic to use an IDE other than QGIS's python interface. Does not require anything specific to QGIS or PyQGIS.
import sqlite3 as sqlite
def processOneSource(srcDB, dstDB):
# create_index_sql = "CREATE UNIQUE INDEX tile_index on tiles (zoom_level, tile_column, tile_row);"
# dstDB.connection.execute(create_index_sql)
# the index forces an error if there is already a tile for the same zxy
sqlite_insert_blob_query = """ INSERT INTO tiles (zoom_level, tile_column, tile_row, tile_data) VALUES (?, ?, ?, ?)"""
tiles = srcDB.connection.execute('select zoom_level, tile_column, tile_row, tile_data from tiles;')
for t in tiles:
z = t[0]
x = t[1]
y = t[2]
data = t[3]
# example of how you might include exclude tiles
if not (z == 12 or z == 13 or z == 14 or z == 15 or z == 16):
continue
print(str((t[0], t[1], t[2])))
data_tuple = (t[0], t[1], t[2], t[3])
try:
dstDB.connection.execute(sqlite_insert_blob_query, data_tuple)
except Exception as e:
print(e)
dstDB.commit()
if __name__ == '__main__':
srcDB = sqlite.connect("path_to_yourfilename")
dstDB = sqlite.connect("path_to_yourfilename")
processOneSource(srcDB, dstDB)
You can use tile-join, it has a bunch of flags so you can customize the output.

PyGears reordering bits

I would like to reorder bits before sending it to another module. I would like to make gear that will take 2 inputs pixel and weight and output called reordered should be:
reordered[0] = {pixel[0],weight[0]}
reordered[1] = {pixel[1],weight[1]}
Below is a picture that explains desired gear:
I made the assumption that both pixels and weights are coming as one interface thus I group it. This module should look something like this:
#datagear
def reorder( din: Queue[Tuple['pixel', 'weight']] ) -> Array[Queue[Tuple['pixel.data', 'weight.data']], 3]:
pixel = din.data[0]
weight = din.data[1]
return (
((pixel[0], weight[0]), din.eot),
((pixel[1], weight[1]), din.eot),
((pixel[2], weight[2]), din.eot),
)
Datagear is generally used for handling data and reordering it.
But please have in mind that if Pixel and Weight were two interfaces additional logic would be generated for synchronization of these two interfaces.

Graphite divideSeries(#E,#A) return no data

I have 2 series(#A and #E), one contains how much x I gain each minute, and the other contains how much x I need.
My goal is to calculate how long time it'll take before I'm done.
I've tried to do divideSeries(#A,#E), which returns "No data" on my graph.
#A:
currentAbove(summarize(removeAboveValue(removeBelowValue(derivative(screeps.emil8250.ControllerProgress), 0), 2000), '30m', 'avg', false), 0)
#E:
currentAbove(diffSeries(#C, #D), 0)
Currently #A is 108 and #E is 154.003, so I'd assume the result would be 1.425,95.
Any suggestions on why this isn't working?
I managed to fix this, by converting x to percent and then using derivative to find delta.
Then I used scale instead of divideSeries to calculate how many hours was left.

TSQL divide one count by another to give a proportion

I would like to calculate the proportion of animals in column BreedTypeID with a value of 1. I think the easiest way is to count the n BreedTypeID = 1 / total BreedTypeID. (I also wnat them to have the same YearDOB and substring in their ID as shown) I tried the following:
(COUNT([dbo].[tblBreed].[BreedTypeID])=1 OVER (PARTITION BY Substring([AnimalNo],6,6), YEAR([DOB]))/ COUNT([dbo].[tblBreed].[BreedTypeID]) OVER (PARTITION BY Substring([AnimalNo],6,6), YEAR([DOB]))) As Proportion
But it bugged with the COUNT([dbo].[tblBreed].[BreedTypeID])=1
How can I specify to only count [BreedTypeID] when =1?
Many thanks
This will fix your problem, although I would suggest you use table aliases instead of schema.table.column. Much easier to read:
Just replace:
COUNT([dbo].[tblBreed].[BreedTypeID])=1
WITH
SUM( CASE WHEN [dbo].[tblBreed].[BreedTypeID] = 1 THEN 1 ELSE 0 END)

Specman e coverage: ignored values appear in the coverage statistics

I need to collect a coverage only when one of the items has a specific value (only when size == BYTE). The code I wrote:
item size : size_t = trans.size using no_collect;
item byte_alignment : uint(bits:2) = trans.addr using no_collect;
cross size, byte_alignment using ignore = (size != BYTE);
In the test I run, size != BYTE, but I still have the cross_size__byte_alignment item in the coverage statistics with zero Overall Average Grade.. Why?
How to prevent collecting coverage for size != BYTE?
Thank you for your help
use the "when" option on the item/cross to say when you want to collect coverage.
use the "ignore" option to remove buckets from the item/cross.
if you want to collect only when size equals BYTE and you do not want to see the buckets where size is not BYTE, combine both options:
cross size, byte_alignment using ignore = (size != BYTE), when = (size == BYTE);