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

Aperta
#273 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
api

Direzione di ricerca

Inizia tracciando cwms.get_locations_catalog e cwms.store_location per l’endpoint /locations, quindi confronta le relative mappature di serializzazione e deserializzazione con il CDA JSON mostrato nell’issue. Verifica che l’oggetto posizione restituito dal percorso di recupero possa essere fornito al percorso di memorizzazione, inclusi gli alias, e conferma che il round trip non produca più un errore di serializzazione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
16
Fork
11
Merge medio
7h 35m
PR unite (30g)
3

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di HydrologicEngineeringCenter/cwms-python

Tutte le issue di HydrologicEngineeringCenter/cwms-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.