From 6fc5a09c6d32689704e546033c466af2334965c6 Mon Sep 17 00:00:00 2001 From: josch Date: Wed, 16 May 2012 10:43:22 +0200 Subject: [PATCH] add all those small scripts --- add_approach_points.py | 20 +++++++++++++------- barcodes.py | 15 +++++++++++++++ densities.py | 17 +++++++++++++++++ descriptions.py | 23 +++++++++++++++++++++++ evaluate.py | 9 +++++++++ evaluate_multi.py | 34 ++++++++++++++++++++++++++++++++++ num_articles_order.py | 12 ++++++++++++ num_articles_packlist.py | 20 ++++++++++++++++++++ pallets.py | 25 +++++++++++++++++++++++++ 9 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 barcodes.py create mode 100644 densities.py create mode 100644 descriptions.py create mode 100644 evaluate.py create mode 100644 evaluate_multi.py create mode 100644 num_articles_order.py create mode 100644 num_articles_packlist.py create mode 100644 pallets.py diff --git a/add_approach_points.py b/add_approach_points.py index 53a6a6b..b52dc55 100644 --- a/add_approach_points.py +++ b/add_approach_points.py @@ -6,17 +6,23 @@ 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']: - 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 - article['ApproachPoint3']['X'], article['ApproachPoint3']['Y'], article['ApproachPoint3']['Z'] = x+x3, y+y3, z+z3 + 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 + article['ApproachPoint3']['X'], article['ApproachPoint3']['Y'], article['ApproachPoint3']['Z'] = x+x3, y+y3, z+z3 sys.stdout.write(dicttoxmlstring(packlist)) diff --git a/barcodes.py b/barcodes.py new file mode 100644 index 0000000..b70f66b --- /dev/null +++ b/barcodes.py @@ -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() diff --git a/densities.py b/densities.py new file mode 100644 index 0000000..e5b109e --- /dev/null +++ b/densities.py @@ -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() diff --git a/descriptions.py b/descriptions.py new file mode 100644 index 0000000..42b01ab --- /dev/null +++ b/descriptions.py @@ -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() diff --git a/evaluate.py b/evaluate.py new file mode 100644 index 0000000..ea28dda --- /dev/null +++ b/evaluate.py @@ -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]) diff --git a/evaluate_multi.py b/evaluate_multi.py new file mode 100644 index 0000000..6d0257a --- /dev/null +++ b/evaluate_multi.py @@ -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) diff --git a/num_articles_order.py b/num_articles_order.py new file mode 100644 index 0000000..ec782ae --- /dev/null +++ b/num_articles_order.py @@ -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) diff --git a/num_articles_packlist.py b/num_articles_packlist.py new file mode 100644 index 0000000..6fb6d08 --- /dev/null +++ b/num_articles_packlist.py @@ -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 diff --git a/pallets.py b/pallets.py new file mode 100644 index 0000000..a82cb96 --- /dev/null +++ b/pallets.py @@ -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()