Пример #1
0
    def post(self):

        # confirm that the X-Manual header was specified
        manual = checkXManual(request)

        prevId = -1
        if 'X-Crop-Id' in request.headers:
            prevId = request.headers.get('X-Crop-Id')
        else:
            abort(400, "Need to specify header 'X-Crop-Id'!")

        dao = OutgoingManualDAO(
            defaultConfigPath()) if manual else OutgoingAutonomousDAO(
                defaultConfigPath())

        outgoingIn = outgoing_manual(
            json=request.get_json()) if manual else outgoing_autonomous(
                json=request.get_json())
        outgoingIn.crop_id = prevId
        resultingId = dao.upsertClassification(outgoingIn)

        if resultingId == -1:
            return {
                'message':
                'Failed to insert classification into outgoing table'
            }, 500

        response = make_response(
            jsonify({
                'message': 'success!',
                'id': resultingId
            }))
        response.headers['X-Class-Id'] = resultingId
        return response
Пример #2
0
    def newModelFromRow(self, row, json=None):
        """
        Create a new outgoing_autonomous model object given a list of sql values from the table,
        or a json dictionary

        @type row: [string]
        @param row: List of ordered string values to be placed within an outgoing_autonomous object
        """
        return outgoing_autonomous(tableValues=row, json=json)
Пример #3
0
    def test(self):
        truncateTable('incoming_image')
        truncateTable('cropped_autonomous')
        truncateTable('outgoing_autonomous')
        dao = OutgoingAutonomousDAO(defaultConfigPath())

        testIns = outgoing_autonomous()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        self.assertNotEqual(dao.addClassification(testIns), -1)

        dao = CroppedAutonomousDAO(defaultConfigPath())
        model = cropped_autonomous()
        model.image_id = 123
        model.time_stamp = 1547453775.2
        model.cropped_path = '/im/a/totally/real/cropped/path/i/swear.jpg'
        model.crop_coordinate_br = "(12, 34)"
        model.crop_coordinate_tl = "(56, 78)"
        self.assertNotEqual(dao.addImage(model), -1)

        dao = IncomingImageDAO(defaultConfigPath())
        model = incoming_image()
        model.time_stamp = 1547453775.2
        model.focal_length = 16.0
        model.image_path = '/im/a/totally/real/path/i/swear.jpg'
        model.manual_tap = True
        model.autonomous_tap = True
        resultingId = dao.addImage(model)
        self.assertNotEqual(resultingId, -1)

        util = UtilDAO(defaultConfigPath())
        util.resetAutonomousDB()

        resultingModel = dao.getImage(resultingId)
        self.assertIsNotNone(resultingModel)
        self.assertFalse(resultingModel.autonomous_tap)
        self.assertTrue(resultingModel.manual_tap)
        self.assertEqual(resultingModel.image_path, model.image_path)
        self.assertEqual(resultingModel.focal_length, model.focal_length)

        dao = CroppedAutonomousDAO(defaultConfigPath())
        self.assertEqual(len(dao.getAll()), 0)

        dao = OutgoingAutonomousDAO(defaultConfigPath())
        self.assertEqual(len(dao.getAll()), 0)
Пример #4
0
    def test(self):
        truncateTable('outgoing_autonomous')
        dao = OutgoingAutonomousDAO(defaultConfigPath())

        testIns = outgoing_autonomous()
        testIns.crop_id = 42
        testIns.shape = 'circle'
        testIns.background_color = 'white'
        testIns.alphanumeric = 'A'
        testIns.alphanumeric_color = 'black'
        resultingId = dao.addClassification(testIns)
        self.assertNotEqual(resultingId, -1)

        # should not be able to insert a duplicate record
        self.assertEqual(dao.addClassification(testIns), -1)
        self.assertIsNotNone(dao.getClassification(resultingId))