def FindBusinessBasedOnCity(cityToSearch, savelocation1, collection): businesses - [ for idx in range(len(collection.all())): data_point = collection.fetch(idx) if data_point['city'] == cityToSearch: businesses.append([data_point['name'], data_point['full_address'], data_point['city'], data_point['state']]) f = open(savelocation1, 'w') for attr in businesses: f.write('$'.join(str(s) for s in attr)) f.write('\n') f.close() def FindBusinessBasedonLocation(categoriesToSearch, myLocation, maxDistance, savelocation2, collection): names - [] lati - myLocation[0] lon1 - myLocation[1] for idx in range(len(collection.all())): data_point = collection.fetch(idx) lat2 = data_point['latitude'] lon2 - data_point['longitude'] distance = DistanceFunction(lat2, lon2, lat1, lon1) if distance <= maxDistance: for category in categoriesToSearch: if category in data_point['categories']: names.append(data_point['name']) f = open(savelocation2, 'w') for name in names: f.write(name + '\n') f.close() def DistanceFunction(lat2, lon2, lat1, lon1): R = 3959 phil = math.radians (lat1) phi2 = math.radians (lat2) delta_phi = math.radians (lat2 - lat1) delta_lambda = math.radians (lon2 - lon1) a = math.sin(delta_phi/2) * math.sin(delta_phi/2) + math.cos (phi1) * math.cos(phi2) * math.sin(delta_lambda/2)* math. c = 2 * math.atan2 (math.sqrt(a), math.sqrt(1 - a)) d = R*C return d

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

How does this code work?

What do these functions do?

 

This is Python

def FindBusinessBasedonCity(cityToSearch, saveLocation1, collection):
businesses = []
for idx in range (len (collection.all())):
data_point = collection.fetch(idx)
if data_point['city']
businesses.append([data_point['name'], data_point['full_address'], data_point['city'], data_point['state']])
cityToSearch:
==
f = open (savelLocation1, 'w')
for attr in businesses:
f.write('$'.join(str(s) for s in attr))
f.write('\n')
f.close()
def FindBusinessBasedOnLocation(categoriesToSearch, myLocation, maxDistance, savelocation2, collection):
[]
myLocation[0]
my Location[1]
names =
lati =
lon1 =
for idx in range (len(collection.all())):
data_point = collection.fetch(idx)
lat2 = data_point['latitude']
lon2 =
data_point['longitude']
distance = DistanceFunction (lat2, lon2, lat1, lon1)
if distance <= maxDistance:
%3D
for category in categoriesToSearch:
if category in data_point['categories']:
names.append (data_point['name'])
f = open(savelocation2, 'w')
for name in names:
f.write(name + '\n')
f.close()
def DistanceFunction(lat2, lon2, lat1, lon1):
R = 3959
phil = math.radians (lat1)
phi2 = math.radians (lat2)
delta_phi = math.radians (lat2 - lat1)
delta_lambda = math.radians (lon2 - lon1)
a = math.sin(delta_phi/2) * math.sin(delta_phi/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
d = R * c
math.cos(phil)
math.cos(phi2)
* math.sin(delta_lambda/2)* math.sin(delt
+
return d
Transcribed Image Text:def FindBusinessBasedonCity(cityToSearch, saveLocation1, collection): businesses = [] for idx in range (len (collection.all())): data_point = collection.fetch(idx) if data_point['city'] businesses.append([data_point['name'], data_point['full_address'], data_point['city'], data_point['state']]) cityToSearch: == f = open (savelLocation1, 'w') for attr in businesses: f.write('$'.join(str(s) for s in attr)) f.write('\n') f.close() def FindBusinessBasedOnLocation(categoriesToSearch, myLocation, maxDistance, savelocation2, collection): [] myLocation[0] my Location[1] names = lati = lon1 = for idx in range (len(collection.all())): data_point = collection.fetch(idx) lat2 = data_point['latitude'] lon2 = data_point['longitude'] distance = DistanceFunction (lat2, lon2, lat1, lon1) if distance <= maxDistance: %3D for category in categoriesToSearch: if category in data_point['categories']: names.append (data_point['name']) f = open(savelocation2, 'w') for name in names: f.write(name + '\n') f.close() def DistanceFunction(lat2, lon2, lat1, lon1): R = 3959 phil = math.radians (lat1) phi2 = math.radians (lat2) delta_phi = math.radians (lat2 - lat1) delta_lambda = math.radians (lon2 - lon1) a = math.sin(delta_phi/2) * math.sin(delta_phi/2) c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) d = R * c math.cos(phil) math.cos(phi2) * math.sin(delta_lambda/2)* math.sin(delt + return d
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Hash Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education