def add_provider(db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude): # if db is enabled, then open a session with the database if db_enabled: session = Session() # create an instance of the Provider type provider = Provider(lastname=lastname, firstname=firstname, credentials=credentials, addr1=addr1, addr2=addr2, city=city, zipcode=zipcode,state=state, latitude=latitude, longitude=longitude) #To check if the record already exists in database p = select([Provider.firstname]).where(Provider.firstname+Provider.lastname+Provider.credentials +Provider.addr1+Provider.addr2 == firstname+lastname+credentials+addr1+addr2) res = session.execute(p) prov_data = res.fetchone() session.close() #To check if record exists, then this step will be skipped if not(prov_data): session = Session() # To fetch the Geographical coordinates from Zip_geotable z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode) result = session.execute(z) geo_data = result.fetchone() if geo_data: latitude = geo_data.latitude longitude= geo_data.longitude #print db_enabled, lastname, firstname, credentials, addr1, addr2, city, zipcode, state,latitude, longitude # create an instance of the Provider type provider = Provider(lastname=lastname, firstname=firstname, credentials=credentials, addr1=addr1, addr2=addr2, city=city, zipcode=zipcode,state=state, latitude=latitude, longitude=longitude) # if db is enabled, then add to the recordset and commit the txn session.add(provider) session.commit() session.close() return provider
def get_station(): session = Session() stations = [] rows = session.execute("select * from station;") for row in rows: stations.append(dict(row)) session.close() return jsonify(stations=stations)
def get_station_available_info(station_id): session = Session() available_info = [] rows = session.execute("select available_bike_stands, available_bikes from bike \ where station_id = {} and last_update = \ (select max(last_update) from bike where station_id = {});".format(station_id, station_id)) for row in rows: print(row) available_info.append(dict(row)) session.close() return jsonify(available_info=available_info)
def get_coordinates(zipcode , miles): session = Session() # To fetch the Geographical coordinates from Zip_geotable z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode) result = session.execute(z) #print result geo_data = result.fetchone() #If zipcode exists in database if geo_data: latitude = geo_data.latitude longitude= geo_data.longitude patient_loc = geopy.Point(latitude,longitude ) #print latitude,longitude find_distance(patient_loc, miles) else: print 'Zipcode not found. Please enter a valid zipcode' session.close()
def get_coordinates(zipcode, miles): session = Session() # To fetch the Geographical coordinates from Zip_geotable z = select([Zip_geo.latitude, Zip_geo.longitude]).where(Zip_geo.zipcode == zipcode) result = session.execute(z) #print result geo_data = result.fetchone() #If zipcode exists in database if geo_data: latitude = geo_data.latitude longitude = geo_data.longitude patient_loc = geopy.Point(latitude, longitude) #print latitude,longitude find_distance(patient_loc, miles) else: print 'Zipcode not found. Please enter a valid zipcode' session.close()
def find_distance(patient_location, miles): session = Session() p = select([Provider.latitude, Provider.longitude]) result = session.execute(p) doc_data = result.fetchall() doc_count = 0 # Checks for each doctor's location in the database for coordinates in doc_data: doc_location = geopy.Point(coordinates.latitude,coordinates.longitude ) dist = geopy.distance.distance(patient_location, doc_location).miles if dist < float(miles): doc_count = doc_count + 1 if doc_count == 0: print 'No doctors found near you in ' + str(miles)+ ' miles' else: print str(doc_count) + ' doctors found near you in ' + str(miles)+ ' miles'
def find_distance(patient_location, miles): session = Session() p = select([Provider.latitude, Provider.longitude]) result = session.execute(p) doc_data = result.fetchall() doc_count = 0 # Checks for each doctor's location in the database for coordinates in doc_data: doc_location = geopy.Point(coordinates.latitude, coordinates.longitude) dist = geopy.distance.distance(patient_location, doc_location).miles if dist < float(miles): doc_count = doc_count + 1 if doc_count == 0: print 'No doctors found near you in ' + str(miles) + ' miles' else: print str(doc_count) + ' doctors found near you in ' + str( miles) + ' miles'
def deleteTable(): session = Session() session.execute("DELETE FROM zones_competent_authorities;") session.execute("DELETE FROM zones_lau_codes;") session.execute("DELETE FROM zone_predecessors;") session.execute("DELETE FROM zone_pollutants;") session.execute("DELETE FROM zone_legal_acts;") session.execute("DELETE FROM zone_time_extension_types;") session.execute("DELETE FROM authorities;") session.execute("DELETE FROM legal_acts;") session.execute("DELETE FROM zones;") session.execute("DELETE FROM authorities;") session.commit()