Пример #1
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
Пример #2
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
Пример #3
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
Пример #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 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
Пример #6
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)
Пример #7
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)
Пример #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 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")
Пример #14
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")
Пример #15
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)
Пример #16
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
Пример #17
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
        },
    )
Пример #18
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
Пример #19
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
Пример #20
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
Пример #21
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()
Пример #22
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)
Пример #23
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
Пример #24
0
 def executions(self):
     return LazyGetModelByName(
         settings.XGDS_PLANNER_PLAN_EXECUTION_MODEL).get().objects.filter(
             plan=self)
Пример #25
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)
Пример #26
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)