python 3.x - My sqlite3 cursor has less rows than expected -


in following code have 2 cursors first loc_crs should have 3 rows in it. when run program loc_crs seems have 1 row

import db_access  def get_average_measurements_for_area(area_id): """ returns average value of measurements locations in given area. returns none if there no measurements. """ loc_crs = db_access.get_locations_for_area(area_id)  avg = 0 loc_row in loc_crs:      loc_id = int(loc_row['location_id'])     meas_crs = db_access.get_measurements_for_location(loc_id)      meas_row in meas_crs:         meas = float(meas_row['value'])         avg += meas         # print("meas: ", str(meas))      print("loc_id: ", str(loc_id)) print(str(avg)) 

get_average_measurements_for_area(3)

this output.

loc_id:  16 avg:  568.2259127787871 

edit: here methods being called:

def get_locations_for_area(area_id): """ return list of dictionaries giving locations given area. """ cmd = 'select * location location_area ?' crs.execute(cmd, [area_id])  return crs  def get_measurements_for_location(location_id): """ return list of dictionaries giving measurement rows given location. """ cmd = 'select value measurement measurement_location ?' crs.execute(cmd, [location_id]) return crs 

here link database: http://cs.kennesaw.edu/~bsetzer/4320su15/extra/databases/measurements/measures.sqlite


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -