generated from mwc/lab_scatter
I completed the definitions for the scatter plot.
This process was tough. By the end of the last unit, I did think there were concepts that I was beginning to grasp and implement as habit, but these seemed like learning from the start all over again. The minimum and maximum definitions made sense and were easy enough to work through, but when it came to completing the more complex lines of code, I did struggle. One way I found myself troubleshooting was breaking down the steps of the task even further into chunks and trying to write a piece of code for each chunk. I do think there might be places in this submission where I got to the concept, but the way I did so was a little clunky. I tried to find other way to pair down the "clunky-ness" and some of that seemed successful, while other times I am not sure if my solutions were actually optimal. I saw a really interesting post the other day, amid scrolling, that encapsulates this feeling perfectly. The process is like explaining how to make a PB&J to a person. Except you are explaining it to someone who is has never seen or used such items before. I tell them to take out two pieces of bread, all good. Lay them down, all good. now with a knife take peanut butter out of the jar, error. But why is there an error? That is the next step? What is wrong? Well, I never told them to take the lid off... But it would never occur to me to tell them that, everyone should just know that, right? That is how I feel sometimes when I am coding. I feel like i am telling it, just get some peanut butter, but I never told it to do one crucial step first. The trouble is, I don't know what that missing piece is most times. So, it is a lot of trial and error. This can be frustrating. But when it does eventually work, or when pieces begin to work, it is satisfying.
This commit is contained in:
parent
09498ad085
commit
b10bb91c4a
51
transform.py
51
transform.py
|
@ -5,39 +5,46 @@
|
|||
# None of them are finished; this is your job!
|
||||
|
||||
def maximum(data):
|
||||
"Returns the largest number in data"
|
||||
raise NotImplementedError
|
||||
highest = data[0]
|
||||
for number in data:
|
||||
if number > highest:
|
||||
highest = number
|
||||
return highest
|
||||
|
||||
def minimum(data):
|
||||
"Returns the smallest number in data"
|
||||
raise NotImplementedError
|
||||
lowest = None
|
||||
for number in data:
|
||||
if lowest is None:
|
||||
lowest = number
|
||||
if number < lowest:
|
||||
lowest = number
|
||||
return lowest
|
||||
|
||||
def bounds(data):
|
||||
"Returns a list of the smallest and largest numbers in data"
|
||||
raise NotImplementedError
|
||||
return [minimum(data), maximum(data)]
|
||||
|
||||
|
||||
def clamp(value, low, high):
|
||||
"""Clamps a value to a range from low to high.
|
||||
Returns value if it is between low and high.
|
||||
If value is lower than low, returns low. If value is higher than high, returns high.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
return max(low, min(value, high))
|
||||
|
||||
|
||||
def ratio(value, start, end):
|
||||
"""Returns a number from 0.0 to 1.0, representing how far along value is from start to end.
|
||||
The return value is clamped to [0, 1], so even if value is lower than start, the return
|
||||
value will not be lower than 0.0.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
r = (value - start)/(end - start)
|
||||
return clamp(r,0,1)
|
||||
|
||||
def scale(value, domain_min, domain_max, range_min, range_max):
|
||||
"Given a value within a domain, returns the scaled equivalent within range."
|
||||
raise NotImplementedError
|
||||
r = ratio(value, domain_min, domain_max)
|
||||
return range_min + r * (range_max - range_min)
|
||||
|
||||
|
||||
def get_x_values(points):
|
||||
"Returns the first value for each point in points."
|
||||
raise NotImplementedError
|
||||
x_values = []
|
||||
for x, y in points:
|
||||
x_values.append(x)
|
||||
return x_values
|
||||
|
||||
def get_y_values(points):
|
||||
"Returns the second value for each point in points."
|
||||
raise NotImplementedError
|
||||
y_values = []
|
||||
for x, y in points:
|
||||
y_values.append(y)
|
||||
return y_values
|
Loading…
Reference in New Issue