Open Contracting Data Standard (OCDS) 的数据审查库
项目描述
命令行
调用 libcoveocds 并传递某些JSON数据的文件名。
libcoveocds tests/fixtures/common_checks/basic_1.json
它将生成标准输出结果的JSON数据。您可以直接将其导入文件中工作。
您还可以传递 --schema-version 1.X 来强制它检查某个版本的架构。
在某些模式下,它还会留下数据目录。以下选项适用于此模式
传递 --convert 来生成数据的工作表。
传递 --output-dir output 来指定目录名(默认基于文件名)。
传递 --delete 来删除已存在的输出目录(默认为错误)
传递 --exclude-file 来避免将原始文件复制到输出目录(默认为复制)
(如果没有指定这些,它将不会留下任何文件)
库
要将此作为Python脚本的一部分用作Python库以验证多个文件或进行测试,您需要
使用pip安装库
pip install libcoveocds
如果在一个Web环境中使用库,安装方式如下
pip install libcoveocds[web]
在您的Python代码中使用它,例如
import os import shutil import tempfile from libcoveocds.api import ocds_json_output data_directory = "path/to/your/directory/with/json/files" temporary_directory = tempfile.mkdtemp(dir=tempfile.gettempdir()) for filename in os.listdir(data_directory): path = os.path.join(data_directory, filename) try: result = ocds_json_output(temporary_directory, path, file_type="json") finally: shutil.rmtree(temporary_directory) # Do something with the result. For example: if result["validation_errors"]: for error in result["validation_errors"]: print(f"Validation error {error} found in {path}") else: print(f"No validation errors found for {path}")
供外部用户使用的代码
应该直接由用户使用的唯一代码是 libcoveocds.config 和 libcoveocds.api 模块。
其他代码(在 libcore、lib 等)不应直接由该库的外部用户使用,因为这些的结构和使用可能更频繁地发生变化。
输出JSON格式
输出是一个具有以下属性的对象
属性(键)名称 |
类型 |
值 |
---|---|---|
file_type |
字符串 |
提供的文件类型,之一 json、csv、xlsx 或 ods |
version_used |
字符串 |
使用的OCDS架构版本,例如 1.1(如果不存在版本字段,则为 1.0) |
schema_url |
字符串 |
使用的包架构的URL,例如 https://standard.open-contracting.org/1.1/en/release-package-schema.json |
extensions |
对象 |
一个 extensions 对象 |
validation_errors |
数组[对象] |
一个包含 validation_errors 对象的数组 |
common_error_types |
数组[] |
始终为空数组 |
deprecated_fields |
数组[对象] |
一个包含 deprecated_fields 对象的数组 |
releases_aggregates |
对象 |
一个 releases_aggregates 对象 |
records_aggregates |
对象 |
一个 records_aggregates 对象 |
additional_closed_codelist_values |
对象 |
从codelist字段的JSON Pointer(删除数组索引,例如 releases/tender/documents/documentType)到一个 additional codelist object 的映射 |
additional_open_codelist_values |
对象 |
从codelist字段的JSON Pointer(删除数组索引,例如 releases/tender/documents/documentType)到一个 additional codelist object 的映射 |
additional_checks |
对象 |
从附加检查类型(目前只有 empty_field)到一个包含 additional check objects 的数组的映射 |
conformance_errors |
对象 |
一个 conformance_errors 对象 |
additional_fields |
数组[对象] |
顶层附加字段,作为 additional_fields 对象的数组 |
all_additional_fields |
数组[对象] |
所有附加字段,包括其他附加字段的子字段,作为一个包含 all_additional_fields 对象的数组 |
json_deref_error |
字符串 |
未解决引用的异常消息(如果有抛出) |
注意,在所有使用架构的地方,都是扩展架构(如果存在扩展)。
extensions
属性(键)名称 |
类型 |
值 |
---|---|---|
extensions |
数组[对象] |
一个 extensions/extensions 对象 |
无效的扩展 |
array[array[string]] |
一个包含扩展URL和可读错误消息的元组数组,例如[["http://etc", "404: not found"]] |
扩展模式URL |
字符串 |
将扩展模式写入的文件,如果已设置输出目录,例如extended_schema.json |
is_extended_schema |
布尔型 |
是否已经扩展了模式? |
extensions/extensions
属性(键)名称 |
类型 |
值 |
---|---|---|
url |
字符串 |
扩展元数据文件的URL,例如https://raw.githubusercontent.com/open-contracting-extensions/ocds_metrics_extension/master/extension.json |
schema_url |
字符串 |
扩展发布模式文件的URL,例如https://raw.githubusercontent.com/open-contracting-extensions/ocds_metrics_extension/master/release-schema.json |
description |
字符串 |
从元数据文件中提取 |
name |
字符串 |
从元数据文件中提取 |
documentationUrl |
字符串 |
从元数据文件中提取 |
failed_codelists |
对象 |
从扩展codelist名称(如果适用,前面有+或 -)到可读错误消息的映射 |
codelists |
array[string] |
从元数据文件中提取 |
validation_errors
注意,此列表将排除codelist错误,这些错误将在additional_closed_codelist_values中出现。
lib-cove-ocds使用jsonschema模块的uniqueItems验证器来检查唯一的OCIDs和ID。
属性(键)名称 |
类型 |
值 |
---|---|---|
type |
字符串 |
引起验证错误的JSON模式关键字,例如minLength(在jsonschema库中的完整列表),除非关键字是type或format,在这种情况下,这是相关的type或format,例如array或date-time |
field |
字符串 |
有误数据的JSON Pointer,数组索引已移除,例如releases/tender/items |
description |
字符串 |
一个可读的错误消息,例如'id' is missing but required within 'items' |
path |
字符串 |
有误数据的JSON Pointer,例如releases/0/tender/items/0 |
value |
any |
数据中的错误值,如果不适用则为"" |
deprecated_fields
属性(键)名称 |
类型 |
值 |
---|---|---|
paths |
array[string] |
包含已弃用字段的父对象的JSON Pointers数组,例如["releases/0/tender"] |
explanation |
array[string] |
字段被弃用的版本和可读弃用消息的配对,例如["1.1", "Some explanation text"] |
field |
字符串 |
父对象中弃用字段的名称,例如amendment |
releases_aggregates
属性(键)名称 |
类型 |
值 |
---|---|---|
release_count |
integer |
releases数组中的项目数 |
unique_ocids |
array* |
所有ocids的数组,去重 |
unique_initation_type |
array* |
|
duplicate_release_ids |
array* |
这是一个OCDS实现错误。 |
tags |
对象 |
|
unique_lang |
array* |
|
unique_award_id |
array* |
|
planning_count |
integer |
|
tender_count |
integer |
|
award_count |
integer |
|
processes_award_count |
integer |
|
contract_count |
integer |
|
processes_contract_count |
integer |
|
implementation_count |
integer |
|
processes_implementation_count |
integer |
|
min_release_date |
string (date-time or “”) |
|
max_release_date |
string (date-time or “”) |
|
min_tender_date |
string (date-time or “”) |
|
max_tender_date |
string (date-time or “”) |
|
min_award_date |
string (date-time or “”) |
|
max_award_date |
string (date-time or “”) |
|
min_contract_date |
string (date-time or “”) |
|
max_contract_date |
string (date-time or “”) |
|
unique_buyers_identifier |
对象 |
从标识符到名称的映射 |
unique_buyers_name_no_id |
array* |
|
unique_suppliers_identifier |
对象 |
从标识符到名称的映射 |
unique_suppliers_name_no_id |
array* |
|
unique_procuring_identifier |
对象 |
从标识符到名称的映射 |
unique_procuring_name_no_id |
array* |
|
unique_tenderers_identifier |
对象 |
从标识符到名称的映射 |
unique_tenderers_name_no_id |
array* |
|
unique_buyers |
array[string] |
一个组织名称数组,如果存在则括号中包含标识符 |
unique_suppliers |
array[string] |
一个组织名称数组,如果存在则括号中包含标识符 |
unique_procuring |
array[string] |
一个组织名称数组,如果存在则括号中包含标识符 |
unique_tenderers |
array[string] |
一个组织名称数组,如果存在则括号中包含标识符 |
unique_buyers_count |
integer |
|
unique_suppliers_count |
integer |
|
独特采购次数 |
integer |
|
独特投标人次数 |
integer |
|
独特组织标识符次数 |
integer |
|
独特组织名称次数 |
integer |
|
独特组织次数 |
integer |
|
独特组织方案 |
array* |
|
有地址的组织 |
integer |
|
有联系点的组织 |
integer |
|
总项目次数 |
integer |
以下3个项目次数之和 |
投标项目次数 |
integer |
|
授予项目次数 |
integer |
|
合同项目次数 |
integer |
|
独特项目ID次数 |
integer |
|
项目标识符方案 |
array* |
|
独特货币 |
array* |
|
规划文件次数 |
integer |
|
投标文件次数 |
integer |
|
投标里程碑文件次数 |
integer |
|
授予文件次数 |
integer |
|
合同文件次数 |
integer |
|
实施文件次数 |
integer |
|
实施里程碑文件次数 |
integer |
|
规划文档类型 |
对象 |
从 documentType 到出现次数的映射 |
投标文档类型 |
对象 |
从 documentType 到出现次数的映射 |
投标里程碑文档类型 |
对象 |
从 documentType 到出现次数的映射 |
授予文档类型 |
对象 |
从 documentType 到出现次数的映射 |
合同文档类型 |
对象 |
从 documentType 到出现次数的映射 |
实施文档类型 |
对象 |
从 documentType 到出现次数的映射 |
实施里程碑文档类型 |
对象 |
从 documentType 到出现次数的映射 |
未授予合同的合同 |
数组 |
一个不包含授予的合同对象的数组。 这是一个OCDS实现错误。 |
records_aggregates
属性(键)名称 |
类型 |
值 |
---|---|---|
计数 |
integer |
记录数组中的项目数 |
unique_ocids |
array* |
所有ocids的数组,去重 |
附加代码表对象
属性(键)名称 |
类型 |
值 |
---|---|---|
path |
字符串 |
指向父对象的JSON Pointer,移除了数组索引,例如 releases/tender/documents |
field |
字符串 |
代码表字段名称,例如 documentType |
代码表 |
字符串 |
代码表的文件名,例如 documentType.csv |
代码表_URL |
字符串 |
代码表的URL,例如 https://raw.githubusercontent.com/open-contracting/standard/1.1/schema/codelists/documentType.csv |
代码表修订_URLs |
数组[数组[string] |
修改代码表的扩展中的代码表补丁的URL,作为一个包含“+”或“-”和URL的数组对,例如 [["+", "https://raw.githubusercontent.com/open-contracting-extensions/ocds_tariffs_extension/d9df2969030b0a555c24c7db685262c714b4da24/codelists/+documentType.csv"]] |
isopen |
布尔型 |
这是一个开放代码表吗? |
values |
array* |
不在代码表中的字段值 |
extension_codelist |
布尔型 |
这是由扩展添加的代码表吗?(不仅仅是被修改) |
附加检查对象
属性(键)名称 |
类型 |
值 |
---|---|---|
json_location |
字符串 |
指向问题数据的JSON Pointer,例如 releases/0/buyer |
conformance_errors
属性(键)名称 |
类型 |
值 |
---|---|---|
ocds_prefixes_bad_format |
array[array[string]] |
一个包含坏 ocid 值及其JSON Pointer的数组对,例如 ["MY-ID", "releases/0/ocid"] |
ocid_description |
字符串 |
OCDS模式中 ocid 字段的描述 |
ocid_info_url |
字符串 |
指向OCDS文档中标识符内容的URL |
additional_fields
属性(键)名称 |
类型 |
值 |
---|---|---|
path |
字符串 |
移除数组索引的父对象JSON Pointer,例如 /releases/tender |
field |
字符串 |
附加字段名称,例如 myField |
usage_count |
integer |
附加字段被设置的次数 |
all_additional_fields
属性(键)名称 |
类型 |
值 |
---|---|---|
计数 |
integer |
附加字段被设置的次数 |
examples |
array* |
该字段最多3个值的样本 |
root_additional_field |
布尔型 |
父对象是否由模式描述? |
additional_field_descendance |
对象 |
此字段的子字段。只有当 root_additional_field 为true时才设置。它是一个从附加字段的JSON Pointer(移除了数组索引)到 all_additional_fields 对象的映射,在该对象中 root_additional_field 为false |
path |
字符串 |
移除数组索引的父对象JSON Pointer,例如 /releases/tender |
field_name |
字符串 |
附加字段名称,例如 myField |
array*
带有星号的数组从数据中的字段填充,因此可能是任何类型(如果数据不符合模式)。
贡献
lib-cove-ocds是从[cove](https://github.com/OpenDataServices/cove/tree/fa4441b9413324a740b8dc063ffbf0256a353c55)提取的。