Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brunoluiz/427acbdc0ec5409c6d5c543fbc78e3dc to your computer and use it in GitHub Desktop.
Save brunoluiz/427acbdc0ec5409c6d5c543fbc78e3dc to your computer and use it in GitHub Desktop.
Freight with Macroregion tests (simple scenarios)

Freight with Macroregion tests (simple scenarios)

The following freight request was in two test cases with different zipcodes. The items BRUNO-SKU-SP-3 and BRUNO-SKU-SP-4 were created at location 0098 (SP).

{
        "destinationZipcode": "{{ zipcode }}",
        "clientId": "centauro",
        "channelId": "site",
        "groups": {
                "sputnik": {
                        "items": {
                                "BRUNO-SKU-SP-3": {
                                        "quantity": 1,
                                        "price": 120.99,
                                        "weight": 348
                                },
                                "BRUNO-SKU-SP-4": {
                                        "quantity": 1,
                                        "price": 120.99,
                                        "weight": 348
                                }
                        }
                }
        }
}

For this test, the freight-method "1" had its macroregionPriorities set as:

{ 
  "macroregionPriorities": {
      "mg-state": [
        "mg-state",
        "rj-state",
        "sp-state"
      ],
      "sp-state": [
        "sp-state",
        "rj-state",
        "mg-state"
      ]
    }
}

For the specified SKUs, this priorities means that:

  1. For MG zipcodes, the first inventoryPackage request will only have MG locationIds. As there will be no items to compose a package, a second request will be made using MG+RJ locationIds. As none of these locations will have the item as well, a last request will be made using MG+RJ+SP which will fulfill the request.
  2. For SP zipcodes, the inverse process would be applied but, as the SKU is on a SP location, only one request will be made.

Case 1: Freight performance from SP to MG (zipcode: 30330000)

  1. 196ms
  2. 170ms
  3. 171ms
  4. 179ms
  5. 172ms

Example log:

{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"Promise promise-duration.freight-method-get-by-client took 130ms","time":"2017-11-18T01:58:30.620Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"Promise promise-duration.macroregion-get-ranges-by-client took 153ms","time":"2017-11-18T01:58:30.641Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"Promise promise-duration.macroregion-get-by-client took 154ms","time":"2017-11-18T01:58:30.645Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"req":{"clientId":"unknown","reqId":"unknown","method":"post","url":"https://int-inventory.omniplat.io/v2/clients/centauro/channels/site/packages","body":{"groupId":"sputnik","clientId":"centauro","channelId":"site","locations":{"pickup":["0043","0151"],"shipment":{"1":["0181","0161","0043","0123","0200","0151"],"3":["0052"],"9":["0045","0151","0200","0077","0161","0181","0102","0081","0101","0224","0210","0211","0086","0020","0176","0153","0095","0206","0114","0172","0126","0066","0157","0085","0159","0229","0125","0194","0229","0039","0048","0117","0187","0110","0154","0220","0133","0052","0071","0080","0164","0195","0167","0191","0208","0196","0102","0123","0043","0070"]}},"items":[{"skuId":"BRUNO-SKU-SP-3","quantity":1},{"skuId":"BRUNO-SKU-SP-4","quantity":1}]}},"responseTime":30,"res":{"statusCode":200},"resBody":{"requestId":"73195fee-8fa0-4a8a-92e4-c75a697c7931","isValid":true,"pickup":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"shipment":{"1":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"3":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"9":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]}}},"msg":"[rest] request sent, response received","time":"2017-11-18T01:58:30.730Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"[priorities] Tentative: 0","time":"2017-11-18T01:58:30.731Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"req":{"clientId":"unknown","reqId":"unknown","method":"post","url":"https://int-inventory.omniplat.io/v2/clients/centauro/channels/site/packages","body":{"groupId":"sputnik","clientId":"centauro","channelId":"site","locations":{"pickup":["0043","0151"],"shipment":{"1":["0181","0161","0159","0153","0066","0224","0086","0095","0020","0126","0206","0176","0211","0114","0210","0172","0043","0123","0200","0151"],"3":["0052"],"9":["0045","0151","0200","0077","0161","0181","0102","0081","0101","0224","0210","0211","0086","0020","0176","0153","0095","0206","0114","0172","0126","0066","0157","0085","0159","0229","0125","0194","0229","0039","0048","0117","0187","0110","0154","0220","0133","0052","0071","0080","0164","0195","0167","0191","0208","0196","0102","0123","0043","0070"]}},"items":[{"skuId":"BRUNO-SKU-SP-3","quantity":1},{"skuId":"BRUNO-SKU-SP-4","quantity":1}]}},"responseTime":38,"res":{"statusCode":200},"resBody":{"requestId":"3a9ceb9b-91c0-4679-8dd7-c238da0f5b35","isValid":true,"pickup":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"shipment":{"1":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"3":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"9":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]}}},"msg":"[rest] request sent, response received","time":"2017-11-18T01:58:30.776Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"[priorities] Tentative: 1","time":"2017-11-18T01:58:30.785Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"req":{"clientId":"unknown","reqId":"unknown","method":"post","url":"https://int-inventory.omniplat.io/v2/clients/centauro/channels/site/packages","body":{"groupId":"sputnik","clientId":"centauro","channelId":"site","locations":{"pickup":["0043","0151"],"shipment":{"1":["0195","0181","0161","0159","0125","L1","0153","0066","0224","0086","0095","0020","0126","0206","0176","0211","0114","0210","0172","0085","0081","0187","0045","0077","0191","0167","0102","0208","0196","0070","0101","0048","0117","0098","0229","0194","0039","0043","0123","0200","0151","0164","0133","0071","0110","0154","0080","0052","0220"],"3":["0052"],"9":["0045","0151","0200","0077","0161","0181","0102","0081","0101","0224","0210","0211","0086","0020","0176","0153","0095","0206","0114","0172","0126","0066","0157","0085","0159","0229","0125","0194","0229","0039","0048","0117","0187","0110","0154","0220","0133","0052","0071","0080","0164","0195","0167","0191","0208","0196","0102","0123","0043","0070"]}},"items":[{"skuId":"BRUNO-SKU-SP-3","quantity":1},{"skuId":"BRUNO-SKU-SP-4","quantity":1}]}},"responseTime":21,"res":{"statusCode":200},"resBody":{"requestId":"903bb28b-b001-49e2-a4ed-fdcc3c85d5b9","isValid":true,"pickup":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"shipment":{"1":{"deliveries":[{"deliveryId":"0b48d16e-cdcb-4c50-bb07-589e36d36cc3","packages":[{"packageId":"03a5be59-e0f4-4b59-93d7-4f0a451045e3","location":{"locationId":"0098","canPickupInStore":true,"canReceiveFromStore":false,"canReserveInStore":false,"canShipToCustomer":true,"handlingTax":0,"handlingTime":1,"priority":0,"freightMethodConfigurations":{"1":{"active":true,"handlingTime":2},"9":{"active":true,"handlingTime":1},"freight-method-01":{"active":true,"handlingTime":1}}},"items":{"BRUNO-SKU-SP-3":{"skuId":"BRUNO-SKU-SP-3","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null},"BRUNO-SKU-SP-4":{"skuId":"BRUNO-SKU-SP-4","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null}},"requestedQuantity":2}]}],"exceptions":[]},"3":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"9":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]}}},"msg":"[rest] request sent, response received","time":"2017-11-18T01:58:30.809Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"[priorities] Tentative: 2","time":"2017-11-18T01:58:30.809Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"Promise promise-duration.carrier-get-by-client took 1ms","time":"2017-11-18T01:58:30.811Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"req":{"clientId":"centauro","reqId":"freight-calculate","method":"post","url":"https://int-cargo-falcon.omniplat.io/v1/clients/centauro/freight","body":{"clientId":"centauro","groupId":"sputnik","destination":{"zipCode":30330000},"quotes":{"24e0a8aba9a7d448ef62bf17d9db8170":{"contractIds":["80-1-98"],"price":241.98,"weight":0.696}}}},"responseTime":20,"res":{"statusCode":200},"resBody":{"24e0a8aba9a7d448ef62bf17d9db8170":{"80-1-98":[{"carrierId":"80","methodId":"1","contractId":"80-1-98","zipcodeRangeStart":30000000,"zipcodeRangeEnd":31999999,"minWeight":0.501,"maxWeight":1,"overweightFactor":0,"dimensionalFactor":0,"deliveryEstimate":7,"grisType":"factor","grisValue":0.1,"grisMinValue":0,"adValorenType":"factor","adValorenValue":0.1,"adValorenMinValue":0,"otherCharges":0,"shippingCost":13.675,"icms":0,"icmsCost":0,"calculatedShippingCost":14.158960197946428,"totalShippingCost":14.158960197946428}]}},"msg":"[rest] request sent, response received","time":"2017-11-18T01:58:30.834Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11770,"level":30,"msg":"[priorities-duration] Time: 172","time":"2017-11-18T01:58:30.834Z","v":0}

Case 2: Freight performance from SP to SP (zipcode: 30330000)

Example log:

  1. 114ms
  2. 140ms
  3. 160ms
  4. 97ms
  5. 119ms
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"msg":"Promise promise-duration.freight-method-get-by-client took 133ms","time":"2017-11-18T02:02:35.982Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"msg":"Promise promise-duration.macroregion-get-by-client took 139ms","time":"2017-11-18T02:02:35.989Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"msg":"Promise promise-duration.macroregion-get-ranges-by-client took 226ms","time":"2017-11-18T02:02:36.073Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"req":{"clientId":"unknown","reqId":"unknown","method":"post","url":"https://int-inventory.omniplat.io/v2/clients/centauro/channels/site/packages","body":{"groupId":"sputnik","clientId":"centauro","channelId":"site","locations":{"pickup":["0052","0068","0077","0080","0085","0098","0101","0102","0117","0133","0157","0164","0167","0187","0191","0195","0196","0208","0220","0229"],"shipment":{"1":["0229","L1","0194","0039","0187","0070","0195","0191","0167","0102","0208","0196","0048","0117","0081","0098","0077","0045","0164","0133","0071","0110","0154","0080","0052","0220","0125","0101","0085"],"3":["0052"],"9":["0159","0085","0195","0161","0181","0045","0157","0077","0151","0200","0081","0123","0043","0187","0110","0154","0220","0133","0052","0071","0080","0164","0101","0098","0167","0191","0208","0196","0102","0070","0125","0194","0229","0039","0224","0210","0211","0086","0020","0176","0153","0095","0206","0114","0172","0126","0066","0102","0229","0048","0117"]}},"items":[{"skuId":"BRUNO-SKU-SP-3","quantity":1},{"skuId":"BRUNO-SKU-SP-4","quantity":1}]}},"responseTime":36,"res":{"statusCode":200},"resBody":{"requestId":"ca14ae0b-28e8-4d7e-9a5b-35d8e563b7be","isValid":true,"pickup":{"deliveries":[{"deliveryId":"7142f411-f269-4969-88e1-385d2eaa74e5","packages":[{"packageId":"24fcdffd-0c30-4456-99e6-80a4730d498c","location":{"locationId":"0098","canPickupInStore":true,"canReceiveFromStore":false,"canReserveInStore":false,"canShipToCustomer":true,"handlingTax":0,"handlingTime":1,"priority":0,"freightMethodConfigurations":{"1":{"active":true,"handlingTime":2},"9":{"active":true,"handlingTime":1},"freight-method-01":{"active":true,"handlingTime":1}}},"items":{"BRUNO-SKU-SP-3":{"skuId":"BRUNO-SKU-SP-3","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null},"BRUNO-SKU-SP-4":{"skuId":"BRUNO-SKU-SP-4","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null}},"requestedQuantity":2}]}],"exceptions":[{"locationId":"0052","canReceiveFromStore":false,"items":[{"skuId":"BRUNO-SKU-SP-3","totalRequested":1,"totalAvailable":0},{"skuId":"BRUNO-SKU-SP-4","totalRequested":1,"totalAvailable":0}]}]},"shipment":{"1":{"deliveries":[{"deliveryId":"4e0e6abc-6d41-4e0d-863e-47e399a16912","packages":[{"packageId":"ad710cda-a7c5-464f-91cc-8e8f52a718f8","location":{"locationId":"0098","canPickupInStore":true,"canReceiveFromStore":false,"canReserveInStore":false,"canShipToCustomer":true,"handlingTax":0,"handlingTime":1,"priority":0,"freightMethodConfigurations":{"1":{"active":true,"handlingTime":2},"9":{"active":true,"handlingTime":1},"freight-method-01":{"active":true,"handlingTime":1}}},"items":{"BRUNO-SKU-SP-3":{"skuId":"BRUNO-SKU-SP-3","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null},"BRUNO-SKU-SP-4":{"skuId":"BRUNO-SKU-SP-4","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null}},"requestedQuantity":2}]}],"exceptions":[]},"3":{"deliveries":[],"exceptions":[{"skus":{"BRUNO-SKU-SP-3":1,"BRUNO-SKU-SP-4":1}}]},"9":{"deliveries":[{"deliveryId":"aa2bf274-80c3-4155-a24b-2b519bb77857","packages":[{"packageId":"a9a8ea73-d5a2-49e0-af46-64b770ea48d4","location":{"locationId":"0098","canPickupInStore":true,"canReceiveFromStore":false,"canReserveInStore":false,"canShipToCustomer":true,"handlingTax":0,"handlingTime":1,"priority":0,"freightMethodConfigurations":{"1":{"active":true,"handlingTime":2},"9":{"active":true,"handlingTime":1},"freight-method-01":{"active":true,"handlingTime":1}}},"items":{"BRUNO-SKU-SP-3":{"skuId":"BRUNO-SKU-SP-3","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null},"BRUNO-SKU-SP-4":{"skuId":"BRUNO-SKU-SP-4","availableQuantity":597,"requestedQuantity":1,"stockType":"PHYSICAL","deliveryDate":null,"daysToDelivery":null,"salesStartsAt":null,"salesEndsAt":null,"billingStartsAt":null}},"requestedQuantity":2}]}],"exceptions":[]}}},"msg":"[rest] request sent, response received","time":"2017-11-18T02:02:36.166Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"msg":"[priorities] Tentative: 0","time":"2017-11-18T02:02:36.167Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"msg":"Promise promise-duration.carrier-get-by-client took 1ms","time":"2017-11-18T02:02:36.168Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"req":{"clientId":"centauro","reqId":"freight-calculate","method":"post","url":"https://int-cargo-falcon.omniplat.io/v1/clients/centauro/freight","body":{"clientId":"centauro","groupId":"sputnik","destination":{"zipCode":6020010},"quotes":{"24e0a8aba9a7d448ef62bf17d9db8170":{"contractIds":["80-1-98"],"price":241.98,"weight":0.696},"84ec43845a762e66822531ba19c0f8d0":{"contractIds":["80-9-98"],"price":241.98,"weight":0.696,"priority":"C"}}}},"responseTime":34,"res":{"statusCode":200},"resBody":{"24e0a8aba9a7d448ef62bf17d9db8170":{"80-1-98":[]},"84ec43845a762e66822531ba19c0f8d0":{"80-9-98":[{"carrierId":"81","methodId":"9","contractId":"80-9-98","zipcodeRangeStart":1000000,"zipcodeRangeEnd":6949999,"minWeight":0.501,"maxWeight":1,"overweightFactor":0,"dimensionalFactor":0,"deliveryEstimate":7,"grisType":"factor","grisValue":0.1,"grisMinValue":0,"adValorenType":"factor","adValorenValue":0.1,"adValorenMinValue":0,"otherCharges":0,"shippingCost":10.975,"icms":0,"icmsCost":0,"calculatedShippingCost":11.458960388681291,"totalShippingCost":11.458960388681291}]}},"msg":"[rest] request sent, response received","time":"2017-11-18T02:02:36.206Z","v":0}
{"name":"chubaca","hostname":"ip-172-29-95-163","pid":11989,"level":30,"msg":"[priorities-duration] Time: 114","time":"2017-11-18T02:02:36.207Z","v":0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment