def get_average_measurements_for_area(area_id): """ Returns the average value of all measurements for all locations in the given area Returns None if there are no measurements. """ # create a list of tuples containing the area to be measured locations = get_locations_for_area(area_id) # utility variables total = 0 counter = 0 # Loops through locations and adds the measurements for eah location to a total for row in locations: location_id = row[0] # Gets the measurement measurements = get_measurements_for_location(location_id) for col in measurements: # Adds measure to total total += col[1] # Counts number of locations counter += 1 # Checks to see if there is no values if total != 0: return total / counter else: return None
def get_average_measurements_for_area(area_id): rVal = 0 id = get_locations_for_area(area_id) if not id: return None lst = [] for z in id: lst.append(z['location_id']) if not lst: return None summe = [] three = [] for r in lst: summe = (get_measurements_for_location(r)) if summe: three += (summe) sum = 0 total = len(three) for e in three: sum += e['value'] rVal = sum/total return rVal """
def number_of_locations_by_area(area_id): """ Returns the number of locations for the given area. """ my_tuple = db_access.get_locations_for_area(area_id) #print(len(my_tuple)) return len(my_tuple)
def number_of_locations_by_area(area_id): """ Returns the number of locations for the given area. """ if area_id == '': raise Exception("area ID could not be ''") locations = db_access.get_locations_for_area(area_id) return len(locations)
def number_of_locations_by_area(area_id): """ Returns the number of locations for the given area. """ # gets the locations locations = get_locations_for_area(area_id) # counts the total number of locations counter = 0 for row in locations: counter += 1 # Returns the total amount return counter
def get_average_measurements_for_area(area_id): """ Returns the average value of all measurements for all locations in the given area. Returns None if there are no measurements. """ locations = db_access.get_locations_for_area(area_id) if len(locations) == 0: return None else: return_table = [] for i in locations: for k in db_access.get_measurements_for_location(i[0]): return_table.append(k[1]) return mean(return_table)
def get_average_measurements_for_area(area_id): """ Returns the average value of all measurements for all locations in the given area. Returns None if there are no measurements. """ locations = db_access.get_locations_for_area(area_id) if len(locations) == 0: return None else: me_irl = [] for i in locations: for j in db_access.get_measurements_for_location(i[0]): me_irl.append(j[1]) if len(me_irl) == 0: return None else: return statistics.mean(me_irl)
def get_average_measurements_for_area(area_id): """ Returns the average value of all measurements for all locations in the given area. Returns None if there are no measurements. """ measurement_total = 0 count = 0 my_tuple = db_access.get_locations_for_area(area_id) #print(my_tuple) for row in my_tuple: my_tuple_loc = db_access.get_measurements_for_location(row[0]) #print my_tuple_loc for row_loc in my_tuple_loc: count = count + 1 measurement_total = measurement_total + row_loc[1] if count == 0: return None return measurement_total / count
def get_average_measurements_for_area(area_id): """ Returns the average value of all measurements for all locations in the given area. Returns None if there are no measurements. """ crs_two = db_access.get_locations_for_area(area_id) averageValue = 0.0 total = 0.0 item = 0.0 for row in crs_two: anID = int(row['location_id']) measurementCRS = db_access.get_measurements_for_location(anID) for measurementRow in measurementCRS: total += float(measurementRow['value']) item +=1 if item == 0: return None else: averageValue = total/item return averageValue
def testOneLocation(self): locs = db_access.get_locations_for_area(3) m = filter_first(locs, lambda r: r[0] == 18) self.assertEqual('Mall', m[1])
def number_of_locations_by_area(area_id): id = get_locations_for_area(area_id) num = len(id) # print(num) return num """
def testNumberOfLocations(self): locs = db_access.get_locations_for_area(3) self.assertEqual(len(locs), 4)
if user_val != None and bool: val = get_area_by_id(user_val) if val == None: #lines 44-49 will detect if a user has submitted a value which can't be found within the database a = get_all_areas() print("<div id=\"error_page1\"><strong>ERROR: User entered an ID which was not found!</strong></br>Select an Area</br><form method=\"get\" action=\"/cgi-bin/location_table.py\"><select name=\"area_id\" size=\"5\"></div>") for x in a: print("<option value=\"" + str(x['area_id']) + "\">" + x['name'] + "</option>") print("</select></br><input id=\"sButton\" type=\"submit\" value=\"Submit\"></form></div></div></body></html>") else: # print("test", val) for a in val: print("<div id=\"page_body2\">Location Information for the " + a['name'] + " area </br></br>") print("<form method =\"get\" action=\"/cgi-bin/measurement_table.py\"><table class=\"grid\"><th class=\"grid\">Select</th><th class=\"grid\">ID</th><th class=\"grid\">Name</th><th class=\"grid\">Altitude</th>") for x in get_locations_for_area(user_val): # print("<tr> <td><input type=\"radio\" value=\"" + x['name'] + "\" name=\"" + x['name'] + "\"></td> <td>" + str(x['location_id']) + " </td> <td>" + x['name'] + " </td> <td>" + str(x['altitude']) + " </td> </tr>") print("<tr> <td><input type=\"radio\" value=\"" + str(x['location_id']) + "\" name=\"location_id\"></td> <td>" + str(x['location_id']) + " </td> <td>" + x['name'] + " </td> <td>" + str(x['altitude']) + " </td> </tr>") print("</table></br><input id=\"sButton\" type=\"submit\"></form></div></body></html>") elif user_val == None: #lines 63-68 will detect if a user hasn't subimtted any data a = get_all_areas() print("<div id=\"error_page1\"><strong>ERROR: User did not make a valid selection.</strong></br>Select an Area</br><form method=\"get\" action=\"/cgi-bin/location_table.py\"><select name=\"area_id\" size=\"5\"></div>") for x in a: print("<option value=\"" + str(x['area_id']) + "\">" + x['name'] + "</option>") print("</select></br><input id=\"sButton\" type=\"submit\" value=\"Submit\"></form></div></div></body></html>") # elif type(user_val) == int: #lines 70-75 will detect if a user has submitted an integer value instead of a string elif bool == False: #lines 70-75 will detect if a user has submitted an integer value instead of a string
def testOneLocation(self): locs = db_access.get_locations_for_area(3) m = filter_first(locs, lambda r: r["location_id"] == 18) self.assertEqual("Mall", m["name"])
selectedArea = db_access.get_area_by_id(formAreaID) print(KJM_HTML_Utility.htmlHeader("Selected Area")) print(''' <body> ''') theAreaName = str() theAreaID = 0 for i in selectedArea: theAreaName = i['name'] theAreaID = i['area_id'] print("<h1>Location information for " + theAreaName +"</h1>") area_locations = db_access.get_locations_for_area(theAreaID) if area_locations: # create a table for the location print(''' <table class="grid"> <thead> <tr> <th>Select</th> <th>ID</th> <th>Name</th> <th>Altitude</th> </tr> </thead> <tbody> <html>
def number_of_locations_by_area(area_id): """ Returns the number of locations for the given area. """ return len(db_access.get_locations_for_area(area_id))
def location_area(area_id): data = get_locations_for_area(area_id) response.content_type = "application/json" return dumps(data)
categoryString = '' theCategory = [] try: for i in aList: theCategory.append(i['name']) countString = len(area_category) for i in theCategory: categoryString += i if countString > 1: categoryString += ', ' countString += -1 except TypeError: categoryString = '' return categoryString # ------------------------------------| Pretty Print |---------------------------------------------- for area in areas: area_id = area['area_id'] area_location = db_access.get_locations_for_area(area_id) area_category = db_access.get_categories_for_area(area_id) avgMeasurementString = str( db_utility.get_average_measurements_for_area(area_id)) if not db_utility.get_average_measurements_for_area(area_id): avgMeasurementString = '--------' # Final output row = template.format(area_id, area['name'], len(area_location), avgMeasurementString,getCategoryString(area_category)) print(row)