JSON data from fetch can't be directly used to store again

未关闭
#273 6 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
python
领域
api

调研方向

首先跟踪 /locations 端点对应的 cwms.get_locations_catalog 和 cwms.store_location,然后将它们的序列化和反序列化映射与 issue 中显示的 CDA JSON 进行比较。验证 fetch 路径返回的 location 对象可以提供给 store 路径,包括 aliases,并确认往返过程不再产生序列化错误。

由索引模型根据 Issue 内容生成。

描述

At least for the /locations endpoint, the json data from the fetch result can't be passed again into the appropriate store endpoint. CDA reports a serialization error.

Purpose:
I need to load all the locations from our production instance into cwbi-dev, so I wanted to use cwms-python to dump all the locations and insert them into cwbi.

Here's the script I used:

import os
import cwms

CWBI_API_KEY="apikey"
CWBI_API_ROOT="https://water.dev.cwbi.us/cwms-data"

cwms.api.init_session(api_root=os.environ.get("CDA_APT_ROOT", None), api_key=os.environ.get("CDA_APT_KEY", None))
locations = cwms.get_locations_catalog(office_id='SPK', unit_system='EN')

cwms.api.init_session(api_root=CWBI_API_ROOT, api_key=CWBI_API_KEY)

for location in locations.json['entries']:
	print(location)
	cwms.store_location(data=location, fail_if_exists=False)

The JSON has different key names than CDA returns, or expects in the POST.
For example:
office-id -> office
timezone-name -> time-zone

and many more.

Expectation:
I would expect the JSON data from the get_ method to match what CDA would return, especially since I have to supply JSON data to the relevant store_ methods in cwms-python.

Additional info:
Here's the JSON returned by CDA:

{
    "office-id": "SPK",
    "name": "Truckee R-Vista",
    "latitude": 0,
    "longitude": 0,
    "active": true,
    "public-name": "Truckee River At Vista, NV",
    "timezone-name": "US/Pacific",
    "location-kind": "SITE",
    "nation": "US",
    "state-initial": "NV",
    "county-name": "Washoe",
    "nearest-city": "Sparks",
    "horizontal-datum": "NAD27",
    "published-longitude": 119.7,
    "published-latitude": 39.520555555556,
    "vertical-datum": "NAVD88",
    "elevation": 0,
    "bounding-office-id": "UNK",
    "elevation-units": "ft"
}

Here's the JSON returned by cwms-python:

{
	"office": "SPK",
	"name": "Truckee R-Vista",
	"nearest-city": "Sparks",
	"public-name": "Truckee River At Vista, NV",
	"kind": "SITE",
	"time-zone": "US/Pacific",
	"latitude": 0.0,
	"longitude": 0.0,
	"published-latitude": 39.520555555556,
	"published-longitude": 119.7,
	"horizontal-datum": "NAD27",
	"elevation": 0.0,
	"unit": "ft",
	"vertical-datum": "NAVD88",
	"nation": "United States",
	"state": "NV",
	"county": "Washoe",
	"bounding-office": "UNK",
	"active": true,
	"aliases": [
		{"name": "Agency Aliases-USGS Station Name", "value": "Truckee River At Vista, NV"},
		{"name": "Agency Aliases-USGS Station Number", "value": "10350000"}
	]
}

The "aliases" key is acceptable for storing data, so I'm not sure why it doesn't show up on CDA when fetching via swagger.

主要语言
Python
星标
16
派生
11
平均合并
7 小时 35 分钟
30 天内合并 PR
3

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

HydrologicEngineeringCenter/cwms-python 的其他 Issue

查看 HydrologicEngineeringCenter/cwms-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。