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 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): """ 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_measurement_for_location(location_id): crs_two = db_access.get_location_by_id(location_id) averageValue = 0.0 total = 0.0 item = 0.0 measurementsForSelectedLocation = db_access.get_measurements_for_location(location_id) for i in measurementsForSelectedLocation: total += float(i['value']) item +=1 if item == 0: return None else: averageValue = total/item return averageValue
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 testOneMeasurement(self): meas = db_access.get_measurements_for_location(18) m = filter_first(meas, lambda r: r[0] == 1803) self.assertAlmostEqual(61.11457551359794, m[1], delta=1e-10)
def testNumberOfMeasurements(self): meas = db_access.get_measurements_for_location(18) self.assertEqual(10, len(meas))
def testOneMeasurement(self): meas = db_access.get_measurements_for_location(18) m = filter_first(meas, lambda r: r["measurement_id"] == 1803) self.assertAlmostEqual(61.11457551359794, m["value"], delta=1e-10)
def measurements_in_location(location_id): response.content_type = "application/json" data = get_measurements_for_location(location_id) return dumps(data)
''') # ------------------------------------| start |---------------------------------------------- form = cgi.FieldStorage() try: formLocationID = form.getvalue('location_id') if not db_access.get_location_by_id(formLocationID): printErrorMSG(str(formLocationID)) # ------------------------------------| good data received |---------------------------------------------- else: selectedLocation = db_access.get_location_by_id(formLocationID) measurementsForSelectedLocation = db_access.get_measurements_for_location(formLocationID) # ------------------------------------| HTML Page start |------------------------------------ print(KJM_HTML_Utility.htmlHeader("Selected Location")) print(''' <body> ''') for i in selectedLocation: #header identify the area and location by name. locArea = db_access.get_area_by_id(i['location_area']) itsName = str() for aName in locArea: itsName = aName['name'] print("<h1>" + str(i['name']) + "</h1>\n<h2> Area: " + str(itsName) + "</h2>")