Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCFS-1207: Adding new columns to Other Use #1269

Open
wants to merge 6 commits into
base: release-0.2.0
Choose a base branch
from

Conversation

areyeslo
Copy link
Collaborator

Add new columns to the Fuels for Other Use AG grid table in the compliance report and Report Details:

  • Determining Carbon Intensity
  • Fuel Code
  • CI of Fuel
    image

image

Copy link

github-actions bot commented Nov 21, 2024

Backend Test Results

400 tests  ±0   400 ✅ ±0   1m 33s ⏱️ +6s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 4c6d8af. ± Comparison against base commit 3d6f8e0.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Nov 21, 2024

Frontend Test Results

  1 files  ±0  114 suites  ±0   38s ⏱️ +3s
367 tests ±0  347 ✅ ±0  20 💤 ±0  0 ❌ ±0 
369 runs  ±0  349 ✅ ±0  20 💤 ±0  0 ❌ ±0 

Results for commit 4c6d8af. ± Comparison against base commit 3d6f8e0.

♻️ This comment has been updated with latest results.

@areyeslo areyeslo force-pushed the LCFS-1207-AddColumnsToOtherUse_v2 branch from d78f715 to 714de3f Compare November 21, 2024 16:57
Copy link
Collaborator

@dhaselhan dhaselhan left a comment

Choose a reason for hiding this comment

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

Tests needs to be fixed

@areyeslo areyeslo force-pushed the LCFS-1207-AddColumnsToOtherUse_v2 branch 4 times, most recently from 85c1f6e to 22d783f Compare November 21, 2024 18:44
@areyeslo
Copy link
Collaborator Author

Tests passing :)

@areyeslo areyeslo force-pushed the LCFS-1207-AddColumnsToOtherUse_v2 branch from 22d783f to 1d5a193 Compare November 21, 2024 19:43
@@ -136,9 +136,27 @@ async def test_save_other_uses_row_create(
) as mock_validate_organization_access:
set_mock_user(fastapi_app, [RoleEnum.SUPPLIER])
url = fastapi_app.url_path_for("save_other_uses_row")
payload = create_mock_schema({}).model_dump()
payload = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you moving away from the create_mock_schema helper?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you!

"quantitySupplied": "Quantity supplied",
"addressForService": "Address for service",
"legalName": "Legal name",
"complianceReportId": "Compliance Report ID",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use title case normally, was this part of the requirements?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you!

params.colDef.field
)
) {
let ciOfFuel = 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Put this in a helper function so I can better understand what its trying to do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Considering the following object:

{
    "fuelTypeId": 1,
    "fuelType": "Biodiesel",
    "fossilDerived": null,
    "provision1Id": null,
    "provision2Id": null,
    "defaultCarbonIntensity": 100.21,
    "fuelCodes": [
        {
            "fuelCodeId": 2,
            "fuelCode": "BCLCF124.4",
            "carbonIntensity": 3.62
        },
        {
            "fuelCodeId": 3,
            "fuelCode": "BCLCF125.4",
            "carbonIntensity": -2.14
        },
        {
            "fuelCodeId": 4,
            "fuelCode": "BCLCF138.5",
            "carbonIntensity": 4.26
        },
        {
            "fuelCodeId": 6,
            "fuelCode": "BCLCF251.2",
            "carbonIntensity": 0.35
        },
        {
            "fuelCodeId": 8,
            "fuelCode": "BCLCF274.2",
            "carbonIntensity": -15.03
        },
        {
            "fuelCodeId": 15,
            "fuelCode": "BCLCF362.1",
            "carbonIntensity": -1
        }
    ],
    "provisionOfTheAct": [
        {
            "provisionOfTheActId": 2,
            "name": "Fuel code - section 19 (b) (i)"
        },
        {
            "provisionOfTheActId": 3,
            "name": "Default carbon intensity - section 19 (b) (ii)"
        }
    ],
    "units": "L"
}

We are just checking if provision_of_the_act is 'Fuel code - section 19 (b) (i)', If it is the case, then we find the fuel_code associated to the fuel_type selected and provide the value to ciOfFuel. Otherwise, just take the value from defaultCarbonIntensity in fuel_type. which in this case is 100.21.

@@ -107,6 +107,38 @@ export const AddEditOtherUses = () => {
}
}

const onCellValueChanged = useCallback(
async (params) => {
if (params.colDef.field === 'provisionOfTheAct') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this only applies to a single value, it should be in the valueSetter of that column in _schema

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you see this comment?

headerName: t('otherUses:otherUsesColLabels.ciOfFuel'),
field: 'ciOfFuel',
floatingFilter: false,
valueFormatter: (params) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use decimalFormatter instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you!

frontend/src/views/OtherUses/_schema.jsx Show resolved Hide resolved
@areyeslo areyeslo force-pushed the LCFS-1207-AddColumnsToOtherUse_v2 branch 2 times, most recently from dac6903 to 7708949 Compare November 22, 2024 21:03
@@ -92,7 +98,7 @@ export const otherUsesColDefs = (optionsData, errors) => [
},
{
field: 'fuelCategory',
headerName: i18n.t('otherUses:otherUsesColLabels.fuelCategory'),
headerName: i18n.t('otherUses:otherUsesColLabels.fuelCategory'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spacing

@@ -119,7 +219,8 @@ export const otherUsesColDefs = (optionsData, errors) => [
min: 0,
showStepperButtons: false
},
cellStyle: (params) => StandardCellErrors(params, errors)
cellStyle: (params) => StandardCellErrors(params, errors),
minWidth: 200
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spacing

},
{
field: 'rationale',
flex: 1,
headerName: i18n.t('otherUses:otherUsesColLabels.otherExpectedUse'),
cellEditor: 'agTextCellEditor',
cellDataType: 'text',
editable: (params) => params.data.expectedUse === 'Other'
editable: (params) => params.data.expectedUse === 'Other',
minWidth: 300
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spacing

@@ -155,15 +291,17 @@ export const otherUsesColDefs = (optionsData, errors) => [
suppressKeyboardEvent,
cellRenderer: (params) =>
params.value || <Typography variant="body4">Select</Typography>,
cellStyle: (params) => StandardCellErrors(params, errors)
cellStyle: (params) => StandardCellErrors(params, errors),
minWidth: 200
Copy link
Collaborator

Choose a reason for hiding this comment

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

Spacing

@@ -107,6 +107,38 @@ export const AddEditOtherUses = () => {
}
}

const onCellValueChanged = useCallback(
async (params) => {
if (params.colDef.field === 'provisionOfTheAct') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you see this comment?

@@ -47,6 +47,20 @@ export const AddEditOtherUses = () => {
}
}, [location.state])

// If otherUses data is available, set the rowData
useEffect(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like a duplicate of the code below. Why do we need this since its being set in onGridReady?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is just for updates. Once the record is saved for first time, there is a race condition that otherUses is not loaded, so I have to wait until the data is available.

@@ -29,21 +43,25 @@ def create_mock_entity(overrides: dict):


def create_mock_schema(overrides: dict):
mock_schema = OtherUsesCreateSchema(
Copy link
Collaborator

@dhaselhan dhaselhan Nov 25, 2024

Choose a reason for hiding this comment

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

Why are you moving away from a typed object?

mock_compliance_report_uuid = "mock_group_uuid"

# Mock the first db.execute call for fetching compliance report group UUID
mock_first_execute = MagicMock()
mock_first_execute.scalar.return_value = mock_compliance_report_uuid

# Create a realistic mock other_use object
mock_other_use = MagicMock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you not using create_mock_entity?

valueFormatter: (params) => parseFloat(params.value).toFixed(2),
cellStyle: (params) => StandardCellErrors(params, errors),
editable: false,
valueGetter: (params) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is being properly set on the backend, why do we need such a complex getter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

because there are dependencies based on the selection of the user. This is related to the comment above:
Considering the following object:

{
    "fuelTypeId": 1,
    "fuelType": "Biodiesel",
    "fossilDerived": null,
    "provision1Id": null,
    "provision2Id": null,
    "defaultCarbonIntensity": 100.21,
    "fuelCodes": [
        {
            "fuelCodeId": 2,
            "fuelCode": "BCLCF124.4",
            "carbonIntensity": 3.62
        },
        {
            "fuelCodeId": 3,
            "fuelCode": "BCLCF125.4",
            "carbonIntensity": -2.14
        },
        {
            "fuelCodeId": 4,
            "fuelCode": "BCLCF138.5",
            "carbonIntensity": 4.26
        },
        {
            "fuelCodeId": 6,
            "fuelCode": "BCLCF251.2",
            "carbonIntensity": 0.35
        },
        {
            "fuelCodeId": 8,
            "fuelCode": "BCLCF274.2",
            "carbonIntensity": -15.03
        },
        {
            "fuelCodeId": 15,
            "fuelCode": "BCLCF362.1",
            "carbonIntensity": -1
        }
    ],
    "provisionOfTheAct": [
        {
            "provisionOfTheActId": 2,
            "name": "Fuel code - section 19 (b) (i)"
        },
        {
            "provisionOfTheActId": 3,
            "name": "Default carbon intensity - section 19 (b) (ii)"
        }
    ],
    "units": "L"
}

We are just checking if provision_of_the_act is 'Fuel code - section 19 (b) (i)', If it is the case, then we find the fuel_code associated to the fuel_type selected and provide the value to ciOfFuel. Otherwise, just take the value from defaultCarbonIntensity in fuel_type. which in this case is 100.21.

@areyeslo areyeslo force-pushed the LCFS-1207-AddColumnsToOtherUse_v2 branch from a07288a to d7abb36 Compare November 26, 2024 01:13
@areyeslo areyeslo force-pushed the LCFS-1207-AddColumnsToOtherUse_v2 branch from d7abb36 to 0fb1b0a Compare November 26, 2024 01:13
@areyeslo areyeslo force-pushed the LCFS-1207-AddColumnsToOtherUse_v2 branch from 0fb1b0a to 49d186c Compare November 26, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants