Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Create extended field values for processing/facility type #1616

Merged
merged 4 commits into from Feb 3, 2022

Conversation

caseycesari
Copy link
Contributor

@caseycesari caseycesari commented Feb 2, 2022

Overview

When the processing_type or facility_type fields are included with facilities submitted via the API or CSV, the field values are matched to facility/processing values in the taxonomy using the matching function. Users can specify single or multiple values. If any of the submitted types are unable to be matched, a parsing error is returned for that facility.

Connects #1583

Demo

Single value submitted for facility type via API

{
  "country": "US",
  "name": "Chestnut 13",
  "address": "1300 Chestnut St Philadelphia, PA 19123",
  "facility_type": "office / hq"
}
...
      "facility_type": [
        {
          "id": 53,
          "verified": false,
          "value": {
            "raw_values": "office / hq",
            "matched_values": [
              [
                "FACILITY_TYPE",
                "EXACT",
                "Office / HQ",
                "Office / HQ"
              ]
            ]
          },
          "updated_at": "2022-02-02T10:46:04.830892Z",
          "contributor_name": "Service Provider A",
          "contributor_id": 2,
          "value_count": 1,
          "is_from_claim": false,
          "field_name": "facility_type"
        }
      ],
...

Multiple values submitted for processing type via CSV

country,name,address,processing_type
US,Chestnut 20,"2000 Chestnut Street, Philadelphia, PA 19123","ginning"|"pulp making"
...
"facility_type": [{
	"id": 58,
	"verified": false,
	"value": {
		"raw_values": "ginning|\"pulp making\"",
		"matched_values": [
			["PROCESSING_TYPE", "EXACT", "Raw Material Processing or Production", "Ginning"],
			["PROCESSING_TYPE", "EXACT", "Raw Material Processing or Production", "Pulp making"]
		]
	},
	"updated_at": "2022-02-02T11:50:00.632581Z",
	"contributor_name": "Service Provider A",
	"contributor_id": 2,
	"value_count": 1,
	"is_from_claim": false,
	"field_name": "facility_type"
}],
"processing_type": [{
	"id": 57,
	"verified": false,
	"value": {
		"raw_values": "ginning|\"pulp making\"",
		"matched_values": [
			["PROCESSING_TYPE", "EXACT", "Raw Material Processing or Production", "Ginning"],
			["PROCESSING_TYPE", "EXACT", "Raw Material Processing or Production", "Pulp making"]
		]
	},
	"updated_at": "2022-02-02T11:50:00.629849Z",
	"contributor_name": "Service Provider A",
	"contributor_id": 2,
	"value_count": 1,
	"is_from_claim": false,
	"field_name": "processing_type"
}],
...

Invalid value is submitted via CSV

Invalid value is submitted via API

Notes

Currently, processing/facility type values are not displayed on the front-end. We may need a follow-up card for this, although there are some cards that may cover this (#1592? #1613?)

Testing Instructions

  • Run ./scripts/update to apply the included migration
  • Try to create facilities with production/facility types via the API and CSV upload. Sample JSON blobs and CSVs can be found in 1605, except replace product_type with processing_type or facility_type.
    • API
      • Test with single facility or processing type. Example: { facility_type: "raw material processing or production" }
      • Test with multiple facility to processing types. Example: { processing_type: ["cutting", "assembly"] }
      • Test with invalid type value. Example: { processing_type: "sdfjasdkjfsakdfjsf" }
      • Test creation of facility type when only processing type is specified: Example: { processing_type: "cutting" }
    • CSV
      • Test with single facility or processing type. Example: "raw material processing or production"
      • Test with multiple facility to processing types. Example: "cutting"|"assembly"
      • Test with invalid type value. Example: "dfsadfasdfsdaf"
      • Test creation of facility type when only processing type is specified. Example: "cutting"

Checklist

  • fixup! commits have been squashed
  • CI passes after rebase
  • CHANGELOG.md updated with summary of features or fixes, following Keep a Changelog guidelines

These will be used when processing facilities that have processing
and/or facility types specified.

Refs #1583
@caseycesari caseycesari force-pushed the cpc/add-extended-field-types branch 3 times, most recently from 04f3e9f to 0d89101 Compare February 2, 2022 12:39
Copy link
Contributor

@jwalgran jwalgran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, clear implementation. I made a suggestion that I think is required to mate the expectations that submitting a value for either field sets values on both.

Comment on lines +99 to +101
if (raw_data.get('processing_type') and
raw_data.get('facility_type') is None):
raw_data['facility_type'] = raw_data['processing_type']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to do this in reverse as well since each facility type is also included as a processing type. Better to err on the side of having the facility show up when searching either field for a particular value.

    if (raw_data.get('facility_type') and
       raw_data.get('processing_type') is None):
        raw_data['processing_type'] = raw_data['facility_type']

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh good point. I'll switch this up.

for field in RAW_DATA_FIELDS:
if field in fields:
field_value = values[fields.index(field)]
create_extendedfield(field, field_value, item, contributor)

# Add a facility_type extended field if the user only
# submitted a processing_type
if ((field == 'processing_type') and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to do this in reverse as well since each facility type is also included as a processing type. Better to err on the side of having the facility show up when searching either field for a particular value.

            if ((field == 'facility_type') and
               'processing_type' not in fields):
                create_extendedfield('processing_type', field_value, item,
                                     contributor)

The field values are used as look-up values in the facility/processing
type matching function. Single and multiple types are handled from both
the API endpoint and when processing a CSV. If any of the submitted
types are unabled to be matched, a parsing error is returned for that
facility.

Refs #1583
The structure of the processing/facility type values are more complex
than the other extended fields and special handling will need to be
implemented before the values can be displayed in the front-end.

Refs #1583
@caseycesari caseycesari merged commit 81827fa into develop Feb 3, 2022
@caseycesari caseycesari deleted the cpc/add-extended-field-types branch February 3, 2022 00:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants