SolarArbiter / solarforecastarbiter-core

Core data gathering, validation, processing, and reporting package for the Solar Forecast Arbiter
https://solarforecastarbiter-core.readthedocs.io
MIT License
33 stars 21 forks source link

Add cli command for data copy from observation to observation #747

Open lboeman opened 2 years ago

lboeman commented 2 years ago

Initially thought that having a cli tool for copying data from one observation to another would be helpful for https://github.com/SolarArbiter/solarforecastarbiter-api/pull/324 but determined that the API cli was not a great fit. This boils down to mostly ensuring permissions are correct and using the script below, but it could be helpful to have a cli command so that it could be tested and repeatable. Below is part of the PR discussion and a loose example of the needed code to perform the action as a reference.

lboeman commented 2 years ago

I'm going to walk back adding an additional helper for backfilling data here. It seems like something that should be added to core's solararbiter cli if really needed at all. Because the admin cli works with scheduled jobs, and this would be a one-off command where the overhead of storing refresh tokens and such would make it more complicated than it needs to be. A script to do the cloning would be something like:

from solarforecastarbiter.io import APISession, request_cli_access_token

copy_from = <uuid>
copy_to = <uuid>
token = request_cli_access_token(<username>, <password>)
session = APISession(token)

values = session.get_observation_values(copy_from, <start>, <end>)
values['quality_flag'] = values['quality_flag'] & 1 # maintain user flagged 
session.post_observation_values(copy_to, values)

If that's something that would be good to have as a cli command I can make a core PR. I think this one should be ready for a review.

Originally posted by @lboeman in https://github.com/SolarArbiter/solarforecastarbiter-api/issues/324#issuecomment-956827781