Skip to content

Commit

Permalink
Fix Data Quality
Browse files Browse the repository at this point in the history
fgdc reader needed some refactoring.
Added/fixed checks for nil/empty.
  • Loading branch information
jwaspin committed Feb 6, 2024
1 parent f7ff830 commit 1ff7d59
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 101 deletions.
142 changes: 52 additions & 90 deletions lib/adiwg/mdtranslator/readers/fgdc/modules/module_quality.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@ module Fgdc
module Quality

def self.unpack(xDataQual, hMetadata, hDataQuality, hResponseObj)
intMetadataClass = InternalMetadata.new

hDataQuality[:scope] = intMetadataClass.newScope
hDataQuality[:scope][:scopeCode] = 'tabularDataset'

hDataQuality[:scope] = {scopeCode: 'tabularDataset'}
hDataQuality[:systemIdentifier] = {
uid: UUIDTools::UUID.random_create.to_s,
label: "CSDGM Data Quality"
}


# data quality 2.1 (attracc) - attribute accuracy
xAccuracy = xDataQual.xpath('./attracc')
accuracyReport = xAccuracy.xpath('./attraccr').text
hDataQuality[:report] << {
type: 'DQ_NonQuantitativeAttributeCompleteness',
descriptiveResult: [ {statement: accuracyReport} ]
}
report = intMetadataClass.newDataQualityReport
report[:type] = 'DQ_NonQuantitativeAttributeAccuracy'
descriptiveResult = intMetadataClass.newDescriptiveResult
descriptiveResult[:statement] = accuracyReport
report[:descriptiveResult] << descriptiveResult
hDataQuality[:report] << report

# data quality 2.1 (qattracc) - Quantitative Attribute Accuracy Assessment

xQuantitativeAccuracy = xDataQual.xpath('./qattracc')
unless xQuantitativeAccuracy.xpath('./attraccv').empty?
hDataQuality[:report] << {
type: 'DQ_QuantitativeAttributeAccuracy',
quantitativeResult: [{
value: xQuantitativeAccuracy.xpath('./attraccv').text
}]
}
report = intMetadataClass.newDataQualityReport
report[:type] = 'DQ_QuantitativeAttributeAccuracy'
report[:quantitativeResult] = intMetadataClass.newQualityMeasure
report[:quantitativeResult][:values] = [xQuantitativeAccuracy.xpath('./attraccv').text]
hDataQuality[:report] << report
end

# data quality 2.2 (logic) - logical consistency (required) (not implemented)
Expand All @@ -50,12 +52,11 @@ def self.unpack(xDataQual, hMetadata, hDataQuality, hResponseObj)
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: data quality logical consistency section is missing'
else
logic = xLogic.text
hDataQuality[:report] << {
type: 'DQ_ConceptualConsistency',
qualityMeasure: {
description: logic
}
}
report = intMetadataClass.newDataQualityReport
report[:type] = 'DQ_ConceptualConsistency'
report[:qualityMeasure] = intMetadataClass.newQualityMeasure
report[:qualityMeasure][:description] = logic
hDataQuality[:report] << report
end

# data quality 2.3 (complete) - completion report (required)
Expand All @@ -64,94 +65,58 @@ def self.unpack(xDataQual, hMetadata, hDataQuality, hResponseObj)
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: data quality completion report section is missing'
else
complete = xComplete.text
hDataQuality[:report] << {
type: 'DQ_CompletenessOmission',
descriptiveResult: [{
statement: complete
}]
}
report = intMetadataClass.newDataQualityReport
report[:type] = 'DQ_CompletenessOmission'
descriptiveResult = intMetadataClass.newDescriptiveResult
descriptiveResult[:statement] = complete
report[:descriptiveResult] << descriptiveResult
hDataQuality[:report] << report
end

# data quality 2.4 (position) - positional accuracy
xPositionalAccuracy = xDataQual.xpath('./posacc')
unless xPositionalAccuracy.empty?

# horizontal positional accuracy
xHorizontal = xPositionalAccuracy.xpath('./horizpa')
unless xHorizontal.empty?

report = {}

unless xHorizontal.xpath('horizpar').empty?
report[:evaluationMethod] = {
methodDescription: xHorizontal.xpath('horizpar').text
}
end

report = intMetadataClass.newDataQualityReport
report[:type] = 'DQ_AbsoluteExternalPositionalAccuracy'
unless xHorizontal.xpath('qhorizpa/horizpae').empty?
report[:qualityMeasure] = {
description: xHorizontal.xpath('qhorizpa/horizpae').text
}
report[:qualityMeasure] = intMetadataClass.newQualityMeasure
report[:qualityMeasure][:description] = xHorizontal.xpath('qhorizpa/horizpae').text
# The commented code below looks wrong and needs to be validated (also, it's nameOfMeasure, which is an array)
# report[:qualityMeasure][:name] = ['Horizontal Positional Accuracy Report']
end

unless xHorizontal.xpath('qhorizpa/horizpav').empty?
report[:quantitativeResult] = [{
value: [ xHorizontal.xpath('qhorizpa/horizpav').text ]
}]
unless xHorizontal.xpath('horizpar').empty?
report[:evaluationMethod] = intMetadataClass.newEvaluationMethod
report[:evaluationMethod][:methodDescription] = xHorizontal.xpath('horizpar').text
end

unless report.empty?
if report[:qualityMeasure].nil?
report[:qualityMeasure] = {
name: ['Horizontal Positional Accuracy Report']
}
else
report[:qualityMeasure][:name] = ['Horizontal Positional Accuracy Report']
end

report[:type] = 'DQ_AbsoluteExternalPositionalAccuracy'

hDataQuality[:report] << report
unless xHorizontal.xpath('qhorizpa/horizpav').empty?
report[:quantitativeResult] = [intMetadataClass.newQuantitativeResult]
report[:quantitativeResult][:values] = [ xHorizontal.xpath('qhorizpa/horizpav').text ]
end
hDataQuality[:report] << report
end

# vertical positional accuracy
xVertical = xPositionalAccuracy.xpath('./vertacc')
unless xVertical.empty?

report = {}

unless xVertical.xpath('vertaccr').empty?
report[:evaluationMethod] = {
methodDescription: xVertical.xpath('vertaccr').text
}
end

report = intMetadataClass.newDataQualityReport
report[:type] = 'DQ_AbsoluteExternalPositionalAccuracy'
unless xVertical.xpath('qvertpa/vertacce').empty?
report[:qualityMeasure] = {
description: xVertical.xpath('qvertpa/vertacce').text
}
report[:qualityMeasure] = intMetadataClass.newQualityMeasure
report[:qualityMeasure][:description] = xVertical.xpath('qvertpa/vertacce').text
# The commented code below looks wrong and needs to be validated (also, it's nameOfMeasure, which is an array)
# report[:qualityMeasure][:name] = ['Vertical Positional Accuracy Report']
end

unless xVertical.xpath('qvertpa/vertaccv').empty?
report[:quantitativeResult] = [{
value: [ xVertical.xpath('qvertpa/vertaccv').text ]
}]
unless xVertical.xpath('vertaccr').empty?
report[:evaluationMethod] = intMetadataClass.newEvaluationMethod
report[:evaluationMethod][:methodDescription] = xVertical.xpath('vertaccr').text
end

unless report.empty?
if report[:qualityMeasure].nil?
report[:qualityMeasure] = {
name: ['Vertical Positional Accuracy Report']
}
else
report[:qualityMeasure][:name] = ['Vertical Positional Accuracy Report']
end

report[:type] = 'DQ_AbsoluteExternalPositionalAccuracy'

hDataQuality[:report] << report
unless xVertical.xpath('qvertpa/vertaccv').empty?
report[:quantitativeResult] = intMetadataClass.newQuantitativeResult
report[:quantitativeResult][:values] = [ xVertical.xpath('qvertpa/vertaccv').text ]
end
hDataQuality[:report] << report
end
end

Expand All @@ -167,10 +132,7 @@ def self.unpack(xDataQual, hMetadata, hDataQuality, hResponseObj)
hResponseObj[:readerExecutionMessages] << 'WARNING: FGDC reader: data quality lineage section is missing'
end

# data quality 2.6 (cloud) - cloud cover (not implemented)

return hDataQuality

end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ module DataQualityReport

def self.build(hReport)
Jbuilder.new do |json|
json.type hReport[:type]
json.standaloneQualityReportDetails hReport[:standaloneQualityReportDetails]
json.qualityMeasure QualityMeasure.build(hReport[:qualityMeasure]) unless hReport[:qualityMeasure].nil?
json.evaluationMethod EvaluationMethod.build(hReport[:evaluationMethod]) unless hReport[:evaluationMethod].nil? || hReport[:evaluationMethod].empty?
json.quantitativeResult @Namespace.json_map(hReport[:quantitativeResult], QuantitativeResult) unless hReport[:quantitativeResult].nil? || hReport[:quantitativeResult].empty?
json.descriptiveResult @Namespace.json_map(hReport[:descriptiveResult], DescriptiveResult) unless hReport[:descriptiveResult].nil? || hReport[:descriptiveResult].empty?
json.conformanceResult @Namespace.json_map(hReport[:conformanceResult], ConformanceResult) unless hReport[:conformanceResult].nil? || hReport[:conformanceResult].empty?
json.coverageResult @Namespace.json_map(hReport[:coverageResult], CoverageResult) unless hReport[:coverageResult].nil? || hReport[:coverageResult].empty?
json.type hReport[:type] unless hReport[:type].nil?
json.standaloneQualityReportDetails hReport[:standaloneQualityReportDetails] unless hReport[:standaloneQualityReportDetails].nil?
json.qualityMeasure QualityMeasure.build(hReport[:qualityMeasure]) unless hReport[:qualityMeasure].empty?
json.evaluationMethod EvaluationMethod.build(hReport[:evaluationMethod]) unless hReport[:evaluationMethod].empty?
json.quantitativeResult @Namespace.json_map(hReport[:quantitativeResult], QuantitativeResult) unless hReport[:quantitativeResult].empty?
json.descriptiveResult @Namespace.json_map(hReport[:descriptiveResult], DescriptiveResult) unless hReport[:descriptiveResult].empty?
json.conformanceResult @Namespace.json_map(hReport[:conformanceResult], ConformanceResult) unless hReport[:conformanceResult].empty?
json.coverageResult @Namespace.json_map(hReport[:coverageResult], CoverageResult) unless hReport[:coverageResult].empty?
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ module MdJson
module DescriptiveResult
def self.build(hResult)
Jbuilder.new do |json|
json.dateTime hResult[:dateTime]
json.scope Scope.build(hResult[:scope]) unless hResult[:scope].nil?
json.statement hResult[:statement]
json.dateTime hResult[:dateTime] unless hResult[:dateTime].nil?
json.scope Scope.build(hResult[:scope]) unless hResult[:scope].empty?
json.statement hResult[:statement] unless hResult[:statement].nil?
end
end

Expand Down

0 comments on commit 1ff7d59

Please sign in to comment.