Ejemplo n.º 1
0
    def create_get_site_response(self, siteArg=None):

        if siteArg == None or siteArg == '':
            siteResultArr = self.dao.get_all_sites()
        else:
            siteCodesArr = siteArg.split(',')
            siteCodesArr = [
                s.replace(self.network + ':', '') for s in siteCodesArr
            ]
            siteResultArr = self.dao.get_sites_by_codes(siteCodesArr)

        if len(siteResultArr) == 0:
            return None

        siteInfoResponse = WaterML.SiteInfoResponseType()

        queryInfo = WaterML.QueryInfoType()
        #TODO: check on how this should be done for multiple sites
        criteria = WaterML.criteria(locationParam=siteArg)
        queryInfo.set_criteria(criteria)
        queryInfoNote = WaterML.NoteType()
        queryInfo.add_note(queryInfoNote)
        queryInfo.set_extension('')
        siteInfoResponse.set_queryInfo(queryInfo)

        for siteResult in siteResultArr:
            s = self.create_site_element(siteResult)
            siteInfoResponse.add_site(s)

        return siteInfoResponse
Ejemplo n.º 2
0
    def create_get_site_info_response(self, siteArg, varArg=None):
        siteCode = siteArg.replace(self.network + ':', '')
        siteResult = self.dao.get_site_by_code(siteCode)

        if (varArg == None or varArg == ''):
            seriesResultArr = self.dao.get_series_by_sitecode(siteCode)
        else:
            varCode = varArg.replace(self.vocabulary + ':', '')
            seriesResultArr = self.dao.get_series_by_sitecode_and_varcode(
                siteCode, varCode)

        if len(seriesResultArr) == 0:
            return None

        siteInfoResponse = WaterML.SiteInfoResponseType()

        queryInfo = WaterML.QueryInfoType()
        criteria = WaterML.criteria(locationParam=siteArg,
                                    variableParam=varArg)
        queryInfo.set_criteria(criteria)
        queryInfoNote = WaterML.NoteType()
        queryInfo.add_note(queryInfoNote)
        queryInfo.set_extension('')
        siteInfoResponse.set_queryInfo(queryInfo)

        s = self.create_site_element(siteResult, seriesResultArr)
        siteInfoResponse.add_site(s)

        return siteInfoResponse
Ejemplo n.º 3
0
    def create_get_values_response(self,
                                   siteArg,
                                   varArg,
                                   startDateTime=None,
                                   endDateTime=None):

        #TODO: Tim thinks the DAO should handle network and vocab parsing,
        #      not WOF
        siteCode = siteArg.replace(self.network + ':', '')
        varCode = varArg.replace(self.vocabulary + ':', '')

        valueResultArr = self.dao.get_datavalues(siteCode, varCode,
                                                 startDateTime, endDateTime)
        if not valueResultArr:
            raise Exception(
                "ERROR: No data found for %s:%s for dates %s - %s" %
                (siteCode, varCode, startDateTime, endDateTime))

        timeSeriesResponse = WaterML.TimeSeriesResponseType()

        queryInfo = WaterML.QueryInfoType()
        timeParam = WaterML.timeParam(beginDateTime=startDateTime,
                                      endDateTime=endDateTime)
        criteria = WaterML.criteria(locationParam=siteArg,
                                    variableParam=varArg,
                                    timeParam=timeParam)
        queryInfo.set_criteria(criteria)
        queryInfoNote = WaterML.NoteType()
        queryInfo.add_note(queryInfoNote)
        queryInfo.set_extension('')
        timeSeriesResponse.set_queryInfo(queryInfo)

        timeSeries = WaterML.TimeSeriesType()

        #sourceInfo (which is a siteInfo) element
        siteResult = self.dao.get_site_by_code(siteCode)

        #TODO: Exception?
        if not siteResult:
            pass

        sourceInfo = self.create_site_info_element(siteResult)
        timeSeries.sourceInfo = sourceInfo

        #variable element
        varResult = self.dao.get_variable_by_code(varCode)

        #TODO: Exception?
        if not varResult:
            pass

        variable = self.create_variable_element(varResult)
        timeSeries.variable = variable

        #TODO: fill in some more of the attributes in this element
        values = WaterML.TsValuesSingleVariableType()

        values.count = len(valueResultArr)

        if varResult.VariableUnits:
            values.unitsAbbreviation = varResult.VariableUnits.UnitsAbbreviation
            values.unitsCode = varResult.VariableUnits.UnitsID

        #Need to keep track of unique methodIDs and sourceIDs
        methodIdSet = set()
        sourceIdSet = set()
        qualifierIdSet = set()
        offsetTypeIdSet = set()

        for valueResult in valueResultArr:
            v = self.create_value_element(valueResult)
            values.add_value(v)

            if valueResult.MethodID:
                methodIdSet.add(valueResult.MethodID)

            if valueResult.SourceID:
                sourceIdSet.add(valueResult.SourceID)

            if valueResult.QualifierID:
                qualifierIdSet.add(valueResult.QualifierID)

            if valueResult.OffsetTypeID:
                offsetTypeIdSet.add(valueResult.OffsetTypeID)

        #Add method elements for each unique methodID
        if methodIdSet:
            methodIdArr = list(methodIdSet)
            methodResultArr = self.dao.get_methods_by_ids(methodIdArr)
            for methodResult in methodResultArr:
                method = self.create_method_element(methodResult)
                values.add_method(method)

        #Add source elements for each unique sourceID
        if sourceIdSet:
            sourceIdArr = list(sourceIdSet)
            sourceResultArr = self.dao.get_sources_by_ids(sourceIdArr)
            for sourceResult in sourceResultArr:
                source = self.create_source_element(sourceResult)
                values.add_source(source)

        #Add qualifier elements
        if qualifierIdSet:
            qualIdArr = list(qualifierIdSet)
            qualResultArr = self.dao.get_qualifiers_by_ids(qualIdArr)
            for qualifierResult in qualResultArr:
                q = WaterML.qualifier(
                    qualifierID=qualifierResult.QualifierID,
                    default=None,
                    network=self.network,
                    vocabulary=self.vocabulary,
                    qualifierCode=qualifierResult.QualifierCode)
                values.add_qualifier(q)

        #Add offset elements
        if offsetTypeIdSet:
            offsetTypeIdArr = list(offsetTypeIdSet)
            offsetTypeResultArr = self.dao.get_offsettypes_by_ids(
                offsetTypeIdArr)
            for offsetTypeResult in offsetTypeResultArr:
                offset = self.create_offset_element(offsetTypeResult)
                values.add_offset(offset)

        timeSeries.values = values
        timeSeriesResponse.set_timeSeries(timeSeries)
        return timeSeriesResponse