Skip to content
This repository has been archived by the owner on Mar 31, 2021. It is now read-only.

Fix erroneous purchase category definitions #500

Merged
merged 7 commits into from
Dec 21, 2020

Conversation

pierresegonne
Copy link
Member

Description

The identified purchaseCategories correspond to identifiers that don't hold any emission factors. Therefore when bloom activities pointing to these purchaseCategories are created, they won't have any carbon footprint

Misc

For more context, see this issue

Copy link
Contributor

@skovhus skovhus left a comment

Choose a reason for hiding this comment

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

We should add a unit test that verifies that all identifiers returned from bridge or nag is mapped is valid.

@skovhus skovhus assigned skovhus and unassigned pierresegonne Dec 21, 2020
@skovhus
Copy link
Contributor

skovhus commented Dec 21, 2020

@madsnedergaard FYI I found two other issues when adding unit tests for this. :)

@madsnedergaard
Copy link
Member

FYI: We also need to migrate existing activities with incorrect identifier :)

@skovhus
Copy link
Contributor

skovhus commented Dec 21, 2020

FYI: We also need to migrate existing activities with incorrect identifier :)

Yes, I believe this is covered in https://github.com/tmrowco/bloom/issues/292#issuecomment-748224152

Comment on lines 48 to 47
'Basic Expenses': PURCHASE_CATEGORY_FOOD,
'Basic Expenses': null,
Copy link
Member

Choose a reason for hiding this comment

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

Why remove this one? It should point to Food, which is in footprints.yml?

image

image

Copy link
Contributor

Choose a reason for hiding this comment

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

The test didn’t find a carbon intensity. I’ll check. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

So the issue seems to be that https://github.com/tmrowco/bloom-contrib/blob/master/co2eq/purchase/index.js#L51 only adds children... It means that we end up with a "Food" entry without any intensityKilograms. 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

I would expect getEntryByKey('Food') to return an entry with a intensityKilograms... Not sure if this is a regression from #488 or it is working as intended.

Copy link
Member

@madsnedergaard madsnedergaard Dec 21, 2020

Choose a reason for hiding this comment

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

Huh, so it wouldn't be able to run the model with a "parent" identifier?

Copy link
Member

Choose a reason for hiding this comment

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

Works in production right now despite #488 being merged 🤔

image

Copy link
Contributor

@skovhus skovhus Dec 21, 2020

Choose a reason for hiding this comment

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

Hm.

It seems like the purchase model is doing a smarter lookup for the entry and carbon intensity than doing getEntryByKey('Food'). This would means, that the test here is insufficient.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've verified that the activity you linked to, has the Food as identifier. And the carbonModelName is purchase version 9.

Copy link
Contributor

Choose a reason for hiding this comment

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

Turned out to be a Jest caching issue: yarn test --clearCache did the job. Thanks @madsnedergaard !

@madsnedergaard
Copy link
Member

madsnedergaard commented Dec 21, 2020

FYI: We also need to migrate existing activities with incorrect identifier :)

Yes, I believe this is covered in tmrowco/bloom#292 (comment)

Ah, nice - I'll do that migration on prod-database now :)

EDIT Done!

@@ -94,12 +92,12 @@ const idToCategory = {
248: PURCHASE_CATEGORY_STORE_PERSONAL_CARE, // Cosmetics
235: PURCHASE_CATEGORY_STORE_PERSONAL_CARE, // Hairdresser

161: PURCHASE_CATEGORY_HOUSING, // - Home
161: null, // - Home (not sure about the subcategory in PURCHASE_CATEGORY_HOUSING)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have verified that this was not affected by my Jest caching issue. We do not have a carbon footprint for PURCHASE_CATEGORY_HOUSING (HOUSING, WATER, ELECTRICITY, GAS AND OTHER FUELS).

Copy link
Member

@madsnedergaard madsnedergaard left a comment

Choose a reason for hiding this comment

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

Nice! Hope you haven't spend all your time and energy on that shitty cache thing 😬

@skovhus skovhus merged commit cfb318a into master Dec 21, 2020
@skovhus skovhus deleted the ps/fix_erroneous_purchaseCategories branch December 21, 2020 15:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working carbon model 🛒 retail
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants