Exemple #1
0
    def _exportMetaInformationToXML(self, session, exercise, annotationFile):
        """
        Creates a XML file containing the session details. Specifying the 
        ``Session``, ``Exercise`` and the fll path to the ``Annotationfile`` 
        containing all Validationdata.

        :param str session: Name of the current session
        :param str exercise: Name of the current exercise
        :param str annotationFile: Full path to the annotation file
        """
        filename = 'metainformation.xml'
        output = self._getExportLocation(session, exercise)

        # Build XML structure
        documentXML = et.Element('Meta')

        sessionXML = et.SubElement(documentXML, 'Session')
        sessionXML.text = session

        exerciseXML = et.SubElement(documentXML, 'Exercise')
        exerciseXML.text = exercise

        annotationXML = et.SubElement(documentXML, 'Annotationfile')
        annotationXML.text = output + annotationFile

        exportXML = et.ElementTree(documentXML)
        shared.indentXML(documentXML)
        exportXML.write(output + filename, encoding='utf-8', 
                xml_declaration=True)
        return True
Exemple #2
0
    def export(self, validation):
        """
        :param validation: The parsed 
            :class:`Textfile <txtvalidation.TxtConverter.parseTxtFile>`
        :type validation:
            :class:`Validationfile <lib.shared.Validationfile>`
        """

        filename = 'annotation.xml'

        self._exportMetaInformationToXML(validation.sourcefile.session, 
                validation.sourcefile.exercise, filename)
        output = self._getExportLocation(validation.sourcefile.session,
                validation.sourcefile.exercise)

        # check if file already exists (from a previous run or the other sensors)
        if os.path.isfile(output + filename):
            document = et.ElementTree()
            document.parse(output + filename)

            overwrite = document.find('.//Sensor[@Orientation="'+
                    validation.sourcefile.orientation.name.lower() +'"]/..[@Type="'+validation.type+'"]')
            if overwrite:
                document.getroot().remove(overwrite)
        else:
            head = et.Element('Data')
            document = et.ElementTree(head)

        document = document.getroot()
        if validation.type:
            validationXML = et.SubElement(document, 'Validation')
            validationXML.set('Type', validation.type)
        else:
            validationXML = document

        orientationXML = et.SubElement(validationXML, 'Sensor')
        orientationXML.set('Orientation', validation.sourcefile.orientation.name)

        meta = et.SubElement(orientationXML, 'Meta')
        #print(validation.properties, file=sys.stderr)
        for prop in validation.properties:
            tmp = et.SubElement(meta, prop[0])
            tmp.text = prop[1]

        content = et.SubElement(orientationXML, 'Content')
        steps = 1
        for prop in validation.content:
            counter = et.SubElement(content, 'No' + str(steps))
            for key, value in prop.items():
                tmp = et.SubElement(counter, key)
                tmp.text = value
            steps = steps + 1

        export = et.ElementTree(document)
        shared.indentXML(document)
        export.write(output + filename, encoding='utf-8',
                xml_declaration=True)
        return True