Skip to content

Commit

Permalink
Initial commit for #31
Browse files Browse the repository at this point in the history
  • Loading branch information
krowvin committed Jul 19, 2024
1 parent c22a0af commit 74c3972
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Keyword | Description |
picture | python format string or time format string, tells the system how to format the value |
misstr | what to display when a value is missing (None) |
undef | what to display when a value is undefined (this isn't implemented yet but was part of the original repgen program, general meaning is the time series you asked for doesn't actually exists the database being used) |
dbtype | copy,gents,spkjson,radar are the current valid values. This tells the system how it should interpret the supplied keywords |
dbtype | copy,gents,spkjson,cda are the current valid values. This tells the system how it should interpret the supplied keywords |

Every time you set a keyword, Value stores the last used value. If a keyword doesn't need to change between values (e.g. they all need to render the same) you don't have to include it when creating the additional values.

Expand Down Expand Up @@ -92,7 +92,7 @@ picture is so that when the report is filled the time format will be used
##### Retrieve Time Series

```python
ts = Value(dbtype="radar",
ts = Value(dbtype="cda",
dbloc="Black Butte-Outflow", dbpar="Stage", dbptyp="Inst", dbint="15Minutes", dbdur="0", dbver="Combined-val",
dbtz="UTC", dbunits="ft", dbofc="SPK" )
```
Expand All @@ -101,7 +101,7 @@ The start and end could also be used, in this example the start and end from the
This allows you to get multiple time series of data by only changing the needed parameters.
for example if we wanted the Stages (height of water in a channel) from several different locations we could to the following:
```python
ts = Value(dbtype="radar",
ts = Value(dbtype="cda",
dbloc="Black Butte-Outflow", dbpar="Stage", dbptyp="Inst", dbint="15Minutes", dbdur="0", dbver="Combined-val",
dbtz="PST8PDT", dbunits="ft", dbofc="SPK"
start=datetime.datetime.now()-datetime.timedelta(hours=4)
Expand Down Expand Up @@ -181,7 +181,7 @@ YRS = Value(50,
PICTURE="%2.0f",
)
ts1 = Value(
dbtype="radar",
dbtype="cda",
DBLOC="Black Butte-Pool", DBPAR="Stor", DBPTYP="Inst", DBINT="~1Day", DBDUR=0, DBVER="Calc-val",
DBUNITS="ac-ft",
DBTZ="PST8PDT",
Expand Down
2 changes: 1 addition & 1 deletion __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def parseArgs():
parser.add_argument( '-z', '--tz', dest='tz', default=_z, help="default timezone; equivalent to `TZ=timezone`", metavar='Time Zone Name')
parser.add_argument( '-O', '--office', dest='office', default=None, help="default office to use if not specified in report; equivalent to `DBOFC=OFFICE_ID`", metavar='OFFICE_ID')
parser.add_argument( '-a', '--address', dest='host', default='localhost', help="location for data connections; equivalent to `DB=hostname:port/path`", metavar='IP_or_hostname:port[/basepath]')
parser.add_argument( '-A', '--alternate', dest='alternate', default=None, help="alternate location for data connections, if the primary is unavailable (only for RADAR)", metavar='IP_or_hostname:port[/basepath]')
parser.add_argument( '-A', '--alternate', dest='alternate', default=None, help="alternate location for data connections, if the primary is unavailable (only for CDA)", metavar='IP_or_hostname:port[/basepath]')
parser.add_argument( '-c', '--compatibility', dest='compat', action="store_true", default=False, help="repgen4 compatibility; case-insensitive labels")
parser.add_argument( '--timeout', dest='timeout', type=float, default=None, help="Socket timeout, in seconds" )
# This provides repgen4 style KEY=VALUE argument passing on the command-line
Expand Down
6 changes: 3 additions & 3 deletions converter/convert_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -987,12 +987,12 @@ def cleanup(indent=False):
if key == "DB":
if value == "%DB":
key = "dbtype"
value = '"radar"'
error(f"WARNING: Oracle connectivity is not supported. Use dbtype='radar' with RADAR.")
value = '"cda"'
error(f"WARNING: Oracle connectivity is not supported. Use dbtype='cda' with CDA.")
elif value.lower() == "local":
error(f"WARNING: LOCAL DB connectivity is not supported.")
else:
error(f"WARNING: DB option unsupported. Use dbtype='radar' with RADAR.")
error(f"WARNING: DB option unsupported. Use dbtype='cda' with CDA.")
elif key == "TYPE":
key = "dbtype"

Expand Down
12 changes: 9 additions & 3 deletions repgen/data/value.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ def processDateTime(value, key, extra_part=None):

if self.dbtype is None:
raise ValueError("you must enter a scalar quantity if you aren't specifying a data source")
# TODO: Remove this at some point?
# Conversion with a warning to change the dbtype from radar to CDA for rebrand
elif self.dbtype.upper() == "radar":
print("\n\tWARNING: Update from dbtype=\"RADAR\" to dbtype=\"CDA\"")
self.dbtype = "CDA"
elif self.dbtype.upper() == "FILE":
pass
elif self.dbtype.upper() == "COPY":
Expand Down Expand Up @@ -395,7 +400,7 @@ def parse_slice(value):
self.value = self.values[0][1]
except Exception as err:
print( repr(err) + " : " + str(err), file=sys.stderr )
elif self.dbtype.upper() in ["JSON", "RADAR"]:
elif self.dbtype.upper() in ["JSON", "CDA"]:
import json, http.client as httplib, urllib.parse as urllib

#fmt = "%d-%b-%Y %H%M"
Expand Down Expand Up @@ -500,7 +505,7 @@ def parse_slice(value):
if r1.status == 404:
json.loads(data)
# We don't care about the actual error, just if it's valid JSON
# Valid JSON means it was a RADAR response, so we treat it as a valid response, and won't retry.
# Valid JSON means it was a CDA response, so we treat it as a valid response, and won't retry.
break
except (httplib.NotConnected, httplib.ImproperConnectionState, httplib.BadStatusLine, ValueError, OSError) as e:
print(f"Error fetching: {e}", file=sys.stderr)
Expand Down Expand Up @@ -571,9 +576,10 @@ def parse_slice(value):
print( repr(err) + " : " + str(err), file=sys.stderr )

break

elif self.dbtype.upper() == "DSS":
raise Exception("DSS retrieval is not currently implemented")
else:
raise Exception(f"\n\n\t{self.dbtype.upper()} is not supported!\n\tAvailable options are:\n\t\t {', '.join(self.DB_OPTIONS)}\n")

# math functions
def __add__( self, other ):
Expand Down
2 changes: 1 addition & 1 deletion repgen/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def filterAddress(address):
host = parts[0]
query = parts[1] if len(parts) > 1 else None
elif host.count(':') > 1:
raise ValueError(f"Oracle DB '{host}' is not supported. Use RADAR.")
raise ValueError(f"Oracle DB '{host}' is not supported. Use CDA.")

# Check if port was specified, and add one if not
if ':' not in host:
Expand Down

0 comments on commit 74c3972

Please sign in to comment.