<commit_before>from __future__ import absolute_import

import datetime
from django.conf import settings
from couchdbkit.ext.django.schema import *
import couchforms.const as const
from dimagi.utils.indicators import IndicatorDocumentMixin
from dimagi.utils.parsing import string_to_datetime
from couchdbkit.schema.properties_proxy import SchemaListProperty
from couchforms.safe_index import safe_index
from xml.etree import ElementTree
from django.utils.datastructures import SortedDict
from couchdbkit.resource import ResourceNotFound
import logging
import hashlib
from copy import copy
from couchforms.signals import submission_error_received
from dimagi.utils.mixins import UnicodeMixIn
from couchforms.const import ATTACHMENT_NAME

class Metadata(DocumentSchema):
    """
    Metadata of an xform, from a meta block structured like:
        
        <Meta>
            <timeStart />
            <timeEnd />
            <instanceID />
            <userID />
            <deviceID />
            <deprecatedID /> 
            <username />
        </Meta>
    
    See spec: https://bitbucket.org/javarosa/javarosa/wiki/OpenRosaMetaDataSchema
    
    username is not part of the spec but included for convenience
    """
    timeStart = DateTimeProperty()
    timeEnd = DateTimeProperty()
    instanceID = StringProperty()
    userID = StringProperty()
    deviceID = StringProperty()
    deprecatedID = StringProperty()
    username = StringProperty()
    
class XFormInstance(Document, UnicodeMixIn, IndicatorDocumentMixin):
    """An XForms instance."""
    xmlns = StringProperty()
    received_on = DateTimeProperty()
    
    @property
    def get_form(self):
        """public getter for the xform's form instance, it's redundant with 
        _form but wrapping that access gives future audit capabilities"""
        return self._form
    
    @property
    def _form(self):
        return self[const.TAG_FORM]
    
    @property
    def type(self):
        return self._form.get(const.TAG_TYPE, "")
        
    @property
    def version(self):
        return self._form.get(const.TAG_VERSION, "")
        
    @property<commit_msg>renamed the computed mixin to something more general, not related specifically to indicators<commit_after>from __future__ import absolute_import

import datetime
from django.conf import settings
from couchdbkit.ext.django.schema import *
import couchforms.const as const
from dimagi.utils.indicators import ComputedDocumentMixin
from dimagi.utils.parsing import string_to_datetime
from couchdbkit.schema.properties_proxy import SchemaListProperty
from couchforms.safe_index import safe_index
from xml.etree import ElementTree
from django.utils.datastructures import SortedDict
from couchdbkit.resource import ResourceNotFound
import logging
import hashlib
from copy import copy
from couchforms.signals import submission_error_received
from dimagi.utils.mixins import UnicodeMixIn
from couchforms.const import ATTACHMENT_NAME

class Metadata(DocumentSchema):
    """
    Metadata of an xform, from a meta block structured like:
        
        <Meta>
            <timeStart />
            <timeEnd />
            <instanceID />
            <userID />
            <deviceID />
            <deprecatedID /> 
            <username />
        </Meta>
    
    See spec: https://bitbucket.org/javarosa/javarosa/wiki/OpenRosaMetaDataSchema
    
    username is not part of the spec but included for convenience
    """
    timeStart = DateTimeProperty()
    timeEnd = DateTimeProperty()
    instanceID = StringProperty()
    userID = StringProperty()
    deviceID = StringProperty()
    deprecatedID = StringProperty()
    username = StringProperty()
    
class XFormInstance(Document, UnicodeMixIn, ComputedDocumentMixin):
    """An XForms instance."""
    xmlns = StringProperty()
    received_on = DateTimeProperty()
    
    @property
    def get_form(self):
        """public getter for the xform's form instance, it's redundant with 
        _form but wrapping that access gives future audit capabilities"""
        return self._form
    
    @property
    def _form(self):
        return self[const.TAG_FORM]
    
    @property
    def type(self):
        return self._form.get(const.TAG_TYPE, "")
        
    @property
    def version(self):
        return self._form.get(const.TAG_VERSION, "")
        
    @property
{'fraction_non_alphanumeric': 0.0712812285124914, 'fraction_numerical': 0.0, 'mean_word_length': 3.0370027752081405, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4291832', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1133, 'n_words': 341}