github.com/pachyderm/pachyderm@v1.13.4/examples/group/src/main.py (about) 1 #!/usr/local/bin/python3 2 import glob, json, os, shutil, sys, csv 3 4 5 store_paths = glob.glob(os.path.join("/pfs/stores", "*.txt")) 6 return_paths = glob.glob(os.path.join("/pfs/returns", "*.txt")) 7 purchase_paths = glob.glob(os.path.join("/pfs/purchases", "*.txt")) 8 9 zipcode = "UNKNOWN" 10 separator_line = "\nThis return store does not exist \n" 11 store_id = 0 12 if store_paths: 13 print("Opening store_file...: " + store_paths[0]) 14 with open(store_paths[0], 'r') as store_json: 15 store = json.load(store_json) 16 # Add a text separator to identify in what store the purchase was made 17 store_id = store["storeid"] 18 separator_line = "\nStore: "+ str(store_id) +" - "+ store["name"]+" \n" 19 20 net_amount = 0.00 21 order_total = 0.00 22 return_total = 0.00 23 24 for purchase_path in purchase_paths: 25 with open(purchase_path, 'r') as purchase: 26 csv_reader = csv.reader(purchase, delimiter = '|') 27 for row in csv_reader: 28 if row[0] == "SKU": 29 order_total += float(row[3]) * float(row[5]) 30 31 for return_path in return_paths: 32 with open(return_path, 'r') as return_file: 33 csv_reader = csv.reader(return_file, delimiter = '|') 34 for row in csv_reader: 35 if row[0] == "SKU": 36 return_total += float(row[3]) * float(row[5]) 37 38 39 with open("/pfs/out/"+str(store_id)+".txt", 'w') as revenue_file: 40 net_amount = order_total - return_total 41 revenue_file.write(separator_line) 42 revenue_file.write("ORDER_AMOUNT|" + str(order_total) + "|RETURN_AMOUNT|" + str(return_total) + "|NET_AMOUNT|"+ str(net_amount) + "\n") 43