generated from mwc/lab_scatter
Checkpoint 2
Writingthe code for this wasn't terribly difficult once I figured out what i needed to do. I didn't quite understand the purpose of each function in the context of the overall program, which made the scale function difficult to write at first. When I did get stuck I used the already existing code as well as the examples in the lab to help me figure out what I needed to write.
This commit is contained in:
parent
8e57a173bb
commit
f6cfe7235a
|
@ -342,13 +342,13 @@ files = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sphinx"
|
name = "sphinx"
|
||||||
version = "7.1.1"
|
version = "7.1.2"
|
||||||
description = "Python documentation generator"
|
description = "Python documentation generator"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=3.8"
|
python-versions = ">=3.8"
|
||||||
files = [
|
files = [
|
||||||
{file = "sphinx-7.1.1-py3-none-any.whl", hash = "sha256:4e6c5ea477afa0fb90815210fd1312012e1d7542589ab251ac9b53b7c0751bce"},
|
{file = "sphinx-7.1.2-py3-none-any.whl", hash = "sha256:d170a81825b2fcacb6dfd5a0d7f578a053e45d3f2b153fecc948c37344eb4cbe"},
|
||||||
{file = "sphinx-7.1.1.tar.gz", hash = "sha256:59b8e391f0768a96cd233e8300fe7f0a8dc2f64f83dc2a54336a9a84f428ff4e"},
|
{file = "sphinx-7.1.2.tar.gz", hash = "sha256:780f4d32f1d7d1126576e0e5ecc19dc32ab76cd24e950228dcf7b1f6d3d9e22f"},
|
||||||
]
|
]
|
||||||
|
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
|
|
|
@ -21,14 +21,14 @@ test(minimum, [[0, 1, 2, 3]], 0)
|
||||||
test(minimum, [[-10, -20, -30]], -30)
|
test(minimum, [[-10, -20, -30]], -30)
|
||||||
test(bounds, [[0, 1, 2, 3]], [0, 3])
|
test(bounds, [[0, 1, 2, 3]], [0, 3])
|
||||||
test(bounds, [[-10, -20, -30]], [-30, -10])
|
test(bounds, [[-10, -20, -30]], [-30, -10])
|
||||||
test(clamp, [[10, 0, 100]], 10)
|
test(clamp, [10, 0, 100], 10)
|
||||||
test(clamp, [[-10, 0, 100]], 0)
|
test(clamp, [-10, 0, 100], 0)
|
||||||
test(clamp, [[104, 0, 100]], 100)
|
test(clamp, [104, 0, 100], 100)
|
||||||
test(ratio, [[5, 0, 10]], 0.5)
|
test(ratio, [5, 0, 10], 0.5)
|
||||||
test(ratio, [[167, 100, 200]], 0.67)
|
test(ratio, [167, 100, 200], 0.67)
|
||||||
test(ratio, [[8, 10, 0]], 0.2)
|
test(ratio, [8, 10, 0], 0.2)
|
||||||
test(ratio, [[4, 10, 20]], 0.0)
|
test(ratio, [4, 10, 20], 0.0)
|
||||||
test(scale, [[4, 0, 10, 0, 100]], 40)
|
test(scale, [4, 0, 10, 0, 100], 40)
|
||||||
test(scale, [[180, 120, 240, 0, 100]], 50)
|
test(scale, [180, 120, 240, 0, 100], 50)
|
||||||
test(get_x_values, [[[0, 5], [1, 5], [2, 5]]], [0, 1, 2])
|
test(get_x_values, [[[0, 5], [1, 5], [2, 5]]], [0, 1, 2])
|
||||||
test(get_y_values, [[[0, 5], [1, 5], [2, 5]]], [5, 5, 5])
|
test(get_y_values, [[[0, 5], [1, 5], [2, 5]]], [5, 5, 5])
|
||||||
|
|
51
transform.py
51
transform.py
|
@ -6,38 +6,67 @@
|
||||||
|
|
||||||
def maximum(data):
|
def maximum(data):
|
||||||
"Returns the largest number in data"
|
"Returns the largest number in data"
|
||||||
raise NotImplementedError
|
highest = None
|
||||||
|
for number in data:
|
||||||
|
if highest is None:
|
||||||
|
highest = number
|
||||||
|
if number > highest:
|
||||||
|
highest = number
|
||||||
|
return highest
|
||||||
|
|
||||||
def minimum(data):
|
def minimum(data):
|
||||||
"Returns the smallest number in 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):
|
def bounds(data):
|
||||||
"Returns a list of the smallest and largest numbers in data"
|
"Returns a list of the smallest and largest numbers in data"
|
||||||
raise NotImplementedError
|
min = minimum(data)
|
||||||
|
max = maximum(data)
|
||||||
|
bounds = [min, max]
|
||||||
|
return bounds
|
||||||
|
|
||||||
def clamp(value, low, high):
|
def clamp(value, low, high):
|
||||||
"""Clamps a value to a range from low to high.
|
"""Clamps a value to a range from low to high.
|
||||||
Returns value if it is between low and 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.
|
If value is lower than low, returns low. If value is higher than high, returns high.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
if value < low:
|
||||||
|
return low
|
||||||
|
elif value > high:
|
||||||
|
return high
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
def ratio(value, start, end):
|
def ratio(value, start, end):
|
||||||
"""Returns a number from 0.0 to 1.0, representing how far along value is from start to end.
|
"""Returns a number from 0.0 to 1.0, representing how far along value is
|
||||||
The return value is clamped to [0, 1], so even if value is lower than start, the return
|
from start to end.The return value is clamped to [0, 1], so even if value
|
||||||
value will not be lower than 0.0.
|
is lower than start, the return value will not be lower than 0.0.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
number = ((value - start)/(end - start))
|
||||||
|
number = clamp(number, 0.0, 1.0)
|
||||||
|
return number
|
||||||
|
|
||||||
def scale(value, domain_min, domain_max, range_min, range_max):
|
def scale(value, domain_min, domain_max, range_min, range_max):
|
||||||
"Given a value within a domain, returns the scaled equivalent within range."
|
"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):
|
def get_x_values(points):
|
||||||
"Returns the first value for each point in points."
|
"Returns the first value for each point in points."
|
||||||
raise NotImplementedError
|
x_list = []
|
||||||
|
for data in points:
|
||||||
|
x_list.append(data[0])
|
||||||
|
return x_list
|
||||||
|
|
||||||
def get_y_values(points):
|
def get_y_values(points):
|
||||||
"Returns the second value for each point in points."
|
"Returns the second value for each point in points."
|
||||||
raise NotImplementedError
|
y_list = []
|
||||||
|
for data in points:
|
||||||
|
y_list.append(data[1])
|
||||||
|
return y_list
|
Loading…
Reference in New Issue