-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated scenario generation package to allow for multiple sizes of DE…
…Rs with probabilities
- Loading branch information
EC2 Default User
committed
Sep 24, 2023
1 parent
88425d1
commit 8837b14
Showing
22 changed files
with
337 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" This module implements commad line interface for exporting | ||
schemas and handling opt in vscode update.""" | ||
|
||
# standard imports | ||
from pathlib import Path | ||
from typing import List | ||
|
||
# third-party imports | ||
import click | ||
from pydantic import BaseModel | ||
import pydantic | ||
|
||
# internal imports | ||
from emerge.scenarios import data_model | ||
from emerge.utils import util | ||
|
||
class SchemaItemModel(BaseModel): | ||
name: str | ||
model: pydantic._internal._model_construction.ModelMetaclass | ||
|
||
class Config: | ||
arbitrary_types_allowed=True | ||
|
||
class SchemaManager: | ||
def __init__(self, schema_folder: str =".vscode"): | ||
self.schema_folder = Path(schema_folder) | ||
self.schemas: List[SchemaItemModel] = [] | ||
|
||
def add_schema(self, name: str, model: BaseModel): | ||
self.schemas.append(SchemaItemModel(name=name, model=model)) | ||
|
||
def generate_and_save_schemas(self): | ||
|
||
if not self.schema_folder.exists(): | ||
self.schema_folder.mkdir() | ||
|
||
for schema in self.schemas: | ||
json_schema = schema.model.model_json_schema() | ||
schema_file = self.schema_folder / f"{schema.name}.json" | ||
util.write_file(json_schema, schema_file) | ||
|
||
def configure_vscode_settings(self): | ||
vscode_settings_file = self.schema_folder / "settings.json" | ||
|
||
if not vscode_settings_file.exists(): | ||
util.write_file({}, vscode_settings_file) | ||
|
||
settings = util.read_file(vscode_settings_file, use_json5=True) | ||
vscode_key = "json.schemas" | ||
|
||
if vscode_key not in settings: | ||
settings[vscode_key] = [] | ||
|
||
for schema in self.schemas: | ||
updated_in_place = False | ||
schema_file = self.schema_folder / f"{schema.name}.json" | ||
|
||
for item in settings[vscode_key]: | ||
if schema.name in item.get("url", ''): | ||
item["url"] = str(schema_file) | ||
updated_in_place = True | ||
|
||
if not updated_in_place: | ||
settings[vscode_key].append({ | ||
"fileMatch": ["*.json"], | ||
"url": str(vscode_settings_file) | ||
}) | ||
|
||
util.write_file(settings, vscode_settings_file) | ||
|
||
@click.command() | ||
@click.option( | ||
"-vc", | ||
"--vscode", | ||
default=False, | ||
show_default=True, | ||
help="""Update JSON schemas in vscode settings. Note will create .vscode folder | ||
if not present in the current directory.""" | ||
) | ||
def create_schemas(vscode: bool): | ||
""" Function to handle the JSON schemas for emerge package.""" | ||
|
||
schema_manager = SchemaManager() | ||
schema_manager.add_schema("emerge_scenario_schema", | ||
data_model.DERScenarioConfigModel) | ||
schema_manager.generate_and_save_schemas() | ||
if vscode: | ||
schema_manager.configure_vscode_settings() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
""" Module for managing pydantic data models.""" | ||
|
||
from pydantic import BaseModel, confloat | ||
from pydantic import Field, BaseModel | ||
from typing_extensions import Annotated | ||
|
||
|
||
class ThermalLoadingLimit(BaseModel): | ||
""" Model representing thermal loading limit. """ | ||
|
||
threshold: confloat(ge = 0.0, le=2.0) = 1.0 | ||
threshold: Annotated[float, Field(ge = 0.0, le=2.0)] = 1.0 | ||
|
||
class VoltageViolationLimit(BaseModel): | ||
""" Model representing voltage violation limit. """ | ||
|
||
overvoltage_threshold: confloat(ge = 1.01, le=2.0) = 1.05 | ||
undervoltage_threshold: confloat(ge = 0, le=1.0) = 0.95 | ||
overvoltage_threshold: Annotated[float, Field(ge = 1.01, le=2.0)] = 1.05 | ||
undervoltage_threshold: Annotated[float, Field(ge = 0, le=1.0)] = 0.95 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.