Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run latest formatting to fix CI #277

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
black = "*"

[packages]
geopy = "==1.20.0"
Expand Down
254 changes: 175 additions & 79 deletions Pipfile.lock

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions powersimdata/data_access/csv_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class CsvStore:
"""

def __init__(self, ssh_client):
"""Constructor

"""
"""Constructor"""
self.ssh_client = ssh_client

def get_table(self, filename, path_on_server):
Expand Down
15 changes: 9 additions & 6 deletions powersimdata/data_access/execute_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@


class ExecuteTable(SqlStore):
"""Storage abstraction for execute list using sql database.
"""
"""Storage abstraction for execute list using sql database."""

table = "execute_list"
columns = ["id", "status"]
Expand Down Expand Up @@ -38,7 +37,13 @@ def add_entry(self, scenario_info):
"""
scenario_id, status = scenario_info["id"], "created"
sql = self.insert()
self.cur.execute(sql, (scenario_id, status,))
self.cur.execute(
sql,
(
scenario_id,
status,
),
)

def update_execute_list(self, status, scenario_info):
"""Updates status of scenario in execute list
Expand Down Expand Up @@ -67,9 +72,7 @@ class ExecuteListManager(CsvStore):
"""

def __init__(self, ssh_client):
"""Constructor

"""
"""Constructor"""
super().__init__(ssh_client)

def get_execute_table(self):
Expand Down
25 changes: 11 additions & 14 deletions powersimdata/data_access/scenario_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


class ScenarioTable(SqlStore):
"""Storage abstraction for scenario list using sql database.
"""
"""Storage abstraction for scenario list using sql database."""

table = "scenario_list"
columns = [
Expand Down Expand Up @@ -76,9 +75,7 @@ class ScenarioListManager(CsvStore):
"""

def __init__(self, ssh_client):
"""Constructor

"""
"""Constructor"""
super().__init__(ssh_client)

def get_scenario_table(self):
Expand All @@ -95,16 +92,13 @@ def generate_scenario_id(self):
:return: (*str*) -- new scenario id.
"""
print("--> Generating scenario id")
command = (
"(flock -e 200; \
command = "(flock -e 200; \
id=$(awk -F',' 'END{print $1+1}' %s); \
echo $id, >> %s; \
echo $id) 200>%s"
% (
server_setup.SCENARIO_LIST,
server_setup.SCENARIO_LIST,
posixpath.join(server_setup.DATA_ROOT_DIR, "scenario.lockfile"),
)
echo $id) 200>%s" % (
server_setup.SCENARIO_LIST,
server_setup.SCENARIO_LIST,
posixpath.join(server_setup.DATA_ROOT_DIR, "scenario.lockfile"),
)

err_message = "Failed to generate id for new scenario"
Expand All @@ -123,7 +117,10 @@ def add_entry(self, scenario_info):
# AWK parses the file line-by-line. When the entry of the first column is
# equal to the scenario identification number, the entire line is replaced
# by the scenaario information.
program = "'{if($1==%s) $0=\"%s\"};1'" % (scenario_info["id"], entry,)
program = "'{if($1==%s) $0=\"%s\"};1'" % (
scenario_info["id"],
entry,
)
command = "awk %s %s %s" % (options, program, server_setup.SCENARIO_LIST)

err_message = "Failed to add entry in %s on server" % server_setup.SCENARIO_LIST
Expand Down
11 changes: 5 additions & 6 deletions powersimdata/data_access/sql_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class LoggingCursor(psycopg2.extras.DictCursor):
"""Cursor that prints queries before execution. Primarily used for debugging"""

def execute(self, sql, args=None):
"""Print sql query and delegate execution to super.
"""
"""Print sql query and delegate execution to super."""
print(self.mogrify(sql, args))

try:
Expand All @@ -28,7 +27,7 @@ def execute(self, sql, args=None):


def get_connection():
""" Temporary connection used for local development
"""Temporary connection used for local development
:return: (*str*) -- connection string for postgres db
"""
return "dbname=psd host=localhost user=postgres password=example"
Expand Down Expand Up @@ -60,7 +59,7 @@ class SqlStore:
"""Base class for objects stored in a postgres db. Implements context
manager for connection handling and methods for generating queries based on
convention. Derived classes should define table and columns attributes for
this to work properly.
this to work properly.
"""

def __init__(self):
Expand Down Expand Up @@ -105,7 +104,7 @@ def select_where(self, key):
return self.select_all() + where_clause

def insert(self, subset=None):
""" Build INSERT statement on current table for all columns, or subset if
"""Build INSERT statement on current table for all columns, or subset if
specified.
:param iterable subset: collection of columns to specify in query
:return (*psycopg2.sql.SQL*) -- template for insert statement
Expand All @@ -118,7 +117,7 @@ def insert(self, subset=None):
)

def delete(self, key):
""" Build DELETE .. WHERE statement on current table using key to filter.
"""Build DELETE .. WHERE statement on current table using key to filter.
:param str key: column to use in WHERE clause
:return (*psycopg2.sql.SQL*) -- template for delete statement
"""
Expand Down
29 changes: 8 additions & 21 deletions powersimdata/design/clean_capacity_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,7 @@ def create_change_table(self, ref_scenario):


class IndependentStrategyManager(AbstractStrategyManager):
"""Calculates the next capacities using individual target shortfalls.

"""
"""Calculates the next capacities using individual target shortfalls."""

def __init__(self):
AbstractStrategyManager.__init__(self)
Expand Down Expand Up @@ -793,8 +791,7 @@ def data_frame_of_next_capacities(self):


class AbstractCollaborativeStrategyManager(AbstractStrategyManager):
"""Base class for Collaborative strategy objects, contains common functions.
"""
"""Base class for Collaborative strategy objects, contains common functions."""

def __init__(self):
raise NotImplementedError("Only child classes should be instantiated")
Expand Down Expand Up @@ -913,8 +910,7 @@ def data_frame_of_next_capacities(self):


class CollaborativeStrategyManager(AbstractCollaborativeStrategyManager):
"""Calculates the next capacities using total target shortfalls.
"""
"""Calculates the next capacities using total target shortfalls."""

def __init__(self):
self.addl_curtailment = {"solar": 0, "wind": 0}
Expand All @@ -934,8 +930,7 @@ def calculate_total_shortfall(self):
return total_ce_shortfall

def calculate_participating_capacity(self, category):
"""Calculates capacity for a resource, in participating states.
"""
"""Calculates capacity for a resource, in participating states."""
participating_capacity = sum(
[
self.targets[tar].resources[category].prev_capacity
Expand Down Expand Up @@ -1352,9 +1347,7 @@ def set_allowed_resources(self, allowed_resources):
self.allowed_resources = allowed_resources

def save_target_as_json(self):
"""Saves target object as indented JSON file named by region name.

"""
"""Saves target object as indented JSON file named by region name."""
print(os.getcwd())
json_file = open(
os.path.join(
Expand All @@ -1373,9 +1366,7 @@ def save_target_as_json(self):
json_file.close()

def save_target_as_pickle(self):
"""Saves target object as pickle file named by region name.

"""
"""Saves target object as pickle file named by region name."""
print(os.getcwd())
json_file = open(
os.path.join(
Expand Down Expand Up @@ -1403,14 +1394,10 @@ def __str__(self):


class ResourceManager:
"""Manages the creation of resource objects from scenario information.

"""
"""Manages the creation of resource objects from scenario information."""

def __init__(self):
"""Creates an empty dictionary to hold resource objects.

"""
"""Creates an empty dictionary to hold resource objects."""
self.resources = {}

def __getitem__(self, key):
Expand Down
2 changes: 1 addition & 1 deletion powersimdata/design/tests/test_clean_capacity_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_independent_new_capacity():
"geo": [0, 0, 0, 0],
"hydro": [0, 0, 0, 0],
"solar": [0.4, 0, 0, 0],
"wind": [0, 0, 0, 0,],
"wind": [0, 0, 0, 0],
},
index=area_names,
)
Expand Down
12 changes: 10 additions & 2 deletions powersimdata/design/tests/test_transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ def setUp(self):

# Finally, combine all of this into a MockScenario
self.mock_scenario = MockScenario(
grid_attrs={"branch": mock_branch, "bus": mock_bus, "plant": mock_plant,},
grid_attrs={
"branch": mock_branch,
"bus": mock_bus,
"plant": mock_plant,
},
congu=congu,
congl=congl,
ct=ct,
Expand Down Expand Up @@ -382,7 +386,11 @@ def setUp(self):
"wind": {"zone_id": {"E": 1.3, "W": 2.1}},
}
self.ref_scenario = MockScenario(
grid_attrs={"branch": mock_branch, "bus": mock_bus, "plant": mock_plant,},
grid_attrs={
"branch": mock_branch,
"bus": mock_bus,
"plant": mock_plant,
},
ct={
"branch": {"branch_id": {101: 1.5, 102: 2.5, 103: 2, 105: 4}},
# These shouldn't get used
Expand Down
4 changes: 2 additions & 2 deletions powersimdata/design/transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def scale_congested_mesh_branches(
):
"""Use a reference scenario as a baseline for branch scaling, and further
increment branch scaling based on observed congestion duals.

:param powersimdata.input.change_table.ChangeTable change_table: the
change table instance we are operating on.
:param powersimdata.scenario.scenario.Scenario ref_scenario: the reference
Expand Down Expand Up @@ -367,7 +367,7 @@ def _construct_composite_allow_list(valid_branches, allow_list, deny_list):
def _increment_branch_scaling(change_table, branch_ids, ref_scenario, value=1):
"""Modify the ct dict of a ChangeTable object based on branch scaling from
both a reference scenario and a set of branches to increment by a value.

:param powersimdata.input.change_table.ChangeTable change_table: the
change table instance we are operating on.
:param [list/set/tuple] branch_ids: an iterable of branch indices.
Expand Down
8 changes: 2 additions & 6 deletions powersimdata/input/abstract_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@


class AbstractGrid(object):
"""Grid Builder.

"""
"""Grid Builder."""

def __init__(self):
"""Constructor

"""
"""Constructor"""
self.data_loc = None
self.interconnect = None
self.zone2id = {}
Expand Down
Loading