add all those small scripts

This commit is contained in:
josch 2012-05-16 10:43:22 +02:00
parent f757dca501
commit 6fc5a09c6d
9 changed files with 168 additions and 7 deletions

View file

@ -6,13 +6,19 @@ def main():
print "usage:", sys.argv[0], "packlist.xml x1,y1,z1 x2,y2,z2 x3,y3,z3"
exit(1)
packlist = xmlfiletodict(sys.argv[1])
x1, y1, z1 = map(int, sys.argv[2].split(','))
x2, y2, z2 = map(int, sys.argv[3].split(','))
x3, y3, z3 = map(int, sys.argv[4].split(','))
for article in packlist['Response']['PackList']['PackPallets']['PackPallet']['Packages']['Package']:
d = xmlfiletodict(sys.argv[1])
pallets = d["Response"]["PackList"]["PackPallets"]["PackPallet"]
if not isinstance(pallets, list):
pallets = [pallets]
for pallet in pallets:
for article in pallet["Packages"]["Package"]:
x, y, z = int(article['PlacePosition']['X']), int(article['PlacePosition']['Y']), int(article['PlacePosition']['Z'])
article['ApproachPoint1']['X'], article['ApproachPoint1']['Y'], article['ApproachPoint1']['Z'] = x+x1, y+y1, z+z1
article['ApproachPoint2']['X'], article['ApproachPoint2']['Y'], article['ApproachPoint2']['Z'] = x+x2, y+y2, z+z2

15
barcodes.py Normal file
View file

@ -0,0 +1,15 @@
import sys
from util import xmlfiletodict, get_articles
def main():
if len(sys.argv) != 2:
print "usage:", sys.argv[0], "order.xml"
exit(1)
orderline = xmlfiletodict(sys.argv[1])
for article in get_articles(orderline):
print article['Barcode']
if __name__ == "__main__":
main()

17
densities.py Normal file
View file

@ -0,0 +1,17 @@
import sys
from glob import glob
from util import xmlfiletodict, get_articles
def main():
if len(sys.argv) != 2:
print "usage:", sys.argv[0], "order.xml"
exit(1)
orderline = xmlfiletodict(sys.argv[1])
for article in get_articles(orderline):
volume = article['Article']['Length']*article['Article']['Width']*article['Article']['Height']
print 1000.0*article['Article']['Weight']/volume
if __name__ == "__main__":
main()

23
descriptions.py Normal file
View file

@ -0,0 +1,23 @@
import sys
from util import xmlfiletodict, get_articles
def main():
if len(sys.argv) != 2:
print "usage:", sys.argv[0], "order.xml"
exit(1)
orderline = xmlfiletodict(sys.argv[1])
for article in get_articles(orderline):
print '\t'.join([str(a) for a in [
article['Article']['Description'],
article['Article']['ID'],
article['Article']['Type'],
article['Article']['Family'],
article['Article']['Length'],
article['Article']['Width'],
article['Article']['Height'],
article['Article']['Weight']]])
if __name__ == "__main__":
main()

9
evaluate.py Normal file
View file

@ -0,0 +1,9 @@
import ctypes, sys
if len(sys.argv) != 4:
print "usage:", sys.argv[0], "order.xml packlist.xml scoring.xml"
exit(1)
libpallet = ctypes.cdll.LoadLibrary('./libpallet.so.0.0.0')
libpallet.evaluate.restype = ctypes.c_double
print libpallet.evaluate(sys.argv[1], sys.argv[2], sys.argv[3])

34
evaluate_multi.py Normal file
View file

@ -0,0 +1,34 @@
import ctypes, sys
from util import xmlfiletodict, get_packlist_dict, dicttoxmlfile, get_order_dict
import tempfile
import os
if len(sys.argv) != 3:
print "usage:", sys.argv[0], "packlist.xml scoring.xml"
exit(1)
libpallet = ctypes.cdll.LoadLibrary('./libpallet.so.0.0.0')
libpallet.evaluate.restype = ctypes.c_double
packlist = xmlfiletodict(sys.argv[1])
pallets = packlist['Response']['PackList']['PackPallets']['PackPallet']
article_lists = [ pallet['Packages']['Package'] for pallet in pallets ]
scores = list()
for pallet, articles_to_pack in zip(pallets, article_lists):
partial_packlist = get_packlist_dict(pallet, articles_to_pack)
tmp_fh, tmp = tempfile.mkstemp()
tmp_order_fh, tmp_order = tempfile.mkstemp()
dicttoxmlfile(partial_packlist, tmp)
dicttoxmlfile(get_order_dict(pallet, articles_to_pack), tmp_order)
scores.append(libpallet.evaluate(tmp_order, tmp, sys.argv[2]))
os.close(tmp_fh)
os.close(tmp_order_fh)
os.remove(tmp)
os.remove(tmp_order)
#print tmp_order, tmp
print scores
print sum(scores)/len(scores)

12
num_articles_order.py Normal file
View file

@ -0,0 +1,12 @@
import sys
from util import xmlfiletodict, get_pallet, get_articles
if len(sys.argv) != 2:
print "usage:", sys.argv[0], "order.xml"
exit(1)
orderline = xmlfiletodict(sys.argv[1])
pallet = get_pallet(orderline)
articles = get_articles(orderline)
print len(articles)

20
num_articles_packlist.py Normal file
View file

@ -0,0 +1,20 @@
import sys
from util import xmlfiletodict
if len(sys.argv) != 2:
print "usage:", sys.argv[0], "packlist.xml"
exit(1)
d = xmlfiletodict(sys.argv[1])
pallets = d["Response"]["PackList"]["PackPallets"]["PackPallet"]
if not isinstance(pallets, list):
pallets = [pallets]
num_articles = 0
for pallet in pallets:
num_articles += len(pallet["Packages"]["Package"])
print num_articles

25
pallets.py Normal file
View file

@ -0,0 +1,25 @@
import sys
from util import xmlfiletodict, get_articles
def main():
if len(sys.argv) != 2:
print "usage:", sys.argv[0], "order.xml"
exit(1)
d = xmlfiletodict(sys.argv[1])
pallets = d['Message']['PalletInit']['Pallets']['Pallet']
if not isinstance(pallets, list):
pallets = [pallets]
for p in pallets:
print "\t".join([
p['Dimensions']['Length'],
p['Dimensions']['Width'],
p['Dimensions']['MaxLoadHeight'],
p['Dimensions']['MaxLoadWeight']
])
if __name__ == "__main__":
main()