HydrologicEngineeringCenter / cwms-python

Corps Water Management Systems (CWMS) library utilizing CWMS Data API
MIT License
6 stars 4 forks source link

Add location_df_to_json function #95

Open msweier opened 3 weeks ago

msweier commented 3 weeks ago

This would help bulk management of locations by allowing one to do edits of subsetted location data in a panadas dataframe and then store into the database. It appears you have to manually convert the dataframe into json for a store.

Enovotny commented 2 weeks ago

@msweier for things like this where it is a direct 1 to 1 for the df to json we can use standard pandas functions. for example from json import loads, dumps loads(df.to_json(orient="records"))[0]

now maybe it makes sense to put that in as a function, but since it is really only one line I'm not sure if it is needed.

The functions are for things like timeseries where the df is only a subset of the json that is obtained from CDA. the df only includes the values. So in this case we could not use the standard pandas function to go back to json.

msweier commented 2 weeks ago

@Enovotny loads(df.to_json(orient="records" should probably do the trick. I didn't know that was the way to do it.

I suppose it would be more like location_cat_to_df. I'm thinking for editing metadata for multiple locations in a dataframe (e.g. elevation, state, timezone, etc...) using get_locations_catalog, turning that into a dataframe, subseting data, and storing back. Mainly to clean up data and manage project locations and sublocations. CMA is going away and CWMS-VUE has issues and lags behind with features. Maybe there's a better way to do what I'm trying to do.

image