Skip to content

Conversation

@thomaskileyukaea
Copy link
Owner

@thomaskileyukaea thomaskileyukaea commented Jul 27, 2023

As per SR.1.1.1 add ability to calculate standard deviation for each day and then present this in the graphs show to the user.

Copy link

@bielsnohr bielsnohr left a comment

Choose a reason for hiding this comment

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

Overall, looking good. A few suggested changes to consider. Also, there are some tests that I would expect to see for this new feature:

  • We should use some 2D data rather than just the 1D used here
  • We should have some data with invalid values and check that the functions deal with these edge cases
  • A test where the rows of a 2D matrix have been swapped around to check that the standard deviation is invariant (row swaps shouldn't affect its value).


def s_dev(data):
"""Computes and returns standard deviation for data."""
number = np.mean(data, axis=0)

Choose a reason for hiding this comment

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

I don't immediately know what the purpose of the number variable is from its name. Based on its assignment, it is the mean along one axis, so perhaps it should be called data_mean or event just mean?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Resolved by using np.std

Comment on lines +38 to +43
number = np.mean(data, axis=0)
devs = []
for entry in data:
devs.append((entry - number) * (entry - number))

s_dev2 = sum(devs) / len(data)

Choose a reason for hiding this comment

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

This is an implementation of standard deviation from the ground up. We could probably replace with a call to np.std.

devs.append((entry - number) * (entry - number))

s_dev2 = sum(devs) / len(data)
return {'standard deviation': s_dev2}

Choose a reason for hiding this comment

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

Returning a dict doesn't match what is returned for all of the other functions in this module. We should probably switch to just returning the calculated value.

Choose a reason for hiding this comment

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

And it mixes in responsibilites that should be with the view

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