def test_londo(self):
     results = algorithm.search('londo', 43.70011, -79.4163)
     sorted_search = sorted(results,
                            key=lambda x: x.confidence_level,
                            reverse=True)
     first_city = sorted_search[0]
     self.assertEqual(first_city.name, 'London')
     self.assertEqual(first_city.confidence_level, 0.8362086332750764)
 def test_calgary(self):
     results = algorithm.search('Calgary', 51.012782, -114.3543368)
     sorted_search = sorted(results,
                            key=lambda x: x.confidence_level,
                            reverse=True)
     sorted_search
     first_city = sorted_search[0]
     self.assertEqual(first_city.name, 'Calgary')
     self.assertEqual(first_city.confidence_level, 0.9824211409812602)
     self.assertEqual(first_city.physical_distance, 19.272830905652228)
Example #3
0
def upload_wav():
    # Get query parameters
    query_location = request.args.get('q')
    response = dict()

    if query_location is None:
        logger.error('Location query is None')
        response['error'] = 'Location query must not be empty'
        return json.dumps(response)
    else:
        query_lat = request.args.get('latitude')
        query_long = request.args.get('longitude')

        logger.info(f'Received {query_location} query')

        if query_lat:
            logger.info(
                f'Additional location info: [{query_lat}:{query_long}]')

        results = algorithm.search(query_location, query_lat, query_long)
        sorted_results = sorted(results,
                                key=lambda x: x.confidence_level,
                                reverse=True)
        sorted_results

        logger.info(f'Results: {sorted_results}')
        '''
        TODO
        Wrap up the results into a json response.
        O(n) operation. Is there a better way to encode it to a json response?
        '''
        response['suggestions'] = [{
            'name': result.name,
            'latitude': result.lat,
            'longitude': result.long,
            'score': result.confidence_level
        } for result in sorted_results]
        result = {
            'q': query_location,
            'lat': query_lat,
            'lng': query_long,
            'results': [result.toJSON() for result in sorted_results]
        }

        return json.dumps(response)
Example #4
0
def compute():
    if request.method == 'GET':
        return render_template('compute.html')
    else:
        input1 = request.form['input1']
        app.logger.debug(input1)
        print 'input1: ' + input1

        input2 = request.form['input2']
        app.logger.debug(input2)
        print 'input2: ' + input2

        input3 = request.form['input3']
        app.logger.debug(input3)
        print 'input3: ' + input3

        yamlInput1 = yaml.safe_load(input1)
        app.logger.debug(yamlInput1)
        print 'yamlInput1: ' + str(yamlInput1)
        print yamlInput1

        result1 = search(yamlInput1, int(input2), int(input3))
        print result1
        return render_template('compute.html', result=result1)
Example #5
0
 def test_successful(self):
     self.assertTrue(search(self.array, 20, 5))
Example #6
0
 def test_searchingNoneSuccessful(self):
     self.assertTrue(search([None], None, None))
Example #7
0
 def test_searchingNoneFailed(self):
     self.assertFalse(search(self.array, None, None))
Example #8
0
 def test_emptyArray(self):
     self.assertFalse(search([], 10, 5))
Example #9
0
 def test_failed(self):
     self.assertFalse(search(self.array, 100, 3))
Example #10
0
 def test_searchingNoneSuccessful(self):
     self.assertFalse(search([None], 10, 20))
Example #11
0
 def test_searchingNegativeNumberInPositiveArray(self):
     self.assertFalse(search(self.array, -10, -30))
Example #12
0
 def test_failed(self):
     self.assertFalse(search(self.array, 60, 60))
Example #13
0
File: main.py Project: OrmesKD/PyC
import sys,algorithm
from obj import *

#Hard coded shapes
shape1 = Shape((10,10),(15,10),(15,30),(10,30),(10,10))
shape2 = Shape((30,10),(35,10),(35,30),(30,30),(30,10))
shape3 = Shape((70,10),(75,10),(75,35),(50,35),(50,30),(70,30),(70,10))
shape4 = Shape((85,10),(110,10),(110,35),(105,35),(105,15),(85,15),(85,10))

Shapes = [shape1,shape2,shape3,shape4]

algorithm.search(Shapes)




	


# pygame.init()

# done = False
# clock = pygame.time.Clock()

# while not done:
# 	clock.tick(30)

# 	for event in pygame.event.get():
# 		if event.type == pygame.QUIT:
# 			done = True
Example #14
0
 def test_empty_query(self):
     results = algorithm.search('', None, None)
     sorted_search = sorted(results,
                            key=lambda x: x.confidence_level,
                            reverse=True)
     sorted_search
Example #15
0
 def test_succesfull(self):
     self.assertTrue(search(self.array, 3, 3))