Beispiel #1
0
def make_cylinder_KML(request):
    if request.method == 'POST':
        kml_name = request.POST.get('kml_name')
        color = request.POST.get('color')
        altitude = int(request.POST.get('altitude'))
        multiplier = float(request.POST.get('multiplier'))
        radius = int(request.POST.get('radius'))
        parseManager = ParseManager.getParseManager("")

        print parseManager.data
        print " "
        print " "

        print kml_name
        print color
        print altitude
        print multiplier

        dome_Generator = CylinderGenerator(parseManager.data[0], kml_name, color, altitude, multiplier, radius)
        dome_Generator.generate()
        kml_file = Kml(visibility=False)
        kml_file.file.name = 'kmls_management/static/' + kml_name
        kml_file.save()

        request.session.clear()

        return HttpResponseRedirect('/VYD/KmlManager/kmls')

    return render(request, 'presentation/presentation_form_cylinder.html')
Beispiel #2
0
def make_cylinder_KML(request):
    if request.method == 'POST':
        kml_name = request.POST.get('kml_name')
        color = request.POST.get('color')
        altitude = int(request.POST.get('altitude'))
        multiplier = float(request.POST.get('multiplier'))
        radius = int(request.POST.get('radius'))
        parseManager = ParseManager.getParseManager("")

        print parseManager.data
        print " "
        print " "

        print kml_name
        print color
        print altitude
        print multiplier

        dome_Generator = CylinderGenerator(parseManager.data[0], kml_name,
                                           color, altitude, multiplier, radius)
        dome_Generator.generate()
        kml_file = Kml(visibility=False)
        kml_file.file.name = 'kmls_management/static/' + kml_name
        kml_file.save()

        request.session.clear()

        return HttpResponseRedirect('/VYD/KmlManager/kmls')

    return render(request, 'presentation/presentation_form_cylinder.html')
Beispiel #3
0
def create_kml(item, type, action):
    name = type + "_" + str(item.id) + ".kml"
    path = os.path.dirname(__file__) + "/static/kml/" + name

    if type == 'hangar':
        kml_generator.create_hangar_polygon(item, path)
    else:
        kml_generator.create_droppoint_marker(item, path)

    if action == 'create':
        Kml(name=name, url="static/kml/" + name).save()
    else:
        kml_vis = Kml.objects.get(name=name)
        kml_vis.visibility = item.is_available
        kml_vis.save()

    if type == 'hangar':
        name_influence = kml_generator.hangar_influence(
            item,
            os.path.dirname(__file__) + "/static/kml/" + type + "_" +
            str(item.id) + "_inf.kml")
        if action == 'create':
            Kml(name=name_influence,
                url="static/kml/" + name_influence,
                visibility=item.is_available).save()
        else:
            kml_vis = Kml.objects.get(name=name_influence)
            kml_vis.visibility = item.is_available
            kml_vis.save()
Beispiel #4
0
def find_drone_path(origin, destiny, path_name, incidence, is_returning=False):
    geo_point_origin = (origin.latitude, origin.longitude)
    geo_point_destiny = (destiny.latitude, destiny.longitude)
    file_path = path_name + "in" + str(incidence.id) + "drone.kml"
    dist = geopy.distance.distance(geo_point_origin, geo_point_destiny) \
        .kilometers
    bearing = \
        calculate_initial_compass_bearing(geo_point_origin, geo_point_destiny)
    take_off_steps = 8
    altitude = origin.altitude
    Kml(name="incidence" + str(incidence.id) + ".kml",
        url=path_name + "incidence" + str(incidence.id) + ".kml",
        visibility=True).save()
    create_emergency_marker(
        incidence, path_name + "incidence" + str(incidence.id) + ".kml")
    placemark_kml(incidence.drone,
                  (geo_point_origin[0], geo_point_origin[1], altitude),
                  file_path)
    take_off_steps -= 1
    altitude += 25
    sync_kml_galaxy()
    create_drone_manage_route(path_name, incidence.id)
    steps = 20
    lat = geo_point_origin[0]
    lon = geo_point_origin[1]

    for i in range(take_off_steps):
        placemark_kml(incidence.drone,
                      (geo_point_origin[0], geo_point_origin[1], altitude),
                      file_path)
        altitude += 25
        time.sleep(2)

    for i in range(steps):
        destination = VincentyDistance(kilometers=dist / steps) \
            .destination(geopy.Point(lat, lon), bearing)
        lat, lon = destination.latitude, destination.longitude
        placemark_kml(incidence.drone, (lat, lon, altitude), file_path)
        time.sleep(2)

    for i in range(8):
        placemark_kml(incidence.drone, (lat, lon, altitude), file_path)
        altitude -= 25
        time.sleep(2)

    time.sleep(5)
    os.remove(path_name + "incidence" + str(incidence.id) + ".kml")
    Kml.objects.filter(name="incidence" + str(incidence.id) + ".kml"). \
        delete()
    Kml(name="finishedincidence" + str(incidence.id) + ".kml",
        url=path_name + "finishedincidence" + str(incidence.id) +
        ".kml").save()
    create_emergency_marker(
        incidence,
        path_name + "finishedincidence" + str(incidence.id) + ".kml", True)
    sync_kml_galaxy()
    time.sleep(10)
    delete_incidence(incidence, path_name)
    time.sleep(30)
    delete_finished_incidence_marker(incidence, path_name)
Beispiel #5
0
 def create_hangars(self, path):
     self.stdout.write("Creating Hangars Kml...")
     for item in Hangar.objects.all():
         name = "hangar_" + str(item.id) + ".kml"
         create_hangar_polygon(item, path + name)
         name_inf = hangar_influence(
             item, path + "hangar_" + str(item.id) + "_inf.kml")
         Kml(name=name, url=path + name).save()
         Kml(name=name_inf, url=path + name_inf).save()
Beispiel #6
0
 def create_logo(self, path, app_ip):
     self.stdout.write("Creating Logo Kml...")
     name = "faed_logo"
     faed_logo_kml(path + name,
                   "http://" + app_ip + "/static/img/static_icon.png", 1, 1,
                   0.2, 0.15)
     Kml(name=name + ".kml", url=path + name + ".kml", visibility=0).save()
     faed_logo_kml(path + "logos",
                   "http://" + app_ip + "/static/img/logos.png", 0, 0, 0.2,
                   0.3)
     Kml(name="logos.kml", url=path + "logos.kml", visibility=0).save()
Beispiel #7
0
 def create_droppoints(self, path):
     self.stdout.write("Creating Droppoints Kml...")
     dp = []
     for item in DropPoint.objects.all():
         name = "droppoint_" + str(item.id) + ".kml"
         create_droppoint_marker(item, path + name)
         dp.append(name)
     name_general = "general_dp.kml"
     create_general(path + name_general, dp)
     Kml(name=name_general, url=path + name_general).save()
Beispiel #8
0
def create_drone_manage_route(path_name, id_incidence):
    ip_server = get_server_ip()
    url_file = "http://" + str(ip_server)[0:(len(ip_server) - 1)] + \
               ":8000/static/kml/" + "in" + str(id_incidence) + \
               "drone.kml" + "\n"
    manage_kml(path_name + "manage" + str(id_incidence), url_file, 0.5)
    Kml(name="manage" + str(id_incidence) + ".kml",
        url="static/kml/manage" + str(id_incidence) + ".kml").save()
    sync_kml_galaxy()
    time.sleep(2)
Beispiel #9
0
def generate_weather(path):
    json_data = get_weather(lleida, "metric")
    data = json_loads_byteified(json_data)
    weather_info(path + "meteo_info.kml", data['main']['temp'],
                 data['main']['temp_max'], data['main']['temp_min'],
                 data['wind']['speed'], data['clouds']['all'],
                 data['main']['pressure'], data['main']['humidity'],
                 data['weather'][0]['description'])
    if not Kml.objects.filter(name="meteo_info.kml"):
        Kml(name="meteo_info.kml", url=path + "meteo_info.kml",
            visibility=0).save()
Beispiel #10
0
def make_marker_KML(request):
    if request.method == 'POST':
        kml_name = request.POST.get('kml_name')
        icon_marker = request.POST.get('icon_marker')
        print " "
        print " "
        print kml_name
        print icon_marker

        parseManager = ParseManager.getParseManager("")

        print parseManager.data

        markerTours = MarkersTour(parseManager.data[0], kml_name, icon_marker)

        markerTours.makeFile()

        kml_file = Kml(visibility=False)
        kml_file.file.name = 'kmls_management/static/' + kml_name
        kml_file.save()
        request.session.clear()
        return HttpResponseRedirect('/VYD/KmlManager/kmls')

    return render(request, 'presentation/presentation_form_markers.html')
Beispiel #11
0
def make_marker_KML(request):
    if request.method == 'POST':
        kml_name = request.POST.get('kml_name')
        icon_marker = request.POST.get('icon_marker')
        print " "
        print " "
        print kml_name
        print icon_marker

        parseManager = ParseManager.getParseManager("")

        print parseManager.data

        markerTours = MarkersTour(parseManager.data[0], kml_name, icon_marker)

        markerTours.makeFile()

        kml_file = Kml(visibility=False)
        kml_file.file.name = 'kmls_management/static/' + kml_name
        kml_file.save()
        request.session.clear()
        return HttpResponseRedirect('/VYD/KmlManager/kmls')

    return render(request, 'presentation/presentation_form_markers.html')
Beispiel #12
0
def find_emergency_path(request):

    MAX_WIND_SPEED = 20.0

    url = 'http://api.openweathermap.org/data/2.5/weather?q=Lleida&units=metric'
    response = requests.get(url=url)
    data = json.loads(response.text)

    #try:
    #    if data['wind']['speed'] >= MAX_WIND_SPEED or bool(data['rain']):
    #        print data['rain']
    #        print data['wind']['speed']
    #        return HttpResponse(status=503)
    #except KeyError:
    #    pass

    lat = request.GET.get('lat', '')
    lon = request.GET.get('lng', '')
    path = os.path.dirname(__file__) + "/static/kml/"

    last_distance = sys.maxint
    all_hangars = models.Hangar.objects.all()
    selected_hangar = None
    all_droppoints = models.DropPoint.objects.all()
    selected_droppoint = None
    point_location = Point(float(lon), float(lat))

    for droppoint in all_droppoints:
        distance = D(m=point_location.distance(
            Point(droppoint.longitude, droppoint.latitude)))
        if distance.m < last_distance:
            last_distance = distance.m
            selected_droppoint = droppoint

    last_distance = sys.maxint
    point_location = Point(selected_droppoint.longitude,
                           selected_droppoint.latitude)
    for hangar in all_hangars:
        distance = D(m=point_location.distance(
            Point(hangar.longitude, hangar.latitude)))
        if distance.m < last_distance:
            last_distance = distance.m
            selected_hangar = hangar

    # print selected_hangar.name, selected_hangar.drone.name, selected_droppoint.name

    selected_hangar.drone.destination_lat = selected_droppoint.latitude
    selected_hangar.drone.destination_lon = selected_droppoint.longitude

    if not selected_hangar.is_available:
        return HttpResponse(status=503)

    kml_generator.weather_info(
        os.path.dirname(__file__) + "/static/kml/meteo_info.kml",
        data['main']['temp'], data['main']['temp_max'],
        data['main']['temp_min'], data['wind']['speed'], data['clouds']['all'],
        data['main']['pressure'], data['main']['humidity'],
        data['weather'][0]['description'])

    generate_mission_file(selected_hangar)
    kml_generator.create_emergency_marker(lat, lon, path + "incidence.kml")
    Kml(name="incidence.kml", url="static/kml/incidence.kml",
        visibility=True).save()
    sync_kmls_file()
    sync_kmls_to_galaxy(emergency=True)
    kml_generator.find_drone_path(selected_hangar, selected_droppoint, path)

    Kml.objects.get(name="incidence.kml").delete()
    os.remove(path + "incidence.kml")

    for step in range(0, 34, 1):
        Kml.objects.get(name="drone_" + str(step) + ".kml").delete()
        os.remove(path + "drone_" + str(step) + ".kml")

    sync_kmls_file()
    sync_kmls_to_galaxy(emergency=True)

    return HttpResponse(status=201)
Beispiel #13
0
def find_drone_path(hangar, droppoint, filename):
    geo_point_origin = (hangar.latitude, hangar.longitude)
    geo_point_destiny = (droppoint.latitude, droppoint.longitude)

    dist = geopy.distance.distance(geo_point_origin,
                                   geo_point_destiny).kilometers
    bearing = calculate_initial_compass_bearing(geo_point_origin,
                                                geo_point_destiny)

    steps = 20
    num_steps = steps
    step = 0
    altitude = hangar.altitude

    # Drone taking off
    while step <= 6:
        placemark_kml(hangar.drone,
                      (geo_point_origin[0], geo_point_origin[1], altitude),
                      filename + "drone_" + str(step) + ".kml")
        Kml(name="drone_" + str(step) + ".kml",
            url="static/kml/drone_" + str(step) + ".kml",
            visibility=True).save()
        altitude += 25
        step += 1
        drone_to_galaxy()

    lat = geo_point_origin[0]
    lon = geo_point_origin[1]
    placemark_kml(hangar.drone,
                  (geo_point_origin[0], geo_point_origin[1], altitude),
                  filename + "drone_" + str(step) + ".kml")
    Kml(name="drone_" + str(step) + ".kml",
        url="static/kml/drone_" + str(step) + ".kml",
        visibility=True).save()
    step += 1
    drone_to_galaxy()

    # Drone route
    while num_steps > 0:
        destination = VincentyDistance(kilometers=dist / steps).destination(
            geopy.Point(lat, lon), bearing)
        lat, lon = destination.latitude, destination.longitude
        placemark_kml(hangar.drone, (lat, lon, altitude),
                      filename + "drone_" + str(step) + ".kml")
        Kml(name="drone_" + str(step) + ".kml",
            url="static/kml/drone_" + str(step) + ".kml",
            visibility=True).save()
        num_steps -= 1
        step += 1
        drone_to_galaxy()

    # Drone landing
    while step <= 33:
        placemark_kml(hangar.drone, (lat, lon, altitude),
                      filename + "drone_" + str(step) + ".kml")
        Kml(name="drone_" + str(step) + ".kml",
            url="static/kml/drone_" + str(step) + ".kml",
            visibility=True).save()
        altitude -= 25
        step += 1
        drone_to_galaxy()

    time.sleep(5)