Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@01painadam
Copy link
Contributor

@01painadam 01painadam commented Nov 26, 2018

Overview

Plantations loss / extent / emissions were not being summed over all types in the returned data, instead just taking the first element in the array. Note that plantations are returned with a bound1 or bound2 key.

(I suggest that we review this across all widgets that use forestType === 'plantations')

I have updated the header and loss in plantations widget to handle this. In all cases where there are plantations (and we therefor quote natural forest) we should have the figure in the header:

screen shot 2018-11-26 at 17 17 32

5.07kha in this case ... equal to the tooltip figure here:

screen shot 2018-11-26 at 17 17 41

natural forest: 5.07kha

@01painadam 01painadam requested a review from edbrett November 26, 2018 16:33
Copy link
Contributor

@edbrett edbrett left a comment

Choose a reason for hiding this comment

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

Thanks for the updates. No comments on your new code but some on the old. Maybe you can update quickly?

const returnData = {
...d,
outsideAreaLoss:
totalLossByYear[d.year][0].area - summedPlatationsLoss,
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this was there before but it concerns me. As it is reused a few times can we declare totalLossByYear[d.year][0] as a variable above and then access the keys here. Something like this:

const totalLossForYear = (totalLossByYear[d.year] && totalLossByYear[d.year][0]) || {};

const summedLoss = sumBy(groupedLoss[latestYear], 'area');
const summedEmissions = sumBy(groupedLoss[latestYear], 'emissions');
const data = {
totalArea: (extent[0] && extent[0].total_area) || 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Again here we aren't checking if extent is an array or even if it exists. Can we improve this?

Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs addressing. What is the extent isnt an array? This will crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

plantationsExtent is always a length = 1 array so i've gone with:

plantationsExtent && plantationsExtent.length ? plantationsExtent[0].area : 0,

plantationsloss.data && plantationsloss.data.data;
const totalLoss = gadmLoss.data && gadmLoss.data.data;
if (loss.length && totalLoss.length) {
if (lossPlantations.length && totalLoss.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if lossPlantations is undefined then this will crash also. You need to check for it first before doing an array method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if (lossPlantations && totalLoss && lossPlantations.length && totalLoss.length) { ?

@edbrett edbrett merged commit 5b8242a into develop Nov 29, 2018
@edbrett edbrett deleted the fix/plantations-calc branch November 29, 2018 16:53
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.

3 participants