From 2130f4fbce678b4b4c6ad4d420708bc8eaacb589 Mon Sep 17 00:00:00 2001
From: Owen Graham <ohgraham1@madisoncollege.edu>
Date: Thu, 19 May 2022 15:47:42 -0500
Subject: [PATCH] Document more Python functions

---
 visualizer.py | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/visualizer.py b/visualizer.py
index a6068e6..da93550 100755
--- a/visualizer.py
+++ b/visualizer.py
@@ -114,7 +114,7 @@ def read_stations():
 
 @app.route('/record/years')
 def record_years():
-    """Return a JSON list of years for the selected station."""
+    """Return a list of years for the selected station."""
     station = get_station(get_param('station'))
     years = [i['year'] for i in station['records']]
     return jsonify(years)
@@ -122,6 +122,7 @@ def record_years():
 
 @app.route('/plot/boxplot')
 def plot_boxplot():
+    """Boxplot one station/measurement @ multiple years."""
     station_id = get_param('station')
     year1 = get_param('year1', to=year_type)
     year2 = get_param('year2', to=year_type)
@@ -171,6 +172,7 @@ def plot_boxplot():
 
 @app.route('/plot')
 def plot():
+    """Plot one station/year/measurement."""
     station_id = get_param('station')
     year = get_param('year', to=year_type)
     meas = get_param('measurement', to=meas_type)
@@ -203,6 +205,7 @@ def plot():
 
 @app.route('/plot/overlay')
 def plot_overlay():
+    """Plot two station/years @ one measurement."""
     num_datasets = 2
     datasets = tuple(SimpleNamespace() for _ in range(num_datasets))
     stations = read_stations()
@@ -266,7 +269,7 @@ def savefig_response(fig):
 
 
 def get_param(key, to=str):
-    """Get a value from the query string.
+    """Get a parameter from the query string.
 
     Calls `abort(400)` if the value is the wrong type or missing.
     """
@@ -299,7 +302,7 @@ def year_type(s):
 def get_link(station, year):
     """Get the link to a dataset.
 
-    Calls `abort(404)` if there is no link/record for the given year.
+    Calls `abort(404)` if none is found.
     """
     for record in station['records']:
         if record['year'] == year:
@@ -309,15 +312,16 @@ def get_link(station, year):
 
 @app.route('/record/link')
 def record_link():
+    """Return the source link for the selected dataset."""
     station = get_station(get_param('station'))
     year = get_param('year', to=year_type)
     return jsonify(get_link(station, year))
 
 
 def get_station(station_id, stations=None):
-    """Get the station record corresponding to the station ID.
+    """Get a station record by ID.
 
-    Calls `abort(404)` if there is none."""
+    Calls `abort(404)` if none is found."""
     if stations is None:
         stations = read_stations()
     for station in stations:
@@ -327,6 +331,7 @@ def get_station(station_id, stations=None):
 
 
 def get_resources(link):
+    """Fetch the download links for a dataset."""
     doc = jsonld.flatten(link + '.jsonld')
     for i in doc:
         types = i.get('@type', [])
@@ -345,6 +350,7 @@ def get_resources(link):
 
 
 def read_data(station, year):
+    """Fetch data and convert it to a NumPy array."""
     data = []
     resource_list = get_resources(get_link(station, year))
     for url in resource_list:
-- 
GitLab