示例#1
0
    def create_get_variable_info_response(self, varArg=None):

        if (varArg == None or varArg == ''):
            variableResultArr = self.dao.get_all_variables()
        else:
            varCodesArr = varArg.split(',')
            varCodesArr = [
                v.replace(self.vocabulary + ':', '') for v in varCodesArr
            ]
            variableResultArr = self.dao.get_variables_by_codes(varCodesArr)

        variableInfoResponse = WaterML.VariablesResponseType()

        # TODO: Should queryInfo be in thois response?  Suds doesn't
        # like when it is.  If it should be in the response, then the
        # WSDL needs to be updated

        #queryInfo = WaterML.QueryInfoType()
        #criteria = WaterML.criteria(variableParam=varArg)
        #queryInfo.set_criteria(criteria)
        #queryInfoNote = WaterML.NoteType()
        #queryInfo.add_note(queryInfoNote)
        #queryInfo.set_extension('')
        #variableInfoResponse.set_queryInfo(queryInfo)

        variables = WaterML.variables()
        for variableResult in variableResultArr:
            v = self.create_variable_element(variableResult)
            variables.add_variable(v)
        variableInfoResponse.set_variables(variables)
        return variableInfoResponse
示例#2
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
示例#3
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
示例#4
0
    def create_variable_element(self, variableResult):
        variable = WaterML.VariableInfoType(
            variableName=variableResult.VariableName,
            valueType=variableResult.ValueType,
            dataType=variableResult.DataType,
            generalCategory=variableResult.GeneralCategory,
            sampleMedium=variableResult.SampleMedium,
            NoDataValue=variableResult.NoDataValue,
            variableDescription=variableResult.VariableDescription)

        variableCode = WaterML.variableCode()
        variableCode.vocabulary = self.vocabulary
        #TODO: What is this, should it always be true?
        variableCode.default = "true"
        variableCode.variableID = variableResult.VariableID
        variableCode.valueOf_ = variableResult.VariableCode

        variable.add_variableCode(variableCode)

        if variableResult.VariableUnits:
            units = WaterML.units(
                unitsAbbreviation=variableResult.VariableUnits.
                UnitsAbbreviation,
                unitsCode=variableResult.VariableUnitsID,
                unitsType=variableResult.VariableUnits.UnitsType,
                valueOf_=variableResult.VariableUnits.UnitsName)

            variable.set_units(units)

        timeSupport = WaterML.timeSupport()
        timeSupport.isRegular = variableResult.IsRegular

        if variableResult.TimeUnits:
            timeUnits = WaterML.UnitsType(
                UnitID=variableResult.TimeUnits.UnitsID,
                UnitName=variableResult.TimeUnits.UnitsName,
                UnitDescription=variableResult.TimeUnits.UnitsName,
                UnitType=variableResult.TimeUnits.UnitsType,
                UnitAbbreviation=variableResult.TimeUnits.UnitsAbbreviation)

            timeSupport.set_unit(timeUnits)

        # TODO: time interval is not the same as time support.
        # Time interval refers to a spacing between values for regular data,
        # which isn't stored in ODM.
        if variableResult.TimeSupport:
            # integer in WaterML 1.0
            timeSupport.timeInterval = str(int(variableResult.TimeSupport))
        variable.set_timeSupport(timeSupport)
        return variable
示例#5
0
文件: core.py 项目: jirikadlec2/WOFpy
    def create_variable_element(self, variableResult):
        variable = WaterML.VariableInfoType(
            variableName=variableResult.VariableName,
            valueType=variableResult.ValueType,
            dataType=variableResult.DataType,
            generalCategory=variableResult.GeneralCategory,
            sampleMedium=variableResult.SampleMedium,
            NoDataValue=variableResult.NoDataValue,
            variableDescription=variableResult.VariableDescription)

        variableCode = WaterML.variableCode()
        variableCode.vocabulary = self.vocabulary
        #TODO: What is this, should it always be true?
        variableCode.default = "true"
        variableCode.variableID = variableResult.VariableID
        variableCode.valueOf_ = variableResult.VariableCode

        variable.add_variableCode(variableCode)

        if variableResult.VariableUnits:
            units = WaterML.units(
                unitsAbbreviation=variableResult.VariableUnits.UnitsAbbreviation,
                unitsCode=variableResult.VariableUnitsID,
                unitsType=variableResult.VariableUnits.UnitsType,
                valueOf_=variableResult.VariableUnits.UnitsName)

            variable.set_units(units)

        timeSupport = WaterML.timeSupport()
        timeSupport.isRegular = variableResult.IsRegular

        if variableResult.TimeUnits:
            timeUnits = WaterML.UnitsType(
                UnitID=variableResult.TimeUnits.UnitsID,
                UnitName=variableResult.TimeUnits.UnitsName,
                UnitDescription=variableResult.TimeUnits.UnitsName,
                UnitType=variableResult.TimeUnits.UnitsType,
                UnitAbbreviation=variableResult.TimeUnits.UnitsAbbreviation)

            timeSupport.set_unit(timeUnits)

        # TODO: time interval is not the same as time support.
        # Time interval refers to a spacing between values for regular data,
        # which isn't stored in ODM.
        if variableResult.TimeSupport:
            # integer in WaterML 1.0
            timeSupport.timeInterval = str(int(variableResult.TimeSupport))
        variable.set_timeSupport(timeSupport)
        return variable
示例#6
0
文件: core.py 项目: jirikadlec2/WOFpy
    def create_site_info_element(self, siteResult):
        siteInfo = WaterML.SiteInfoType()
        siteInfo.set_siteName(siteResult.SiteName)

        #TODO: agencyName
        siteCode = WaterML.siteCode(network=self.network,
                                    siteID=siteResult.SiteID,
                                    valueOf_=siteResult.SiteCode,
                                    agencyName=None,
                                    defaultId=None)

        siteInfo.add_siteCode(siteCode)

        # TODO: Maybe remove this?  None of the other WOF services
        # return this info probably because it is not that useful
        timeZoneInfo = WaterML.timeZoneInfo(siteUsesDaylightSavingsTime=False,
                                            daylightSavingsTimeZone=None)
        timeZoneInfo.defaultTimeZone = WaterML.defaultTimeZone(
            ZoneOffset=self.timezone,
            ZoneAbbreviation=self.timezone_abbr)

        siteInfo.set_timeZoneInfo(timeZoneInfo)
        geoLocation = WaterML.geoLocation()
        geogLocation = WaterML.LatLonPointType(
            srs="EPSG:{0}".format(siteResult.LatLongDatum.SRSID),
            latitude=siteResult.Latitude,
            longitude=siteResult.Longitude)
        geoLocation.set_geogLocation(geogLocation)

        if (siteResult.LocalX and siteResult.LocalY):
            localSiteXY = WaterML.localSiteXY()
            localSiteXY.projectionInformation = \
                                        siteResult.LocalProjection.SRSName
            localSiteXY.X = siteResult.LocalX
            localSiteXY.Y = siteResult.LocalY
            geoLocation.add_localSiteXY(localSiteXY)

        siteInfo.set_geoLocation(geoLocation)
        siteInfo.set_verticalDatum(siteResult.VerticalDatum)

        # need at least one extension element to meet WaterML 1.0
        # schema validation

        siteInfo.set_extension('')

        # need at least one altname element to meet WaterML 1.0 schema
        # validation
        siteInfo.set_altname('')
        return siteInfo
示例#7
0
文件: core.py 项目: jirikadlec2/WOFpy
    def create_get_variable_info_response(self, varArg=None):

        if (varArg == None or varArg == ''):
            variableResultArr = self.dao.get_all_variables()
        else:
            varCodesArr = varArg.split(',')
            varCodesArr = [v.replace(self.vocabulary + ':', '')
                           for v in varCodesArr]
            variableResultArr = self.dao.get_variables_by_codes(varCodesArr)

        variableInfoResponse = WaterML.VariablesResponseType()

        # TODO: Should queryInfo be in thois response?  Suds doesn't
        # like when it is.  If it should be in the response, then the
        # WSDL needs to be updated

        #queryInfo = WaterML.QueryInfoType()
        #criteria = WaterML.criteria(variableParam=varArg)
        #queryInfo.set_criteria(criteria)
        #queryInfoNote = WaterML.NoteType()
        #queryInfo.add_note(queryInfoNote)
        #queryInfo.set_extension('')
        #variableInfoResponse.set_queryInfo(queryInfo)

        variables = WaterML.variables()
        for variableResult in variableResultArr:
            v = self.create_variable_element(variableResult)
            variables.add_variable(v)
        variableInfoResponse.set_variables(variables)
        return variableInfoResponse
示例#8
0
文件: core_1_0.py 项目: ODM2/WOFpy
    def create_get_site_response(self, siteArg=None):

        if siteArg == None or siteArg == '':
            siteResultArr = self.dao.get_all_sites()
        else:
            siteCodesArr = siteArg.split(',')
            siteCodesArr = [self.get_site_code(s)
                            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)

        if siteResultArr:
            for siteResult in siteResultArr:
                s = self.create_site_element(siteResult)
                siteInfoResponse.add_site(s)
        else:
            #site = WaterML.site()
            #siteInfoResponse.add_site(site)
            raise Exception("Site,'%s', Not Found" % siteArg)

        return siteInfoResponse
示例#9
0
文件: core.py 项目: jirikadlec2/WOFpy
    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
示例#10
0
    def create_value_element(self, valueResult):
        datetime_string = _get_iso8061_datetime_string(valueResult,
                                                       "LocalDateTime",
                                                       "DateTimeUTC")

        value = WaterML.ValueSingleVariable(
            qualityControlLevel=valueResult.QualityControlLevel,
            methodID=valueResult.MethodID,
            sourceID=valueResult.SourceID,
            censorCode=valueResult.CensorCode,
            sampleID=valueResult.SampleID,
            offsetTypeID=valueResult.OffsetTypeID,
            accuracyStdDev=valueResult.ValueAccuracy,
            offsetValue=valueResult.OffsetValue,
            dateTime=datetime_string,
            qualifiers=valueResult.QualifierID,
            valueOf_=str(valueResult.DataValue))

        # TODO: value.offset stuff?  Why does value element have all
        # this offset stuff
        #offsetTypeResult = valueResult.OffsetType
        #if offsetTypeResult != None:
        #    value.offsetDescription = offsetTypeResult.OffsetDescription
        #    value.offsetUnitsAbbreviation = offsetTypeResult.OffsetUnits.UnitsAbbreviation
        #    value.offsetUnitsCode = offsetTypeResult.OffsetUnits.UnitsID
        return value
示例#11
0
文件: core.py 项目: jirikadlec2/WOFpy
    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
示例#12
0
文件: core_1_0.py 项目: ODM2/WOFpy
 def create_qlevel_element(self, qlevelResult):
     #qlevel = WaterML.QualityControlLevelType(
     #            qualityControlLevelID=qlevelResult.QualityControlLevelID,
     #            valueOf_=qlevelResult.QualityControlLevelCode)
     qcode = WaterML.qualityControlLevel(qualityControlLevelCode=qlevelResult.QualityControlLevelCode,
                                         qualityControlLevelID=str(qlevelResult.QualityControlLevelID)
                                         )
     return qcode
示例#13
0
文件: core.py 项目: jirikadlec2/WOFpy
    def create_site_element(self, siteResult, seriesResultArr=None):
        site = WaterML.site()
        siteInfo = self.create_site_info_element(siteResult)

        site.set_siteInfo(siteInfo)

        #need at least one note element to meet WaterML 1.0 schema validation
        if (not siteResult.County
            and not siteResult.State
            and not siteResult.Comments):

            siteInfo.add_note(WaterML.NoteType())
        else:
            if siteResult.County:
                countyNote = WaterML.NoteType(title="County",
                                              valueOf_=siteResult.County)
                siteInfo.add_note(countyNote)

            if siteResult.State:
                stateNote = WaterML.NoteType(title="State",
                                             valueOf_=siteResult.State)
                siteInfo.add_note(stateNote)

            if siteResult.Comments:
                commentsNote = WaterML.NoteType(
                    title="Site Comments",
                    valueOf_=escape(siteResult.Comments))
                siteInfo.add_note(commentsNote)

        seriesCatalog = WaterML.seriesCatalogType()
        if (seriesResultArr != None):
            seriesCatalog.menuGroupName = self.menu_group_name
            #TODO: Make sure this is set properly in config fileame
            seriesCatalog.serviceWsdl = self.service_wsdl

            for seriesResult in seriesResultArr:
                series = self.create_series_element(seriesResult)

                seriesCatalog.add_series(series)

        site.add_seriesCatalog(seriesCatalog)

        # need at least one extension element to meet WaterML 1.0
        # schema validation
        site.set_extension('')
        return site
示例#14
0
文件: core_1_0.py 项目: ODM2/WOFpy
    def create_series_element(self, seriesResult):
        series = WaterML.series()

        #Variable
        variable = self.create_variable_element(seriesResult.Variable)
        series.set_variable(variable)

        series.valueCount = WaterML.valueCount(
            valueOf_=str(seriesResult.ValueCount))

# in WML1_0, these are strings.
        beginDateTime = core._get_datavalues_datetime(
            seriesResult, "BeginDateTime", "BeginDateTimeUTC").isoformat()
        endDateTime = core._get_datavalues_datetime(
            seriesResult, "EndDateTime", "EndDateTimeUTC").isoformat()

        #TimeInterval
        if beginDateTime is None:
            beginDateTime = datetime.datetime.now().isoformat()
        if endDateTime is None:
            endDateTime = datetime.datetime.now().isoformat()
        variableTimeInt = WaterML.TimeIntervalType(
            beginDateTime=beginDateTime,
            endDateTime=endDateTime)
        series.variableTimeInterval = variableTimeInt

        #Method
        if seriesResult.Method:
            method = self.create_method_element(seriesResult.Method)
            series.Method = method

        #Source
        if seriesResult.Source:
            source = self.create_source_element(seriesResult.Source)
            series.Source = source

        #QualityControlLevel
        qualityControlLevel = WaterML.QualityControlLevelType(
                    qualityControlLevelID=seriesResult.QualityControlLevelID,
                    valueOf_=seriesResult.QualityControlLevelCode)

        series.QualityControlLevel = qualityControlLevel

        return series
示例#15
0
    def create_method_element(self, methodResult):
        method = WaterML.MethodType(
            methodID=methodResult.MethodID,
            MethodDescription=methodResult.MethodDescription,
            MethodLink=methodResult.MethodLink)

        # need at least one MethodLink element to meet WaterML 1.0
        # schema validation
        if method.MethodLink == None:
            method.MethodLink = ''
        return method
示例#16
0
    def create_offset_element(self, offsetTypeResult):
        #TODO: where does offsetIsVertical come from
        #TODO: where does offsetHorizDirectionDegrees come from?
        offset = WaterML.OffsetType(
            offsetTypeID=offsetTypeResult.OffsetTypeID,
            offsetValue=None,
            offsetDescription=offsetTypeResult.OffsetDescription,
            offsetIsVertical='true',
            offsetHorizDirectionDegrees=None)

        if offsetTypeResult.OffsetUnits:
            units = WaterML.UnitsType(
                UnitID=offsetTypeResult.OffsetUnits.UnitsID,
                UnitAbbreviation=offsetTypeResult.OffsetUnits.
                UnitsAbbreviation,
                UnitName=offsetTypeResult.OffsetUnits.UnitsName,
                UnitType=offsetTypeResult.OffsetUnits.UnitsType)

            offset.units = units

        return offset
示例#17
0
    def create_source_element(self, sourceResult):
        source = WaterML.SourceType(
            sourceID=sourceResult.SourceID,
            Organization=sourceResult.Organization,
            SourceDescription=sourceResult.SourceDescription,
            SourceLink=sourceResult.SourceLink)

        contactInfo = self.create_contact_info_element(sourceResult)

        source.ContactInformation = contactInfo

        if sourceResult.Metadata:
            metadata = WaterML.MetaDataType(
                TopicCategory=sourceResult.Metadata.TopicCategory,
                Title=sourceResult.Metadata.Title,
                Abstract=sourceResult.Metadata.Abstract,
                ProfileVersion=sourceResult.Metadata.ProfileVersion,
                MetadataLink=sourceResult.Metadata.MetadataLink)

            source.Metadata = metadata

        return source
示例#18
0
文件: core.py 项目: jirikadlec2/WOFpy
    def create_series_element(self, seriesResult):
        series = WaterML.series()

        #Variable
        variable = self.create_variable_element(seriesResult.Variable)
        series.set_variable(variable)

        series.valueCount = WaterML.valueCount(
            valueOf_=str(seriesResult.ValueCount))

        beginDateTime = _get_iso8061_datetime_string(
            seriesResult, "BeginDateTime", "BeginDateTimeUTC")
        endDateTime = _get_iso8061_datetime_string(
            seriesResult, "EndDateTime", "EndDateTimeUTC")

        #TimeInterval
        variableTimeInt = WaterML.TimeIntervalType(
            beginDateTime=beginDateTime,
            endDateTime=endDateTime)
        series.variableTimeInterval = variableTimeInt

        #Method
        if seriesResult.Method:
            method = self.create_method_element(seriesResult.Method)
            series.Method = method

        #Source
        if seriesResult.Source:
            source = self.create_source_element(seriesResult.Source)
            series.Source = source

        #QualityControlLevel
        qualityControlLevel = WaterML.QualityControlLevelType(
                    qualityControlLevelID=seriesResult.QualityControlLevelID,
                    valueOf_=seriesResult.QualityControlLevelCode)

        series.QualityControlLevel = qualityControlLevel

        return series
示例#19
0
    def create_series_element(self, seriesResult):
        series = WaterML.series()

        #Variable
        variable = self.create_variable_element(seriesResult.Variable)
        series.set_variable(variable)

        series.valueCount = WaterML.valueCount(
            valueOf_=str(seriesResult.ValueCount))

        beginDateTime = _get_iso8061_datetime_string(seriesResult,
                                                     "BeginDateTime",
                                                     "BeginDateTimeUTC")
        endDateTime = _get_iso8061_datetime_string(seriesResult, "EndDateTime",
                                                   "EndDateTimeUTC")

        #TimeInterval
        variableTimeInt = WaterML.TimeIntervalType(beginDateTime=beginDateTime,
                                                   endDateTime=endDateTime)
        series.variableTimeInterval = variableTimeInt

        #Method
        if seriesResult.Method:
            method = self.create_method_element(seriesResult.Method)
            series.Method = method

        #Source
        if seriesResult.Source:
            source = self.create_source_element(seriesResult.Source)
            series.Source = source

        #QualityControlLevel
        qualityControlLevel = WaterML.QualityControlLevelType(
            qualityControlLevelID=seriesResult.QualityControlLevelID,
            valueOf_=seriesResult.QualityControlLevelCode)

        series.QualityControlLevel = qualityControlLevel

        return series
示例#20
0
    def create_site_info_element(self, siteResult):
        siteInfo = WaterML.SiteInfoType()
        siteInfo.set_siteName(siteResult.SiteName)

        #TODO: agencyName
        siteCode = WaterML.siteCode(network=self.network,
                                    siteID=siteResult.SiteID,
                                    valueOf_=siteResult.SiteCode,
                                    agencyName=None,
                                    defaultId=None)

        siteInfo.add_siteCode(siteCode)

        # TODO: Maybe remove this?  None of the other WOF services
        # return this info probably because it is not that useful
        timeZoneInfo = WaterML.timeZoneInfo(siteUsesDaylightSavingsTime=False,
                                            daylightSavingsTimeZone=None)
        timeZoneInfo.defaultTimeZone = WaterML.defaultTimeZone(
            ZoneOffset=self.timezone, ZoneAbbreviation=self.timezone_abbr)

        siteInfo.set_timeZoneInfo(timeZoneInfo)
        geoLocation = WaterML.geoLocation()
        geogLocation = WaterML.LatLonPointType(srs="EPSG:{0}".format(
            siteResult.LatLongDatum.SRSID),
                                               latitude=siteResult.Latitude,
                                               longitude=siteResult.Longitude)
        geoLocation.set_geogLocation(geogLocation)

        if (siteResult.LocalX and siteResult.LocalY):
            localSiteXY = WaterML.localSiteXY()
            localSiteXY.projectionInformation = \
                                        siteResult.LocalProjection.SRSName
            localSiteXY.X = siteResult.LocalX
            localSiteXY.Y = siteResult.LocalY
            geoLocation.add_localSiteXY(localSiteXY)

        siteInfo.set_geoLocation(geoLocation)
        siteInfo.set_verticalDatum(siteResult.VerticalDatum)

        # need at least one extension element to meet WaterML 1.0
        # schema validation

        siteInfo.set_extension('')

        # need at least one altname element to meet WaterML 1.0 schema
        # validation
        siteInfo.set_altname('')
        return siteInfo
示例#21
0
    def create_contact_info_element(self, sourceResult):

        if (sourceResult.Address and sourceResult.City and sourceResult.State
                and sourceResult.ZipCode):

            addressString = ", ".join([
                sourceResult.Address, sourceResult.City, sourceResult.State,
                sourceResult.ZipCode
            ])

            contactInfo = WaterML.ContactInformationType(
                Email=sourceResult.Email,
                ContactName=sourceResult.ContactName,
                Phone=sourceResult.Phone,
                Address=addressString)

            return contactInfo

        return None
示例#22
0
    def create_site_element(self, siteResult, seriesResultArr=None):
        site = WaterML.site()
        siteInfo = self.create_site_info_element(siteResult)

        site.set_siteInfo(siteInfo)

        #need at least one note element to meet WaterML 1.0 schema validation
        if (not siteResult.County and not siteResult.State
                and not siteResult.Comments):

            siteInfo.add_note(WaterML.NoteType())
        else:
            if siteResult.County:
                countyNote = WaterML.NoteType(title="County",
                                              valueOf_=siteResult.County)
                siteInfo.add_note(countyNote)

            if siteResult.State:
                stateNote = WaterML.NoteType(title="State",
                                             valueOf_=siteResult.State)
                siteInfo.add_note(stateNote)

            if siteResult.Comments:
                commentsNote = WaterML.NoteType(title="Site Comments",
                                                valueOf_=escape(
                                                    siteResult.Comments))
                siteInfo.add_note(commentsNote)

        seriesCatalog = WaterML.seriesCatalogType()
        if (seriesResultArr != None):
            seriesCatalog.menuGroupName = self.menu_group_name
            #TODO: Make sure this is set properly in config fileame
            seriesCatalog.serviceWsdl = self.service_wsdl

            for seriesResult in seriesResultArr:
                series = self.create_series_element(seriesResult)

                seriesCatalog.add_series(series)

        site.add_seriesCatalog(seriesCatalog)

        # need at least one extension element to meet WaterML 1.0
        # schema validation
        site.set_extension('')
        return site
示例#23
0
文件: core_1_0.py 项目: ODM2/WOFpy
    def create_get_site_info_response(self, siteArg, varArg=None):
        if siteArg is None:
            raise Exception("Site Not Found")
        siteCode = self.get_site_code(siteArg)
        siteResult = self.dao.get_site_by_code(siteCode)

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

        if seriesResultArr is None or len(seriesResultArr) == 0:
            raise Exception("Site,'%s', Not Found" % siteArg)

        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)

        if siteResult:
            s = self.create_site_element(siteResult, seriesResultArr)
            siteInfoResponse.add_site(s)
        else:
            #site = WaterML.site()
            #siteInfoResponse.add_site(site)
            raise Exception("Site,'%s', Not Found" % siteArg)

        return siteInfoResponse
示例#24
0
文件: core.py 项目: jirikadlec2/WOFpy
    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
示例#25
0
文件: core_1_0.py 项目: ODM2/WOFpy
    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 = self.get_site_code(siteArg)
        varCode = self.get_variable_code(varArg)

        valueResultArr = self.dao.get_datavalues(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)

        #if not valueResultArr:
        #    timeSeries = WaterML.TimeSeriesType()
        #    timeSeriesResponse.set_timeSeries(timeSeries)
        #    return timeSeriesResponse

        if not valueResultArr:
            raise Exception("Values Not Found for %s:%s for dates %s - %s" % (
                siteCode, varCode, startDateTime, endDateTime))

        if isinstance(valueResultArr,dict):
            for key in valueResultArr.keys():
                valueResultArr = valueResultArr[key]
                break

        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()
        qualitycontrollevelIdSet = set()

        for valueResult in valueResultArr:
            if valueResult.QualityControlLevelID is not None:
                qualitycontrollevelIdSet.add(valueResult.QualityControlLevelID)
                qlevelResult = self.dao.get_qualcontrollvl_by_id(valueResult.QualityControlLevelID)
                if hasattr(qlevelResult,'Definition'):
                    valueResult.QualityControlLevel = qlevelResult.Definition
                # else:
                #     if hasattr(valueResult,'QualityControlLevel'):
                #         valueResult.QualityControlLevel = qlevelResult.QualityControlLevelCode
            v = self.create_value_element(valueResult)
            values.add_value(v)

            if valueResult.MethodID is not None:
                methodIdSet.add(valueResult.MethodID)

            if valueResult.SourceID is not None:
                sourceIdSet.add(valueResult.SourceID)

            if valueResult.QualifierID is not None:
                qualifierIdSet.add(valueResult.QualifierID)

            if valueResult.OffsetTypeID is not None:
                offsetTypeIdSet.add(valueResult.OffsetTypeID)

            if valueResult.QualityControlLevelID is not None:
                qualitycontrollevelIdSet.add(valueResult.QualityControlLevelID)

        #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)

        #Add qualitycontrollevel elements
        if qualitycontrollevelIdSet:
            qlevelIdIdArr = list(qualitycontrollevelIdSet)

            try:
                qlevelResultArr = self.dao.get_qualcontrollvls_by_ids(qlevelIdIdArr)
                for qlevelResult in qlevelResultArr:
                    qlevel = self.create_qlevel_element(qlevelResult)
                    values.add_qualityControlLevel(qlevel)
            except:
                logging.warn("WofPy: DOA has no get_qualcontrollvls_by_ids method (added for 2.x)")
                for qlevelID in qlevelIdIdArr:
                    qlevel = WaterML.QualityControlLevelType(
                        qualityControlLevelID=qlevelID )
                    values.add_qualityControlLevel(qlevel)

        timeSeries.values = values
        timeSeriesResponse.set_timeSeries(timeSeries)
        return timeSeriesResponse
示例#26
0
文件: core_1_0.py 项目: ODM2/WOFpy
    def create_variable_element(self, variableResult):
        clean_datatype = self.check_dataTypeEnum( variableResult.DataType)
        clean_medium = self.check_SampleMedium(variableResult.SampleMedium)
        clean_category = self.check_generalCategory(variableResult.GeneralCategory)
        clean_valuetype = self.check_valueType(variableResult.ValueType)
        variable = WaterML.VariableInfoType(
            variableName=variableResult.VariableName,
            #valueType=variableResult.ValueType,
            valueType=clean_valuetype,
                       # dataType=variableResult.DataType,
            dataType =clean_datatype,
            #generalCategory=variableResult.GeneralCategory,
            generalCategory=clean_category,
                        #sampleMedium=variableResult.SampleMedium,
            sampleMedium=clean_medium,
            NoDataValue=variableResult.NoDataValue,
            variableDescription=variableResult.VariableDescription)

        #For specimen data
        v_code = variableResult.VariableCode
        v_code_i = v_code.find('::')
        if v_code_i != -1:
            v_code = v_code[0:v_code_i]

        variableCode = WaterML.variableCode()
        variableCode.vocabulary = self.vocabulary
        #TODO: What is this, should it always be true?
        variableCode.default = "true"
        variableCode.variableID = variableResult.VariableID
        variableCode.valueOf_ = v_code

        variable.add_variableCode(variableCode)
        clean_variableUnits = self.check_UnitsType(variableResult.VariableUnits.UnitsType)

        if variableResult.VariableUnits:
            units = WaterML.units(
                unitsAbbreviation=variableResult.VariableUnits.UnitsAbbreviation,
                unitsCode=variableResult.VariableUnitsID,
                #unitsType=variableResult.VariableUnits.UnitsType,
                unitsType=clean_variableUnits,
                valueOf_=variableResult.VariableUnits.UnitsName)

            variable.set_units(units)

        timeSupport = WaterML.timeSupport()
        timeSupport.isRegular = variableResult.IsRegular

        if variableResult.TimeUnits:
            timeUnits = WaterML.UnitsType(
                UnitID=variableResult.TimeUnits.UnitsID,
                UnitName=variableResult.TimeUnits.UnitsName,
                UnitDescription=variableResult.TimeUnits.UnitsName,
                #UnitType=variableResult.TimeUnits.UnitsType,
                UnitType="Time",
                UnitAbbreviation=variableResult.TimeUnits.UnitsAbbreviation)

            timeSupport.set_unit(timeUnits)

        # TODO: time interval is not the same as time support.
        # Time interval refers to a spacing between values for regular data,
        # which isn't stored in ODM.
        if variableResult.TimeSupport:
            # integer in WaterML 1.0
            timeSupport.timeInterval = str(int(variableResult.TimeSupport))
        variable.set_timeSupport(timeSupport)
        return variable
示例#27
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