simulation_api.model

Package contents

Submodules

simulation_api.model.crud

This program manages database querys. CRUD comes from: Create, Read, Update, and Delete.

simulation_api.model.crud._create_parameters(db: sqlalchemy.orm.session.Session, parameters: List[simulation_api.controller.schemas.ParameterDBSchCreate])None[source]

Insert parameter entry into parameters table.

Parameters
  • db (Session) – Database Session.

  • parameters (List[ParameterDBSchCreate]) – Parameter row in parameters’ table.

Returns

Return type

None

simulation_api.model.crud._create_plot_query_values(db: sqlalchemy.orm.session.Session, plot_query_params: List[simulation_api.controller.schemas.PlotDBSchCreate])None[source]

Insert row in plots table (contains plot query params)

Parameters
  • db (Session) – Database Session.

  • plot_query_params (List[PlotDBSchCreate]) – List of rows to be inserted in plots table.

Returns

Return type

None

simulation_api.model.crud._create_simulation(db: sqlalchemy.orm.session.Session, simulation: simulation_api.controller.schemas.SimulationDBSchCreate)simulation_api.model.models.SimulationDB[source]

Inserts simulation in simulations table.

Parameters
  • db (Session) – Database Session.

  • simulation (SimulationDBSchCreate) – Simulation row in simulations table.

Returns

db_simulation – Updated simulation’s row.

Return type

SimulationDB

simulation_api.model.crud._create_user(db: sqlalchemy.orm.session.Session, user: simulation_api.controller.schemas.UserDBSchCreate)simulation_api.model.models.UserDB[source]

Inserts user in users table.

Parameters
  • db (Session) – Database Session.

  • user (UserDBSchCreate) – User row in database.

Returns

db_user – Updated inserted row (with user_id.)

Return type

UserDB

simulation_api.model.crud._get_all_simulations(db: sqlalchemy.orm.session.Session)Tuple[simulation_api.model.models.SimulationDB][source]

Get all simulation entries in simulations table.

Parameters

db (Session) – Database Session.

Returns

Querry of all rows in simulations table.

Return type

sqlalchemy.orm.Query

simulation_api.model.crud._get_parameters(db: sqlalchemy.orm.session.Session, sim_id: str, param_type: simulation_api.controller.schemas.ParamType)Union[List[float], Dict[str, float]][source]

Get parameters from parameters table.

Parameters
  • db (Session) – Database Session.

  • sim_id (str) – Simulation ID.

  • param_type (ParamType) – Type of parameter, wether 'initial condition' or 'parameter'.

Returns

list of initial conditions or dict mapping parameter names to parameter values.

Return type

List[float] or Dict[str, float]

simulation_api.model.crud._get_plot_query_values(db: sqlalchemy.orm.session.Session, sim_id: str)[source]

Return plot query parameters for a given simulation.

Parameters
  • db (Session) – Database Session.

  • sim_id (str) – Simulation ID.

Returns

Plot query values associated to sim_id.

Return type

List[PlotQueryValues]

simulation_api.model.crud._get_simulation(db: sqlalchemy.orm.session.Session, sim_id: str)simulation_api.model.models.SimulationDB[source]

Get simulation with specific id from simulations table.

Parameters
  • db (Session) – Database Session.

  • sim_id (str) – Simulation ID.

Returns

Query with simulation information of sim_id.

Return type

sqlalchemy.orm.Query

simulation_api.model.crud._get_username(db: sqlalchemy.orm.session.Session, user_id: int)[source]

Gets user from users table.

Parameters
  • db (Session) – Database Session.

  • user_id (int) –

Returns

Query with information about username with given user_id.

Return type

sqlalchemy.orm.Query

simulation_api.model.db_manager

This module starts the database engine, the database session and the basemodel for the database tables.

simulation_api.model.models

This program creates all the models and tables in the database

class simulation_api.model.models.ParameterDB(**kwargs)[source]

Bases: sqlalchemy.orm.decl_api.Base

Parmaeters table model.

Stores parameters and initial conditions of simulations.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

ini_cndtn_id

Initial condition position in array of initial conditions.

param_id
param_key

Name of parameter. Must be one of the required parameters related to the system being simulated.

param_type

Parameter type, wether 'initial condition' or 'parameter'.

sim_id

Simulation ID.

simulation

ORM relationship with simulations’ table.

value

Value of 'parameter' or initial contidion.

class simulation_api.model.models.PlotDB(**kwargs)[source]

Bases: sqlalchemy.orm.decl_api.Base

Plots table model.

Stores query parameter values of plots needed to access simulation results via GET in route /api/results/{sim_id}/plot?value={plot_query_value}.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

plot_id

Primary key.

plot_query_value

Label of each plot, used as query value for query param value in route /api/results/{sim_id}/plot.

sim_id

Simulation ID.

simulation

ORM relationship with simulations’ table.

class simulation_api.model.models.SimulationDB(**kwargs)[source]

Bases: sqlalchemy.orm.decl_api.Base

Simulation Status table model.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

date
message

Message with further information about the simulation status.

method

Integration method.

parameters

ORM relationship with parameters’ table.

plots

ORM relationship with plots’ table.

route_pickle

API route to GET simulation results in pickle format.

route_plots

API route to GET simulation plots.

route_results

API route to GET simulation results displayed in frontend web page.

sim_id

Simulation ID.

success

Tells if the simulation was successful or not.

system

Simulated system.

user

ORM relationship with users’ table.

user_id

user_id.

Type

Foreign key

class simulation_api.model.models.UserDB(**kwargs)[source]

Bases: sqlalchemy.orm.decl_api.Base

Users table model.

This table stores basic user information.

Note

hash_value and this users table is not appropiately used yet because logging is not yet implemented in the app.

__init__(**kwargs)

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

hash_value

Hash value of the usser’s password.

simulations

ORM relationship with simulations’ table.

user_id
username