Пример #1
0
def callPextantAjax(request, planId, clear=0):
    """ Call Pextant over Ajax and either return the modified plan with success message,
    or return error message.
    """
    PLAN_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_PLAN_MODEL)
    response = {}
    try:
        plan = PLAN_MODEL.get().objects.get(pk=planId)
        plan = pextantHarness.clearSegmentGeometry(plan)
        response["plan"] = plan.jsonPlan
        if clear:
            response["msg"] = "Sextant route cleared."
            response["status"] = True
            status = 200
        else:
            optimize = str(request.POST['optimize'])

            maxSlope = float(request.POST['slope'])
            post_extent = request.POST['extent']
            if post_extent:
                extent = [float(val) for val in (str(post_extent).split(','))]
            plan = pextantHarness.callPextant(request, plan, optimize,
                                              maxSlope, extent)
            response["plan"] = plan.jsonPlan
            response["msg"] = "Sextant has calculated a new route."
            response["status"] = True
            status = 200
    except Exception, e:
        traceback.print_exc()
        response["msg"] = str(e)
        response["status"] = False
        status = 406
Пример #2
0
 def initializeLetter(self, dateprefix):
     GROUP_FLIGHT_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_GROUP_FLIGHT_MODEL)
     try:
         last = GROUP_FLIGHT_MODEL.get().objects.filter(name__startswith=dateprefix).order_by('name').last()
         self.fields['prefix'].initial = chr(ord(last.name[-1]) + 1)
     except:
         self.fields['prefix'].initial = 'A'
Пример #3
0
def planImportXPJson(request):
    PLAN_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_PLAN_MODEL)
    try:
        form = UploadXPJsonForm(request.POST, request.FILES)
        if form.is_valid():
            planUuid = form.cleaned_data['planUuid']
            try:
                plan = PLAN_MODEL.get().objects.get(uuid=planUuid)
            except:
                return HttpResponse(json.dumps({'Success':"False", 'responseText': 'Wrong UUID, plan not found'}), content_type='application/json', status=406)
            incoming = request.FILES['file']
            newJson = handle_uploading_xpjson(incoming)
            if (len(newJson) > 0):
                newJsonObj = json.loads(newJson, 'UTF-8')
                foundUuid = newJsonObj['uuid']
                if (foundUuid != planUuid):
                    return HttpResponse(json.dumps({'Success':"False", 'responseText': 'Loaded JSON is for a different plan; UUID of plans do not match.'}), content_type='application/json', status=406)
                isValid = validateJson(newJsonObj)
                if isValid == True:
                    updateJson(plan, newJsonObj)
                    return HttpResponse(json.dumps({'Success':"True"}))
                else:
                    return HttpResponse(json.dumps({'Success':"False", 'responseText': isValid}), content_type='application/json', status=406)
            else:
                return HttpResponse(json.dumps({'Success':"False", 'responseText': 'JSON Empty'}), content_type='application/json', status=406)
    except Exception:
        traceback.print_exc()
        exc_type, exc_value, exc_traceback = sys.exc_info()
        return HttpResponse(json.dumps({'Success':"False", 'responseText': exc_value['message']}), content_type='application/json', status=406)
Пример #4
0
 def get_tree_json(cls, parent_class, parent_pk):
     try:
         found = LazyGetModelByName(
             settings.XGDS_IMAGE_IMAGE_SET_MODEL).get().objects.filter(
                 flight__id=parent_pk)
         result = None
         if found.exists():
             moniker = settings.XGDS_IMAGE_IMAGE_SET_MONIKER + 's'
             flight = found[0].flight
             result = [{
                 "title": moniker,
                 "selected": False,
                 "tooltip": "%s for %s " % (moniker, flight.name),
                 "key": "%s_%s" % (flight.uuid, moniker),
                 "data": {
                     "json":
                     reverse('xgds_map_server_objectsJson',
                             kwargs={
                                 'object_name':
                                 'XGDS_IMAGE_IMAGE_SET_MODEL',
                                 'filter': 'flight__pk:' + str(flight.pk)
                             }),
                     "sseUrl":
                     "",
                     "type":
                     'MapLink',
                 }
             }]
         return result
     except ObjectDoesNotExist:
         return None
Пример #5
0
    def buildTextAnnotationQuery(cls, search_keywords):
        """
        Build a query that will search for an image set that is pointed to by a text annotation containing keyword
        :param search_keywords: keywords to search for in the format keyword and keyword or keyword etc
        :return: the found list of pks
        """

        master_query = LazyGetModelByName(
            settings.XGDS_IMAGE_TEXT_ANNOTATION_MODEL).get().objects.all()

        counter = 0
        last_query = None
        keyword_query = None
        while counter < len(search_keywords):
            if counter % 2 == 0:
                last_query = Q(
                    **{'content__icontains': search_keywords[counter]})
            else:
                if not keyword_query:
                    keyword_query = last_query
                else:
                    join_type = search_keywords[counter]
                    if join_type == 'and':
                        keyword_query &= last_query
                    else:
                        keyword_query |= last_query
            counter += 1
        if not keyword_query:
            keyword_query = last_query

        result = master_query.filter(keyword_query)
        image_ids = result.values_list('image_id', flat=True)

        return list(image_ids)
Пример #6
0
 def get_info_json(cls, flight_pk):
     found = LazyGetModelByName(
         settings.XGDS_IMAGE_IMAGE_SET_MODEL).get().objects.filter(
             flight__id=flight_pk)
     result = None
     if found.exists():
         flight = LazyGetModelByName(
             settings.XGDS_CORE_FLIGHT_MODEL).get().objects.get(
                 id=flight_pk)
         result = {
             'name':
             settings.XGDS_IMAGE_IMAGE_SET_MONIKER + 's',
             'count':
             found.count(),
             'url':
             reverse('search_map_object_filter',
                     kwargs={
                         'modelName':
                         settings.XGDS_IMAGE_IMAGE_SET_MONIKER,
                         'filter':
                         'flight__group:%d,flight__vehicle:%d' %
                         (flight.group.pk, flight.vehicle.pk)
                     })
         }
     return result
Пример #7
0
def planImportXPJson(request):
    PLAN_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_PLAN_MODEL)
    try:
        form = UploadXPJsonForm(request.POST, request.FILES)
        if form.is_valid():
            planUuid = form.cleaned_data['planUuid']
            try:
                plan = PLAN_MODEL.get().objects.get(uuid=planUuid)
            except:
                return HttpResponse(json.dumps({'Success':"False", 'responseText': 'Wrong UUID, plan not found'}), content_type='application/json', status=406)
            incoming = request.FILES['file']
            newJson = handle_uploading_xpjson(incoming)
            if (len(newJson) > 0):
                newJsonObj = json.loads(newJson, 'UTF-8')
                foundUuid = newJsonObj['uuid']
                if (foundUuid != planUuid):
                    return HttpResponse(json.dumps({'Success':"False", 'responseText': 'Loaded JSON is for a different plan; UUID of plans do not match.'}), content_type='application/json', status=406)
                isValid = validateJson(newJsonObj)
                if isValid == True:
                    updateJson(plan, newJsonObj)
                    return HttpResponse(json.dumps({'Success':"True"}))
                else:
                    return HttpResponse(json.dumps({'Success':"False", 'responseText': isValid}), content_type='application/json', status=406)
            else:
                return HttpResponse(json.dumps({'Success':"False", 'responseText': 'JSON Empty'}), content_type='application/json', status=406)
    except Exception:
        traceback.print_exc()
        exc_type, exc_value, exc_traceback = sys.exc_info()
        return HttpResponse(json.dumps({'Success':"False", 'responseText': exc_value['message']}), content_type='application/json', status=406)
Пример #8
0
def getInstrumentDataCsvResponse(request, productModel, productPk):
    INSTRUMENT_DATA_PRODUCT_MODEL = LazyGetModelByName(productModel)
    dataProduct = get_object_or_404(INSTRUMENT_DATA_PRODUCT_MODEL.get(), pk=productPk)
    filename, dataframe = dataProduct.getInstrumentDataCsv()
    response = HttpResponse(content_type='text/csv')
    response['Content-Disposition'] = 'attachment; filename=' + filename
    dataframe.to_csv(response, index=False)
    return response
Пример #9
0
def getActiveFlights(vehicle=None):
    ACTIVE_FLIGHTS_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_ACTIVE_FLIGHT_MODEL)

    if not vehicle:
        return ACTIVE_FLIGHTS_MODEL.get().objects.all()
    else:
        # filter by vehicle
        return ACTIVE_FLIGHTS_MODEL.get().objects.filter(flight__vehicle=vehicle)
Пример #10
0
def saveUpdatedInstrumentData(request, instrument_name, pk):
    """
    Updates instrument data on save.
    """

    if request.method == 'POST':
        mapDict = settings.XGDS_MAP_SERVER_JS_MAP[instrument_name]
        INSTRUMENT_MODEL = LazyGetModelByName(mapDict['model'])
        dataProduct = INSTRUMENT_MODEL.get().objects.get(pk=pk)

        # get existing data.
        if 'edit_form_class' in mapDict:
            form = getFormByName(mapDict['edit_form_class'])(request.POST,
                                                             request.FILES)
        else:
            form = BasaltInstrumentDataForm(request.POST, request.FILES)

        try:
            form.is_valid()
        except:
            pass

        for key in form.changed_data:
            value = form.cleaned_data[key]
            if not hasattr(value, 'read'):
                if not isinstance(value, datetime.datetime):
                    setattr(dataProduct, key, value)
            else:
                form.handleFileUpdate(dataProduct, key)
        # save the update info into the model.


#         postDict = request.POST.dict()
#         dataProduct.name = postDict['name']
#         dataProduct.description = postDict['description']
#         dataProduct.minerals = postDict['minerals']
#         resourceId = postDict['resource']
#         if resourceId:
#             resource = BasaltResource.objects.get(id=resourceId)
#             dataProduct.resource = resource

        dataProduct.acquisition_time = form.cleaned_data['dataCollectionTime']

        if (('lat' in form.cleaned_data) and
            ('lon' in form.cleaned_data)) or ('alt' in form.cleaned_data):
            editInstrumentDataPosition(dataProduct, form.cleaned_data['lat'],
                                       form.cleaned_data['lon'],
                                       form.cleaned_data['alt'])
        dataProduct.save()

        messages.success(request, 'Instrument data successfully saved!')

        return HttpResponseRedirect(
            reverse('search_map_single_object',
                    kwargs={
                        'modelPK': pk,
                        'modelName': instrument_name
                    }))
Пример #11
0
 def initializeLetter(self, dateprefix):
     GROUP_FLIGHT_MODEL = LazyGetModelByName(
         settings.XGDS_PLANNER2_GROUP_FLIGHT_MODEL)
     try:
         last = GROUP_FLIGHT_MODEL.get().objects.filter(
             name__startswith=dateprefix).order_by('name').last()
         self.fields['prefix'].initial = chr(ord(last.name[-1]) + 1)
     except:
         self.fields['prefix'].initial = 'A'
Пример #12
0
def mapJsonPlan(request, uuid):
    PLAN_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_PLAN_MODEL)
    try:
        plan = PLAN_MODEL.get().objects.get(uuid=uuid)
        json_data = json.dumps([plan.toMapDict()], indent=4)
        return HttpResponse(content=json_data,
                            content_type="application/json")
    except:
        return HttpResponse(content={},
                            content_type="application/json")
Пример #13
0
def mapJsonPlan(request, uuid):
    PLAN_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_PLAN_MODEL)
    try:
        plan = PLAN_MODEL.get().objects.get(uuid=uuid)
        json_data = json.dumps([plan.toMapDict()], indent=4)
        return HttpResponse(content=json_data,
                            content_type="application/json")
    except:
        return HttpResponse(content={},
                            content_type="application/json")
Пример #14
0
def mapJsonPosition(request, id):
    POSITION_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_POSITION_MODEL)
    try:
        position = POSITION_MODEL.get().objects.get(pk=id)
        json_data = json.dumps([position.toMapDict()], cls=DatetimeJsonEncoder)
        return HttpResponse(content=json_data,
                            content_type="application/json")
    except:
        return HttpResponse(content={},
                            content_type="application/json")
Пример #15
0
def mapJsonTrack(request, uuid, downsample=False):
    TRACK_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_TRACK_MODEL)
    try:
        track = TRACK_MODEL.get().objects.get(uuid=uuid)
        json_data = json.dumps([track.toMapDict(downsample)], cls=DatetimeJsonEncoder)
        return HttpResponse(content=json_data,
                            content_type="application/json")
    except:
        traceback.print_exc()
        return HttpResponse(content={},
                            content_type="application/json")
Пример #16
0
 def initializeVehicleChoices(self):
     CHOICES = []
     VEHICLE_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_VEHICLE_MODEL)
     if (VEHICLE_MODEL.get().objects.count() > 0):
         for vehicle in VEHICLE_MODEL.get().objects.all().order_by('name'):
             CHOICES.append((vehicle.name, vehicle.name))
 
     if len(CHOICES) == 1:
         initial = [c[0] for c in CHOICES]
     else:
         initial = None
     result = forms.MultipleChoiceField(choices=CHOICES, widget=forms.CheckboxSelectMultiple(attrs={"checked":""}), required=False, initial=initial)
     return result
Пример #17
0
 def get_info_json(cls, flight_pk):
     found = LazyGetModelByName(cls.get_qualified_model_name()).get().objects.filter(flight__id=flight_pk)
     result = None
     if found.exists():
         flight = LazyGetModelByName(settings.XGDS_CORE_FLIGHT_MODEL).get().objects.get(id=flight_pk)
         result = {'name': cls.get_plural_moniker(),
                   'count': found.count(),
                   'url': reverse('search_map_object_filter',
                                  kwargs={'modelName': cls.get_jsmap_key(),
                                          'filter': 'flight__group:%d,flight__vehicle:%d' % (
                                          flight.group.pk, flight.vehicle.pk)})
                   }
     return result
Пример #18
0
 def get_info_json(cls, flight_pk):
     """ For some reason because of the way this method is used with reflection we have to redefine it."""
     found = LazyGetModelByName(cls.get_qualified_model_name()).get().objects.filter(flight__id=flight_pk)
     result = None
     if found.exists():
         flight = LazyGetModelByName(settings.XGDS_CORE_FLIGHT_MODEL).get().objects.get(id=flight_pk)
         result = {'name': cls.get_plural_moniker(),
                   'count': found.count(),
                   'url': reverse('search_map_object_filter',
                                  kwargs={'modelName': cls.get_jsmap_key(),
                                          'filter': 'flight__group:%d,flight__vehicle:%d' % (
                                              flight.group.pk, flight.vehicle.pk)})
                   }
     return result
Пример #19
0
def editInstrumentData(request, instrument_name, pk):
    """
    Renders instrument data edit page -- if data exists, displays the existing data.
    """
    mapDict = settings.XGDS_MAP_SERVER_JS_MAP[instrument_name]
    INSTRUMENT_MODEL = LazyGetModelByName(mapDict['model'])
    dataProduct = INSTRUMENT_MODEL.get().objects.get(pk=pk)
    jsonDict = dataProduct.toMapDict()

    # get existing data.
    if 'edit_form_class' in mapDict:
        form = getFormByName(mapDict['edit_form_class'])(initial=jsonDict)
    else:
        form = BasaltInstrumentDataForm(initial=jsonDict)

    form.editingSetup(dataProduct)

    # convert to local time.
    utcTime = dataProduct.acquisition_time
    timezone = dataProduct.acquisition_timezone
    acquisitionTime = utcToTimeZone(utcTime, timezone)
    acquisitionTime = acquisitionTime.strftime('%m/%d/%Y %H:%M')

    form.fields['dataCollectionTime'].initial = acquisitionTime
    form.fields['timezone'].initial = timezone

    # hide the two file fields
    #     form.fields['portableDataFile'].widget = forms.HiddenInput()
    #     form.fields['manufacturerDataFile'].widget = forms.HiddenInput()
    #
    updateInstrumentDataUrl = reverse('instrument_data_update',
                                      kwargs={
                                          'instrument_name': instrument_name,
                                          'pk': pk
                                      })
    return render(
        request,
        'xgds_instrument/editInstrumentData.html',
        {
            'form': form,
            'instrument_name': instrument_name,
            'dataProductJson': json.dumps(jsonDict, cls=DatetimeJsonEncoder),
            'updateInstrumentDataUrl': updateInstrumentDataUrl,
            'manufacturer_data_file_url':
            dataProduct.manufacturer_data_file_url,
            'portable_data_file_url': dataProduct.portable_data_file_url
        },
    )
Пример #20
0
    def startTracking(self):
        resource = self.getResource()

        #Create the track if it does not exist
        if not self.track:
            TRACK_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_TRACK_MODEL)
            try:
                track = TRACK_MODEL.get().objects.get(name=self.name)
            except ObjectDoesNotExist:
                timezone = settings.TIME_ZONE
                if self.plans:
                    timezone = str(self.plans[0].plan.jsonPlan.site.
                                   alternateCrs.properties.timezone)
                    self.timezone = timezone
                track = TRACK_MODEL.get()(
                    name=self.name,
                    resource=resource,
                    timezone=timezone,
                    iconStyle=geocamTrackModels.IconStyle.objects.get(
                        uuid=resource.name),
                    lineStyle=geocamTrackModels.LineStyle.objects.get(
                        uuid=resource.name),
                    dataType=DataType.objects.get(name="RawGPSLocation"))
                track.save()
                self.track = track

                # this is for archival purposes; make sure remoteDelay is set for the other server's delay.
                delayConstant = Constant.objects.get(name="remoteDelay")
                self.delaySeconds = int(delayConstant.value)
                self.save()

        if settings.PYRAPTORD_SERVICE is True:
            pyraptord = getPyraptordClient()
            serviceName = self.vehicle.name + "TrackListener"
            ipAddress = Constant.objects.get(name=resource.name +
                                             "_TRACKING_IP")
            protocol = Constant.objects.get(name=resource.name +
                                            "_TRACKING_PROTO")
            scriptPath = os.path.join(settings.PROJ_ROOT, 'apps', 'basaltApp',
                                      'scripts', 'evaTrackListener.py')
            command = "%s -o %s -p %d -n %s --proto=%s -t %s" % (
                scriptPath, ipAddress.value, resource.port,
                self.vehicle.name[-1:], protocol.value, self.name)
            stopPyraptordServiceIfRunning(pyraptord, serviceName)
            time.sleep(2)
            pyraptord.updateServiceConfig(serviceName, {'command': command})
            pyraptord.startService(serviceName)
Пример #21
0
    def initializeVehicleChoices(self):
        CHOICES = []
        VEHICLE_MODEL = LazyGetModelByName(
            settings.XGDS_PLANNER2_VEHICLE_MODEL)
        if (VEHICLE_MODEL.get().objects.count() > 0):
            for vehicle in VEHICLE_MODEL.get().objects.all().order_by('name'):
                CHOICES.append((vehicle.name, vehicle.name))

        if len(CHOICES) == 1:
            initial = [c[0] for c in CHOICES]
        else:
            initial = None
        result = forms.MultipleChoiceField(
            choices=CHOICES,
            widget=forms.CheckboxSelectMultiple(attrs={"checked": ""}),
            required=False,
            initial=initial)
        return result
Пример #22
0
    def save(self, commit=True):
        instance = super(ImportInstrumentDataForm, self).save(commit=False)
        if (('lat' in self.changed_data) and ('lon' in self.changed_data)) or ('alt' in self.changed_data):
            if instance.user_position is None:
                LOCATION_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_PAST_POSITION_MODEL)
                instance.user_position = LOCATION_MODEL.get().objects.create(serverTimestamp = datetime.datetime.now(pytz.utc),
                                                                             timestamp = instance.acquisition_time,
                                                                             latitude = self.cleaned_data['lat'],
                                                                             longitude = self.cleaned_data['lon'], 
                                                                             altitude = self.cleaned_data['alt'])
            else:
                instance.user_position.latitude = self.cleaned_data['lat']
                instance.user_position.longitude = self.cleaned_data['lon']
                instance.user_position.altitude = self.cleaned_data['alt']
                instance.user_position.save()

        if commit:
            instance.save()
        return instance
Пример #23
0
class BasaltInstrumentDataForm(ImportInstrumentDataForm):
    INSTRUMENT_MODEL = LazyGetModelByName(
        settings.XGDS_INSTRUMENT_INSTRUMENT_MODEL)
    instrument = InstrumentModelChoiceField(
        INSTRUMENT_MODEL.get().objects.all(), widget=forms.HiddenInput())
    name = forms.CharField(required=False, label="Name")
    description = forms.CharField(widget=forms.Textarea,
                                  label="Description",
                                  required=False)
    minerals = forms.CharField(widget=forms.Textarea,
                               label="Minerals",
                               required=False)
Пример #24
0
def check_data_exists(filename, timestamp, exif):
    """
    See if there is already identical data
    :return: True if it already exists, false otherwise
    """
    # get short filename
    tokens = filename.split('/')
    shortname = tokens[len(tokens) - 1]
    cameraId = getCameraByExif(exif)

    if cameraId is None:
        found = LazyGetModelByName(
            settings.XGDS_IMAGE_IMAGE_SET_MODEL).get().objects.filter(
                name=shortname, acquisition_time=timestamp)
    else:
        found = LazyGetModelByName(
            settings.XGDS_IMAGE_IMAGE_SET_MODEL).get().objects.filter(
                name=shortname, acquisition_time=timestamp, camera_id=cameraId)

    if found:
        return True
    return False
Пример #25
0
 def get_tree_json(cls, parent_class, parent_pk):
     """ For some reason because of the way this method is used with reflection we have to redefine it."""
     try:
         found = LazyGetModelByName(cls.get_qualified_model_name()).get().objects.filter(flight__id=parent_pk)
         result = None
         if found.exists():
             moniker = cls.get_plural_moniker()
             flight = found[0].flight
             result = [{"title": moniker,
                        "selected": False,
                        "tooltip": "%s for %s " % (moniker, flight.name),
                        "key": "%s_%s" % (flight.uuid, moniker),
                        "data": {"json": reverse('xgds_map_server_objectsJson',
                                                 kwargs={'object_name': cls.get_object_name(),
                                                         'filter': 'flight__pk:' + str(flight.pk)}),
                                 "sseUrl": "",
                                 "type": 'MapLink',
                                 }
                        }]
         return result
     except ObjectDoesNotExist:
         return None
Пример #26
0
def editInstrumentDataPosition(dataProduct, newLatitude, newLongitude, newAltitude):
    cleanLatitude = cleanValue(newLatitude)
    cleanLongitude = cleanValue(newLongitude)
    cleanAltitude = cleanValue(newAltitude)
    if not newLatitude or not newLongitude:
        return
    
    
    ''' create or update the user position for an instrument data reading '''
    if cleanLatitude != dataProduct.lat or cleanLongitude != dataProduct.lon or cleanAltitude != dataProduct.alt:
        if dataProduct.user_position is None:
            LOCATION_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_PAST_POSITION_MODEL)
            dataProduct.user_position = LOCATION_MODEL.get().objects.create(serverTimestamp = datetime.datetime.now(pytz.utc),
                                                                            timestamp = dataProduct.acquisition_time,
                                                                            latitude = cleanLatitude,
                                                                            longitude = cleanLongitude, 
                                                                            altitude = cleanAltitude)
        else:
            dataProduct.user_position.latitude = cleanLatitude
            dataProduct.user_position.longitude = cleanLongitude
            dataProduct.user_position.altitude = cleanAltitude
            dataProduct.user_position.save()
        dataProduct.save()
Пример #27
0
    def test_frame_grab_and_insert_database(self):
        """
        Test grabbing a video frame and inserting it into the CouchDB
        """
        grab_time_str = '20180902 22:58:52'
        start_time_str = '20180902 22:58:45'
        vehicle_name = 'Generic Vehicle'

        response = self.client.post(
            reverse('grab_frame_save_image'), {
                'path': xgds_videoTest.filepath,
                'start_time': start_time_str,
                'grab_time': grab_time_str,
                'vehicle': vehicle_name,
                'camera': 'Hercules',
                'username': '******',
                'filename_prefix': 'test_grab'
            })

        shortname = 'test_grab_20180902 22:58:52.png'
        found = LazyGetModelByName(
            settings.XGDS_IMAGE_IMAGE_SET_MODEL).get().objects.get(
                name=shortname)

        with open(xgds_videoTest.ref_2, 'rb') as f:
            reference_bytes_2 = f.read()
            f.close()

        # found is an ImageSet, get its raw image bytes
        raw_image = found.getRawImage()
        raw_image_file = raw_image.file
        found_bytes = raw_image_file.read()
        raw_image_file.close()

        equals_reference = (found_bytes == reference_bytes_2)
        self.assertTrue(equals_reference)
Пример #28
0
 def get_info_json(cls, flight_pk):
     found = NirvssSpectrometerDataProduct.objects.filter(
         flight__id=flight_pk)
     result = None
     if found.exists():
         flight = LazyGetModelByName(
             settings.XGDS_CORE_FLIGHT_MODEL).get().objects.get(
                 id=flight_pk)
         result = {
             'name':
             'NIRVSS Spectra',
             'count':
             found.count(),
             'url':
             reverse('search_map_object_filter',
                     kwargs={
                         'modelName':
                         'Spectrometer',
                         'filter':
                         'flight__group:%d,flight__vehicle:%d' %
                         (flight.group.pk, flight.vehicle.pk)
                     })
         }
     return result
Пример #29
0
# __BEGIN_LICENSE__
# Copyright (c) 2015, United States Government, as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All rights reserved.
# __END_LICENSE__

import datetime

from geocamUtil.loader import LazyGetModelByName
from django.conf import settings

PAST_POSITION_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_PAST_POSITION_MODEL)


class PositionFilter(object):
    def __init__(self, distanceMeters, callback=lambda pos: pos.save()):
        self.distanceMeters = distanceMeters
        self.callback = callback

        pastPositions = PAST_POSITION_MODEL.get().objects.all().order_by('-timestamp')
        if pastPositions.count():
            self.previousPos = pastPositions[0]
        else:
            self.previousPos = None

    def add(self, pos):
        if self.previousPos is None or pos.getDistance(self.previousPos) > self.distanceMeters:
            self.callback(pos)
            self.previousPos = pos
            return True
        else:
Пример #30
0
class OrderListJson(BaseDatatableView):
    """
    Ways to look up json for datatables for objects
    """
    
    model = None
    
    # dictionary that is for our filter
    filterDict = {}
    
    # to hold the Q queries for or-ing a search
    queries = None
    
    # set max limit of records returned, this is used to protect our site if someone tries to attack our site
    # and make it return huge amount of data
    max_display_length = 100
    
    def lookupModel(self, modelName):
        try:
            self.model = LazyGetModelByName(getattr(settings, modelName)).get()
        except:
            self.model = LazyGetModelByName(modelName).get()

    @never_cache
    def dispatch(self, request, *args, **kwargs):
        self.filterDict.clear()

        if not self.model:
            if 'modelName' in kwargs:
                self.lookupModel(kwargs.get('modelName'))
        
        if 'filter' in kwargs:
            theFilter = kwargs.get('filter', None)
            self.buildFilterDict(theFilter)

        return super(OrderListJson, self).dispatch(request, *args, **kwargs)


    def addQuery(self, query):
        if self.queries:
            self.queries |= query
        else:
            self.queries = query
        
    def buildQuery(self, search):
        self.queries = None
        if search:
            try:
                for key in self.model.getSearchableFields():
                    self.addQuery(Q(**{key+'__icontains':search}))
                
                if unicode(search).isnumeric():
                    for key in self.model.getSearchableNumericFields():
                        self.addQuery(Q(**{key:search}))
            except:
                try:
                    self.model._meta.get_field('name')
                    self.addQuery(Q(**{'name__icontains':search}))
                except:
                    pass
                
                try:
                    self.model._meta.get_field('description')
                    self.addQuery(Q(**{'description__icontains':search}))
                except:
                    pass
        
    def buildFilterDict(self, theFilter):
        dictEntries = str(theFilter).split(",")
        for entry in dictEntries:
            splits = str(entry).split(":")
            try:
                value = int(splits[1]);
                self.filterDict[splits[0]] = value
            except:
                self.filterDict[splits[0]] = splits[1]

    def filter_queryset(self, qs):
        if self.filterDict:
            qs = qs.filter(**self.filterDict)
        
        defaultToday = u'true' if settings.GEOCAM_UTIL_LIVE_MODE else  u'false'
        todayOnly = self.request.GET.get(u'today', defaultToday)
        if todayOnly == u'true':
            timesearchField = self.model.timesearchField()
            if timesearchField != None:
                today = timezone.localtime(timezone.now()).date()
                filterDict = { timesearchField + '__gt': today}
                qs = qs.filter(**filterDict)
            
        # TODO handle search with sphinx
        search = self.request.GET.get(u'search[value]', None)
        if search:
            self.buildQuery(str(search))
            if self.queries:
                qs = qs.filter(self.queries)
        
        last = self.request.GET.get(u'last', -1)
        if last > 0:
            qs = qs[-last:]
        
        return qs
Пример #31
0
 def getResource(self):
     resource = LazyGetModelByName(
         settings.GEOCAM_TRACK_RESOURCE_MODEL).get().objects.get(
             vehicle=self.vehicle)
     return resource
Пример #32
0
from geocamPycroraptor2.views import getPyraptordClient, stopPyraptordServiceIfRunning
from xgds_data.introspection import verbose_name
from xgds_video.models import *
from xgds_video.recordingUtil import getRecordedVideoDir, getRecordedVideoUrl, startRecording, stopRecording
from xgds_video.recordingUtil import endActiveEpisode, startFlightRecording, stopFlightRecording
from xgds_status_board.models import *
from xgds_instrument.models import getNewDataFileName

from subprocess import Popen
import re

from django.core.cache import caches

_cache = caches['default']

RESOURCE_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_RESOURCE_MODEL)
VEHICLE_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_VEHICLE_MODEL)
ACTIVE_FLIGHT_MODEL = LazyGetModelByName(
    settings.XGDS_PLANNER2_ACTIVE_FLIGHT_MODEL)

couchStore = CouchDbStorage()

LOCATION_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_PAST_POSITION_MODEL)
VIDEO_SOURCE_MODEL = LazyGetModelByName(settings.XGDS_VIDEO_SOURCE_MODEL)
VIDEO_EPISODE_MODEL = LazyGetModelByName(settings.XGDS_VIDEO_EPISODE_MODEL)


class BasaltResource(geocamTrackModels.AbstractResource):
    resourceId = models.IntegerField(
        null=True, blank=True,
        db_index=True)  # analogous to beacon id, identifier for track inputs
Пример #33
0
 def lookupModel(self, modelName):
     try:
         self.model = LazyGetModelByName(getattr(settings, modelName)).get()
     except:
         self.model = LazyGetModelByName(modelName).get()
Пример #34
0
def getActiveFlights():
    ACTIVE_FLIGHTS_MODEL = LazyGetModelByName(settings.XGDS_PLANNER2_ACTIVE_FLIGHT_MODEL)
    return ACTIVE_FLIGHTS_MODEL.get().objects.all()
Пример #35
0
 def executions(self):
     return LazyGetModelByName(
         settings.XGDS_PLANNER_PLAN_EXECUTION_MODEL).get().objects.filter(
             plan=self)
Пример #36
0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
# __END_LICENSE__

from django.conf import settings
from django.utils import timezone
from django.contrib.contenttypes.models import ContentType

from geocamUtil.loader import LazyGetModelByName
from geocamUtil.UserUtil import getUserByUsername
from xgds_notes2.models import LocatedNote, Role, Location

NOTE_MODEL = LazyGetModelByName(settings.XGDS_NOTES_NOTE_MODEL)
"""
Utility methods for various importers
"""


def link_sample_and_image(sample, image):
    """
    Add a note to link a sample to an image
    :param sample: the sample
    :param image: the image
    :return: the new saved note
    """
    content = 'Sample %s' % sample.name
    return add_note_to_object(content, image, sample.place)
Пример #37
0
from geocamUtil.loader import getModelByName
from geocamUtil.datetimeJsonEncoder import DatetimeJsonEncoder
from geocamUtil import TimeUtil
from geocamUtil.models.UuidField import makeUuid
from geocamUtil.loader import LazyGetModelByName, getClassByName
from geocamUtil.models.managers import ModelCollectionManager

from geocamTrack.utils import getClosestPosition

from PIL import Image
from io import BytesIO
from cStringIO import StringIO
import base64

IMAGE_SET_MODEL = LazyGetModelByName(settings.XGDS_IMAGE_IMAGE_SET_MODEL)
SINGLE_IMAGE_MODEL = LazyGetModelByName(settings.XGDS_IMAGE_SINGLE_IMAGE_MODEL)
TRACK_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_TRACK_MODEL)
POSITION_MODEL = LazyGetModelByName(settings.GEOCAM_TRACK_PAST_POSITION_MODEL)
XGDS_CORE_VEHICLE_MODEL = LazyGetModelByName(settings.XGDS_CORE_VEHICLE_MODEL)

XGDS_IMAGE_TEMPLATE_LIST = list(settings.XGDS_MAP_SERVER_HANDLEBARS_DIRS)
XGDS_IMAGE_TEMPLATE_LIST = XGDS_IMAGE_TEMPLATE_LIST + settings.XGDS_CORE_TEMPLATE_DIRS[
    settings.XGDS_IMAGE_IMAGE_SET_MODEL]

ARROW_ANNOTATION_MODEL = LazyGetModelByName(
    settings.XGDS_IMAGE_ARROW_ANNOTATION_MODEL)
ELLIPSE_ANNOTATION_MODEL = LazyGetModelByName(
    settings.XGDS_IMAGE_ELLIPSE_ANNOTATION_MODEL)
RECTANGLE_ANNOTATION_MODEL = LazyGetModelByName(
    settings.XGDS_IMAGE_RECTANGLE_ANNOTATION_MODEL)
Пример #38
0
def getInstrumentDataJson(request, productModel, productPk):
    INSTRUMENT_DATA_PRODUCT_MODEL = LazyGetModelByName(productModel)
    dataProduct = get_object_or_404(INSTRUMENT_DATA_PRODUCT_MODEL.get(), pk=productPk)
    sampleList = dataProduct.samples
    return HttpResponse(json.dumps(sampleList), content_type='application/json')