def test_calculate_distance(self):
        loc1 = Location("90", "0")
        loc2 = Location("0", "0")
        self.assertEqual(pi * RADIUS / 2, calculate_distance(loc1, loc2))

        loc1 = Location("0", "180")
        loc2 = Location("0", "0")
        self.assertEqual(pi * RADIUS, calculate_distance(loc1, loc2))
 def test_create_location_with_invalid_input(self):
     """
     coordinates are always in the form of float, if invalid
     coordinates are passed like ascii it should throw proper exception
     """
     invalid_lat = 'test_lat'
     invalid_lon = 'test_lon'
     with self.assertRaises(InvalidLatLonException):
         Location.createFrom(self.city, invalid_lat, invalid_lon)
 def test_calculate_distance(self):
     """
     this test distance between two known point to
     check if distance calculation formula is working fine.
     """
     origin_coord = Location.createFrom(self.origin_city, self.origin_lat,
                                        self.origin_lon)
     source_coord = Location.createFrom(self.source_city, self.source_lat,
                                        self.source_lon)
     distance = origin_coord.distance_from(source_coord)
     self.assertEqual(distance, self.distance)
Example #4
0
def main(radius, origin_lat, origin_lon, customer_file):
    # create location object of origin to compare distance with other location
    origin = Location('dublin', origin_lat, origin_lon)
    customers = get_customers(customer_file)
    filter_criteria = FilterCriteria.get_filter(0, radius)
    invited_customers = get_customer_within_radius(customers, origin, filter_criteria)
    fields = ['user_id', 'name']  # fields that need to be printed of customers
    report(invited_customers, fields)
Example #5
0
    def process_user_setting(self):
        print("in process_user_setting: start loc is " +
              str(self.start_loc[0]) + str(self.start_loc[1]))
        location = Location(self.start_loc[0], self.start_loc[1])
        ax = host_subplot(111, axes_class=Axes)

        ax.set_autoscale_on(True)

        latitude1, longitude1 = location.x0, location.y0  # type: (float, float)
        ax.plot(latitude1, longitude1, 'ro')

        location = Location(latitude1, longitude1)

        x, y = location.find_hottest_route()
        print("after find_hottest_route= " + str(x), str(y))
        ax.plot(x, y, 'bo')
        plt.show()
        return x, y
    def make_booking(self, customer, car, date1, date2, location1, location2):
        self.add_customer(customer)

        period = (date2 - date1).days + 1
        location = Location(location1, location2)

        booking = Booking(customer, period, car, location)
        self._bookings.append(booking)
        return booking
 def test_create_location_with_string(self):
     """
     coordinate should be typecast to float if they are passed in string type
     """
     str_lat = str(self.origin_lat)
     str_lon = str(self.origin_lon)
     location = Location.createFrom(self.city, str_lat, str_lon)
     self.assertEqual(type(location), Location)
     self.assertEqual(location.latitude, self.origin_lat)
     self.assertEqual(location.longitude, self.origin_lon)
 def test_create_location(self):
     """
     Test for location object creation flow
     :return:
     """
     location = Location.createFrom(self.city, self.origin_lat,
                                    self.origin_lon)
     self.assertEqual(type(location), Location)
     self.assertEqual(location.latitude, self.origin_lat)
     self.assertEqual(location.longitude, self.origin_lon)
     self.assertEqual(location.city, self.city)
 def test_same_location_distance_zero(self):
     """
     this tests the functionality of distance calculation between two
     coordinates.
     distance between two coordinates should always be zero
     """
     coordinate = Location.createFrom(self.origin_city, self.origin_lat,
                                      self.origin_lon)
     duplicate_coordinate = coordinate
     distance = coordinate.distance_from(duplicate_coordinate)
     self.assertEqual(distance, 0.0)
Example #10
0
def add_downtown_to_all():
    listings = redis.keys('house-search:listings/*')
    logging.info("Checking downtown data for " + str(len(listings)) +
                 " potential listings")
    for i in listings:
        k = i.decode()
        if "latitude" in k or "longitude" in k or "/downtown" in k or "/poi/" in k or "score" in k:
            pass
            # these keys do not represent a listing
        else:
            try:
                if redis.get(k + "/downtown") is None:
                    lat = redis.get(k + "latitude")
                    if lat is None:
                        l = location_from_listing(k, redis)
                    else:
                        l = Location(latitude=lat,
                                     longitude=redis.get(k + "longitude"))
                    data = l.get_point_of_interest_data(dt_loc)
                    redis.set(k + "/downtown", str(data['commute']))
            except Exception as e:
                log.exception(traceback.format_exc())
Example #11
0
 def get_nearest_station_from_waypoints(self):
     """
     For each waypoints, retrieve the id of the nearest charging station. And store it into
     'self.stations' array.
     """
     if self.waypoints is not None:
         for location in self.waypoints:
             station = Location(lat=location['lat'],
                                lng=location['lng']).get_nearest_station(self.stations_list,
                                                                         self.station_max_distance)
             if station:
                 self.stations.append(station[0])
             else:
                 raise NoStationInArea("There's no charging station in the area of this location",
                                       location['lat'], location['lng'])
Example #12
0
def run_simulation(n_steps, n_clusters=5):
    components = [Population(), Location(), FlockKMeans(), Infection()]
    sim = setup_simulation(components)

    # Set parameters
    sim.configuration.flock.n_clusters = n_clusters

    # pop = sim.get_population()
    # pop['color'] = pop.infected.map({0: 'black', 1: 'red'})
    # pops = [sim.get_population()]
    # for i in range(0, n_steps):
    #     sim.step()
    # pop = sim.get_population()
    # pop['color'] = pop.infected.map({0: 'black', 1: 'red'})
    # pops.append(pop)

    sim.take_steps(n_steps)
    pop = sim.get_population()
    pop['color'] = pop.infected.map({0: 'black', 1: 'red'})

    return pop
Example #13
0
import os
import discord
from dotenv import load_dotenv
from src.location import Location

load_dotenv()
client = discord.Client()

try:
    l = Location()
except Exception:
    print("Invalid 42 API Key.")


async def get_location(message, username):
    await message.channel.send("Finding {}!".format(username))
    l.refresh_locations()

    try:
        location = l.search(username)
    except Exception:
        await message.channel.send("42 API Key expired!")
        return
    if not location:
        await message.channel.send(
            "{} is not in the building!\nPlease check if you entered the correct username!"
            .format(username))
        return
    await message.channel.send(location)

Example #14
0
 def test_location_create_ok(self):
     l = Location("90", "180")
     self.assertEqual(90.0, l.lat)
     self.assertEqual(180.0, l.long)
     self.assertEqual(pi/2, l.lat_rad)
     self.assertEqual(pi, l.long_rad)
Example #15
0
                        waypoints_amount += 1
                        distance = 0
                else:
                    distance += step['distance']
            print self.waypoints

    # TODO: Fonction non verifiee. Fonctionne en theorie.
    # TODO: Cette fonction utilise stations_list. Trouver structure de donnee pour station_list.
    def get_nearest_station_from_waypoints(self):
        """
        For each waypoints, retrieve the id of the nearest charging station. And store it into
        'self.stations' array.
        """
        if self.waypoints is not None:
            for location in self.waypoints:
                station = Location(lat=location['lat'],
                                   lng=location['lng']).get_nearest_station(self.stations_list,
                                                                            self.station_max_distance)
                if station:
                    self.stations.append(station[0])
                else:
                    raise NoStationInArea("There's no charging station in the area of this location",
                                          location['lat'], location['lng'])


# car = Car('bmw', 100, 25)
station_list = None
way = Travel(Location(address="SNCB Mons Station"), Location(lat=51.2142821, lng=2.9207283), station_list)
print way.destination.address
# print way.steps
Example #16
0
from redis import Redis

from src.location import geocode_destination_here, Location
from src.redis_locations import location_from_listing, set_latitude_longitude_listing

log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)

REDIS_CONN_COUNT = 100

lat = 51.04782078532812
long = 114.05920283654567
key = 'house-search:listings/*'

dt = geocode_destination_here("Downtown, Calgary, AB")
dt_loc = Location(dt)
redis = Redis(host=os.getenv("REDIS_HOST", "10.20.40.57"))


def add_downtown_to_all():
    listings = redis.keys('house-search:listings/*')
    logging.info("Checking downtown data for " + str(len(listings)) +
                 " potential listings")
    for i in listings:
        k = i.decode()
        if "latitude" in k or "longitude" in k or "/downtown" in k or "/poi/" in k or "score" in k:
            pass
            # these keys do not represent a listing
        else:
            try:
                if redis.get(k + "/downtown") is None:
 def add_location(self, location_name):
     loc = Location(location_name)
     self.database._add_location(loc)