def write_deployment(self, campaign_key, deployment_data, extras):
        """
        Write the deployment data to the db, and return a key.
        """

        start_time_stamp = datetime.datetime.strptime(extras[3], '%Y-%m-%dT%H:%M:%S.%fZ')
        end_time_stamp = datetime.datetime.strptime(extras[4], '%Y-%m-%dT%H:%M:%S.%fZ')

        # check if the deployment already exists
        deployments = Deployment.objects.filter(start_time_stamp=start_time_stamp,
                                                short_name=deployment_data['title'],
                                                )

        if deployments.count() > 0:
            print "Deployment %s already exists." % deployments[0].short_name
            return deployments[0].id

        deployment = Deployment(start_time_stamp=start_time_stamp,
                                end_time_stamp=end_time_stamp,
                                short_name=deployment_data['title'][:100],
                                mission_aim=deployment_data['description'],
                                type="SVAM",
                                operator="",
                                start_position=extras[0],
                                end_position=extras[1],
                                transect_shape=extras[2],
                                min_depth=extras[5],
                                max_depth=extras[6],
                                contact_person="",
                                descriptive_keywords="",
                                license="")
        deployment.campaign_id = campaign_key
        deployment.save()

        return deployment.id
Beispiel #2
0
    def post_deployment(self, request, **kwargs):
        # should extract and validate the form...
        form = staging_forms.ApiDeploymentForm(request.POST)
        if form.is_valid():
            # extract the path we are working with
            base = staging_settings.STAGING_IMPORT_DIR
            path = os.path.join(base, kwargs['pk'].decode('hex'))
            path = os.path.abspath(path)

            # now we create the deployment
            created_deployment = Deployment()

            data = form.cleaned_data

            created_deployment.short_name = data['short_name']
            created_deployment.campaign = data['campaign']
            created_deployment.license = data['license']
            created_deployment.descriptive_keywords = data[
                'descriptive_keywords']

            print "passing to function to process"
            # now pass to the parsing function
            try:
                DeploymentImporter.import_path(created_deployment, path)
                logger.debug("DeploymentImporter Run successfully.")
                return self.create_response(request, created_deployment)
            except Exception:
                logger.exception("Unable to import deployment.")
    def write_deployment(self, campaign_key, deployment_data):
        """
        Write the deployment data to the db, and return a key.
        """

        # check if the deployment already exists
        deployments = Deployment.objects.filter(start_time_stamp=deployment_data['start_time_stamp'], short_name=deployment_data['short_name'])

        if deployments.count() > 0:
            print "Deployment %s already exists." % deployments[0].short_name
            return deployments[0].id

        deployment = Deployment(**deployment_data)
        deployment.campaign_id = campaign_key
        deployment.save()

        return deployment.id
Beispiel #4
0
    def test_deployment_import(self):
        """Test the actual import code."""

        # create a few measurement types needed for this
        cadence = ScientificMeasurementType()

        cadence.normalised_name = "cadence"
        cadence.display_name = "Cadence"
        cadence.max_value = 200
        cadence.min_value = 0
        cadence.description = "How fast you pedal"
        cadence.units = 'm'

        cadence.save()

        index = ScientificMeasurementType()

        index.normalised_name = "index"
        index.display_name = "Index"
        index.max_value = 100000
        index.min_value = 0
        index.description = "Number of the Image"
        index.units = "m"

        index.save()

        # get the fixture path
        path = self.deployment_path

        # prefill what we need to
        deployment = Deployment()

        deployment.short_name = "TestDeployment"
        deployment.campaign = self.campaign
        deployment.license = "CC-BY"
        deployment.descriptive_keywords = "Test Keyword, Other Keyword"

        # and fire it off!
        # this should throw nothing
        deploymentimport.DeploymentImporter.import_path(deployment, path)

        # now check it worked!

        # there are 16 image pairs
        self.assertEqual(deployment.pose_set.count(), 16)

        for p in deployment.pose_set.all():
            # check the correct number of images per pose
            self.assertEqual(p.image_set.count(), 2)

            # check the cadence pose measurement came through
            self.assertEqual(p.scientificposemeasurement_set.count(), 1)

            cadence_m = p.scientificposemeasurement_set.get(measurement_type__normalised_name="cadence")

            # get the front image
            front = p.image_set.get(camera__name="Front")

            # check it has an index measurement
            self.assertEqual(front.scientificimagemeasurement_set.count(), 1)

            index_m = front.scientificimagemeasurement_set.get(measurement_type__normalised_name="index")