Skip to content

Instantly share code, notes, and snippets.

@jackross
Last active May 11, 2016 13:54
Show Gist options
  • Save jackross/a43a4cca9ea7fbf17310f8acbd1cdb3d to your computer and use it in GitHub Desktop.
Save jackross/a43a4cca9ea7fbf17310f8acbd1cdb3d to your computer and use it in GitHub Desktop.
Sample Calculator input document JSON
name: Example Strategy
strategy: base_acre
geography: &geography
include:
states:
AR: all_counties
LA: all_counties
MS: all_counties
KY:
ballard:
TN:
shelby:
products: &products
aproach_prima:
label: Aproach® Prima
uom: gallon
units_per_acre: 6.8
incentive_per_acre: 3.0
envive:
label: Envive®
uom: dry_ounce
units_per_acre: 3.5
incentive_per_acre: 2.0
prevathon:
label: Prevathon®
uom: gallon
units_per_acre: 14.0
incentive_per_acre: 4.0
constraints:
- name: seed_purchase_constraint
type: minimum_total_seed_acres
purchase_seasons:
- 2016
crops:
- Corn
- Soybeans
minimum_total_acres: 200
- name: chem_purchase_constraint
type: minimum_total_chem_amount
products: all_products
purchase_date_range:
from: '2015-10-01'
to: '2016-09-30'
minimum_total_amount: 50_000
- name: geographical_constraint
type: geography
geography: *geography
qualification:
and:
- geographical_constraint
- or:
- chem_purchase_constraint
- seed_purchase_constraint
incentive:
minimum: 500
participating_products: *products
{
"operation": {
"operation_id": .OperationId,
"business_partners_details": [
.GrowerDetails[] |
{
"business_partner_id": .BusinessPartnerId
}
],
"properties": [
{
"key": "is_100%_pioneer_seed", "value": .IsAllPioneerSeed
},
{
"key": "is_southern_enterprise_participant", "value": .IsSouthernEnterpriseParticipant
},
{
"key": "southern_enterprise_cap", "value": .SouthernEnterpriseCap
},
{
"key": "is_mc_gown_offer_eligible", "value": .IsMcGownOfferEligible
},
{
"key": "override_seed_requirement", "value": .OverrideSeedRequirement
},
{
"key": "override_seed_requirement_for_all_programs", "value": .OverrideSeedRequirementForAllPrograms
}
],
"geography": {
"states": [
.GrowerDetails[].Address.State
],
"fips_codes": [
.GrowerDetails[].Address.FipsCode
]
}
},
"seed_purchases": [
.PurchaseDetails[] |
{
"crop": .ProductKey,
"uom": "BAG",
"purchase_season": 2016,
"volume": .Quantity
}
],
"chem_purchases": [
.GrowerDetails[].PurchaseDetails[] |
{
"product": .ProductKey,
"uom": .UOMKey,
"purchase_date": .PurchaseDate,
"volume": .Quantity,
"amount": .LineItemPrice,
"properties": [
{
"key": "precision_pac_exception", "value": .PrecisionPacException
},
{
"key": "ppac_approved_retailer", "value": .PPACApprovedRetailer
},
{
"key": "purchase_type", "value": .PurchaseType
},
{
"key": "united_suppliers_retailer", "value": .UnitedSupplierRetailer
}
]
}
]
}
{
"APIKey": "TCAAdmin",
"APISecret": "APIAccess",
"OperationId": "O0BQ56RUU2",
"IsAllPioneerSeed": false,
"IsSouthernEnterpriseParticipant": false,
"SouthernEnterpriseCap": 0,
"IsMcGownOfferEligible": false,
"OverrideSeedRequirement": false,
"OverrideSeedRequirementForAllPrograms": false,
"Season": "2015",
"PurchaseDetails": [
{
"InvoiceNumber": null,
"PurchaseDate": null,
"POSType": "EDI",
"UnitedSupplierRetailer": false,
"PPACApprovedRetailer": false,
"PrecisionPacException": false,
"ProductKey": "Corn",
"Quantity": 42,
"UOMKey": "UNIT",
"ApplicationRate": 0,
"TreatedAcres": 201,
"ApplicationRateUOMKey": null,
"UnitPrice": 0,
"CashAmount": 0,
"CreditAmount": 0,
"LineItemPrice": 0,
"PurchaseType": null
}
],
"GrowerDetails": [
{
"BusinessPartnerId": "B4R6RXL8A2",
"IsPrimaryBeneficiary": true,
"IsPioneerContractSeedGrower": true,
"ContractAcres": 268.792,
"CornContractAcres": 0,
"SoyContractAcres": 268.792,
"IsPioneerAgent": false,
"IsDuPontSalesRep": false,
"Address": {
"County": "Sumter",
"MailingAddress1": "2260 Florence Hwy",
"MailingAddress2": null,
"City": "Sumter",
"State": "SC",
"StateCode": null,
"PostCode": "29153-9232",
"CountryCode": 0,
"FipsCode": 23456,
"Latitude": 0,
"Longitude": 0
},
"PurchaseDetails": [
]
},
{
"BusinessPartnerId": "B4R6RXL8A1",
"IsPrimaryBeneficiary": true,
"IsPioneerContractSeedGrower": true,
"ContractAcres": 268.792,
"CornContractAcres": 0,
"SoyContractAcres": 268.792,
"IsPioneerAgent": false,
"IsDuPontSalesRep": false,
"Address": {
"County": "Sumter",
"MailingAddress1": "2260 Florence Hwy",
"MailingAddress2": null,
"City": "Sumter",
"State": "MS",
"StateCode": null,
"PostCode": "29153-9232",
"CountryCode": 0,
"FipsCode": 12345,
"Latitude": 0,
"Longitude": 0
},
"Contact": null,
"LoanPaymentDate": null,
"LoanPrincipalPaid": 0,
"LoanInterestPaid": 0,
"PurchaseDetails": [
{
"InvoiceNumber": "57632916",
"PurchaseDate": "2015-04-29T13:25:30+00:00",
"POSType": "EDI",
"UnitedSupplierRetailer": false,
"PPACApprovedRetailer": false,
"PrecisionPacException": false,
"ProductKey": "Envive",
"Quantity": 704,
"UOMKey": "DRY_OUNCE",
"ApplicationRate": 0,
"TreatedAcres": 0,
"ApplicationRateUOMKey": null,
"UnitPrice": 0,
"CashAmount": 3308.8,
"CreditAmount": 0,
"LineItemPrice": 3308.8,
"PurchaseType": "Cash"
},
{
"InvoiceNumber": "217986842",
"PurchaseDate": "2016-04-29T13:25:30+00:00",
"POSType": "EDI",
"UnitedSupplierRetailer": false,
"PPACApprovedRetailer": false,
"PrecisionPacException": false,
"ProductKey": "Envive",
"Quantity": 704,
"UOMKey": "DRY_OUNCE",
"ApplicationRate": 0,
"TreatedAcres": 0,
"ApplicationRateUOMKey": null,
"UnitPrice": 0,
"CashAmount": 3308.8,
"CreditAmount": 0,
"LineItemPrice": 3308.8,
"PurchaseType": "Cash"
},
{
"InvoiceNumber": "CM217989057",
"PurchaseDate": "2016-04-29T13:25:30+00:00",
"POSType": "EDI",
"UnitedSupplierRetailer": false,
"PPACApprovedRetailer": false,
"PrecisionPacException": false,
"ProductKey": "Envive",
"Quantity": -264,
"UOMKey": "DRY_OUNCE",
"ApplicationRate": 0,
"TreatedAcres": 0,
"ApplicationRateUOMKey": null,
"UnitPrice": 0,
"CashAmount": -1240.8,
"CreditAmount": 0,
"LineItemPrice": -1240.8,
"PurchaseType": "Cash"
},
{
"InvoiceNumber": "217988806",
"PurchaseDate": "2016-04-29T13:25:30+00:00",
"POSType": "EDI",
"UnitedSupplierRetailer": false,
"PPACApprovedRetailer": false,
"PrecisionPacException": false,
"ProductKey": "APROACH_PRIMA",
"Quantity": 15,
"UOMKey": "GALLON",
"ApplicationRate": 0,
"TreatedAcres": 0,
"ApplicationRateUOMKey": null,
"UnitPrice": 0,
"CashAmount": 4500,
"CreditAmount": 0,
"LineItemPrice": 4500,
"PurchaseType": "Cash"
},
{
"InvoiceNumber": "217988806",
"PurchaseDate": "2016-04-29T13:25:30+00:00",
"POSType": "EDI",
"UnitedSupplierRetailer": false,
"PPACApprovedRetailer": false,
"PrecisionPacException": false,
"ProductKey": "PREVATHON",
"Quantity": 32.5,
"UOMKey": "GALLON",
"ApplicationRate": 0,
"TreatedAcres": 0,
"ApplicationRateUOMKey": null,
"UnitPrice": 0,
"CashAmount": 4868.5,
"CreditAmount": 0,
"LineItemPrice": 4868.5,
"PurchaseType": "Cash"
}
]
}
]
}
require 'json'
require 'jq/extend'
class LegacyConverter
attr_reader :app, :filter
def initialize(app)
@app = app
@filter = File.read('./script/input_transform.jq')
end
def call(env)
status, headers, body = app.call(env)
[status, headers, body[0].jq(filter)] # if body[0] is a hash
[status, headers, JQ(body[0]).search(filter)] # if body[0] is a string
end
end
{
"operation": {
"operation_id": "O0BQ56RUU2",
"business_partners_details": [
{
"business_partner_id": "B4R6RXL8A2"
},
{
"business_partner_id": "B4R6RXL8A1"
}
],
"properties": [
{
"key": "is_100%_pioneer_seed",
"value": false
},
{
"key": "is_southern_enterprise_participant",
"value": false
},
{
"key": "southern_enterprise_cap",
"value": 0
},
{
"key": "is_mc_gown_offer_eligible",
"value": false
},
{
"key": "override_seed_requirement",
"value": false
},
{
"key": "override_seed_requirement_for_all_programs",
"value": false
}
],
"geography": {
"states": [
"SC",
"MS"
],
"fips_codes": [
23456,
12345
]
}
},
"seed_purchases": [
{
"crop": "Corn",
"uom": "BAG",
"purchase_season": 2016,
"volume": 42
}
],
"chem_purchases": [
{
"product": "Envive",
"uom": "DRY_OUNCE",
"purchase_date": "2015-04-29T13:25:30+00:00",
"volume": 704,
"amount": 3308.8,
"properties": [
{
"key": "precision_pac_exception",
"value": false
},
{
"key": "ppac_approved_retailer",
"value": false
},
{
"key": "purchase_type",
"value": "Cash"
},
{
"key": "united_suppliers_retailer",
"value": false
}
]
},
{
"product": "Envive",
"uom": "DRY_OUNCE",
"purchase_date": "2016-04-29T13:25:30+00:00",
"volume": 704,
"amount": 3308.8,
"properties": [
{
"key": "precision_pac_exception",
"value": false
},
{
"key": "ppac_approved_retailer",
"value": false
},
{
"key": "purchase_type",
"value": "Cash"
},
{
"key": "united_suppliers_retailer",
"value": false
}
]
},
{
"product": "Envive",
"uom": "DRY_OUNCE",
"purchase_date": "2016-04-29T13:25:30+00:00",
"volume": -264,
"amount": -1240.8,
"properties": [
{
"key": "precision_pac_exception",
"value": false
},
{
"key": "ppac_approved_retailer",
"value": false
},
{
"key": "purchase_type",
"value": "Cash"
},
{
"key": "united_suppliers_retailer",
"value": false
}
]
},
{
"product": "APROACH_PRIMA",
"uom": "GALLON",
"purchase_date": "2016-04-29T13:25:30+00:00",
"volume": 15,
"amount": 4500,
"properties": [
{
"key": "precision_pac_exception",
"value": false
},
{
"key": "ppac_approved_retailer",
"value": false
},
{
"key": "purchase_type",
"value": "Cash"
},
{
"key": "united_suppliers_retailer",
"value": false
}
]
},
{
"product": "PREVATHON",
"uom": "GALLON",
"purchase_date": "2016-04-29T13:25:30+00:00",
"volume": 32.5,
"amount": 4868.5,
"properties": [
{
"key": "precision_pac_exception",
"value": false
},
{
"key": "ppac_approved_retailer",
"value": false
},
{
"key": "purchase_type",
"value": "Cash"
},
{
"key": "united_suppliers_retailer",
"value": false
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment