Skip to content

Commit ae7b108

Browse files
authored
Merge pull request #94 from staadecker/save_scenario
Add script to save new scenarios to the database
2 parents 95023e6 + 332f587 commit ae7b108

File tree

7 files changed

+240
-171
lines changed

7 files changed

+240
-171
lines changed

docs/Database.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ The command to enter PostgreSQL while SSH'd into the server is `psql wecc`.
4141

4242
## Making changes to the database
4343

44-
Whether it's adding data to the database or changing its schema, it's important
45-
to proceed carefully when making changes to the database. Always make sure to
44+
### Common operations
45+
46+
Some database changes are common operations that are used repeatedly.
47+
For these operations, it's helpful to make a command line tool to make the process easy.
48+
49+
For example, adding a scenario to the database is a common operation. Therefore, we have built
50+
the `switch db save_scenario` command to easily do this. (Run `switch db save_scenario --help` for details).
51+
52+
### Custom operations
53+
54+
When running custom operations on the database it's very important
55+
to proceed carefully. Always make sure to
4656
**test and keep track of your changes**.
4757

4858
Here are the steps to make a change.
@@ -61,9 +71,7 @@ to the convention `YYYY-MM-DD_<script_name>`.
6171
5. Open a pull request to add your script to the repository (see [`docs/Contribute.md`](Contribute.md))
6272
so we can keep track of the changes that have been made.
6373

64-
### Bigger changes
65-
66-
Sometimes, it isn't feasible to have your entire change as a single SQL script.
74+
Note that sometimes, it isn't feasible to have your entire change as a single SQL script.
6775
One way to make bigger changes is to use a Python script. Use the same process
6876
as for the SQL scripts. That is save your Python scripts in the `/database` folder.
6977

switch_model/tools/templates/config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ get_inputs:
2121
# the following parameters are optional and will override the defaults for that scenario
2222
# this should only be used for preliminary exploration of scenarios or for testing
2323
# if a scenario is part of research, it should be included in the database as a row in the scenarios table.
24+
#
25+
# -1 is equivalent to null
2426
# study_timeframe_id:
2527
# time_sample_id:
2628
# demand_scenario_id:

switch_model/wecc/__main__.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,22 @@
55
from __future__ import print_function
66

77
import argparse
8+
import importlib
89
import sys
9-
import switch_model.wecc.sampling.cli as sample
10+
11+
def get_module_runner(module):
12+
def runner():
13+
importlib.import_module(module).main()
14+
return runner
1015

1116

1217
cmds = {
13-
"sample": sample.main,
18+
"sample": get_module_runner("switch_model.wecc.sampling.cli"),
19+
"save_scenario": get_module_runner("switch_model.wecc.save_scenario"),
1420
}
1521

16-
1722
def main(args=None):
18-
parser = argparse.ArgumentParser()
23+
parser = argparse.ArgumentParser(add_help=False)
1924
parser.add_argument("subcommand", choices=cmds.keys(), help="The possible switch subcommands")
2025

2126
args, remaining_args = parser.parse_known_args(args)

0 commit comments

Comments
 (0)