Skip to content
Snippets Groups Projects

Resolve "Introduce a function to return the expected average number of stories for a taxonomy string"

Files
2
+ 42
0
@@ -251,3 +251,45 @@ class Taxonomy:
self._taxonomy_dict[section] = content
else:
raise ValueError("Taxonomy section does not exist")
def get_number_of_stories(self):
"""
Gets the number of stories as defined in the taxonomy dictionary. The function returns
the exact number of stories if possible or a best estimate average number based on the
given range of stories in the taxonomy string. Additionally, the minimum and maximum
values are returned (same as number of stories if exactly defined, and `None` for the
maximum if not defined in the taxonomy dictionary).
Returns:
A tuple containing the number of stories, the minimum number of stories and the
maximum number of stories.
"""
try:
section = self.get_section("height")
except ValueError:
return None, None, None
key, value = section.split(":")
if key == "HBET":
values = value.split("-")
if values[0] == "":
min_stories = 1
else:
min_stories = int(values[0])
if min_stories < 1:
raise ValueError("Building cannot have fewer than 1 story")
if values[1] == "":
max_stories = None
num_stories = min_stories + 1
else:
max_stories = int(values[1])
num_stories = (min_stories + max_stories) / 2
elif key == "H" or key == "HEX":
num_stories = int(value)
min_stories = num_stories
max_stories = num_stories
else:
raise ValueError("Unknown height tag in taxonomy string")
return num_stories, min_stories, max_stories
Loading