stemp package

stemp.app_settings module

App-specific settings

These settings are initialized when wam.settings are called, before app itself gets started.

class stemp.app_settings.ScenarioModules[Quellcode]

Bases: object

Class to import scenario modules once needed

Scenarios cannot be imported within app_settings as not all resources are yet ready. Therefore, scenario modules are imported once when accessed later.

stemp.app_settings.add_engine(db_connection)[Quellcode]

Creates and adds DB connection from configuration file by given name

First, it is checked which db configuration should be used (default, or specified in config file). Second, engine is created by DB parameters for given DB connection and added to slqahelper with connection name.

Parameter:db_connection (str) – Database connection to set up
stemp.app_settings.import_scenario(scenario)[Quellcode]

Scenario with given name is imported from scenario module

Parameter:scenario (str) – Name of scenario module
Rückgabe:Imported scenario module
Rückgabetyp:module

stemp.apps module

class stemp.apps.StempConfig(app_name, app_module)[Quellcode]

Bases: django.apps.config.AppConfig

name = 'stemp'

stemp.constants module

Collection of stemp-related constants and enumerations

class stemp.constants.DemandType[Quellcode]

Bases: enum.IntEnum

Enumeration to differentiate between single household and district

District = 1
Single = 0
label()[Quellcode]

Label for given demand type

Rückgabe:Label of current demand type
Rückgabetyp:str
suffix()[Quellcode]

Suffix for current demand type

This is needed in order to load scenario parameters which are dependent on demand type.

Rückgabe:Demand type suffix
Rückgabetyp:str
class stemp.constants.DistrictStatus[Quellcode]

Bases: enum.Enum

District status enumeration

Changed = 'changed'
New = 'new'
Unchanged = 'unchanged'
class stemp.constants.HeatType[Quellcode]

Bases: enum.Enum

Heat type enumeration

floor = 'Fussbodenheizung'
radiator = 'Heizkörper'
class stemp.constants.HouseType[Quellcode]

Bases: enum.Enum

House type enumeration

EFH = 'Einfamilienhaus'
MFH = 'Mehrfamilienhaus'
class stemp.constants.ResultColor(quality, percentage, style)

Bases: tuple

percentage

Alias for field number 1

quality

Alias for field number 0

style

Alias for field number 2

class stemp.constants.WarmwaterConsumption[Quellcode]

Bases: enum.Enum

Enumeration for Warmwater consumption levels

High = 2
Low = 0
Medium = 1
from_liters = <function WarmwaterConsumption.from_liters>[Quellcode]
in_liters()[Quellcode]

Warmwater level in liters

Rückgabe:Warmwater consumption in liters
Rückgabetyp:int
stemp.constants.get_roof_square_meters(household_square_meters, house_type)[Quellcode]

Calculates potential roof square meters available for PV

Parameter:
  • household_square_meters (int) – Square meters of current household
  • house_type (HouseType) – Single household or district
Rückgabe:

Roof square meters available for PV

Rückgabetyp:

float

stemp.fields module

Module to hold customized django fields

class stemp.fields.HouseholdField(hh, count=1, in_district=False)[Quellcode]

Bases: django.forms.fields.Field

Field for households

Is used in district list and summary. Shows current household and selected amounts.

widget

Alias von stemp.widgets.HouseholdWidget

widget_attrs(widget)[Quellcode]

Given a Widget instance (not a Widget class), returns a dictionary of any HTML attributes that should be added to the Widget, based on this Field.

class stemp.fields.SubmitField(widget=<class 'stemp.widgets.SubmitWidget'>, **kwargs)[Quellcode]

Bases: django.forms.fields.Field

Simple submit field to add submit input

stemp.forms module

Module to hold customized django forms

class stemp.forms.ChoiceForm(name, label=None, choices=None, submit_on_change=True, initial=None, field=<class 'django.forms.fields.ChoiceField'>, widget=<class 'django.forms.widgets.Select'>, *args, **kwargs)[Quellcode]

Bases: django.forms.forms.Form

Customized choice form

Adds foundation attributes and „onchange“ submission.

base_fields = {}
declared_fields = {}
media
class stemp.forms.DistrictListForm(hh_dict)[Quellcode]

Bases: django.forms.forms.Form

Form to add multiple households of different type to current district

base_fields = {}
declared_fields = {}
efh()[Quellcode]

Returns all EFH of current district

Used to differentiate between EFH/MFH in template.

media
mfh()[Quellcode]

Returns all MFH of current district

Used to differentiate between EFH/MFH in template.

class stemp.forms.DistrictSelectForm(data=None, files=None, auto_id='id_%s', prefix=None, initial=None, error_class=<class 'django.forms.utils.ErrorList'>, label_suffix=None, empty_permitted=False, field_order=None, use_required_attribute=None, renderer=None)[Quellcode]

Bases: django.forms.forms.Form

Form to select a district

base_fields = {'district': <django.forms.models.ModelChoiceField object>}
declared_fields = {'district': <django.forms.models.ModelChoiceField object>}
media
class stemp.forms.HouseholdForm(only_house_type=None, *args, **kwargs)[Quellcode]

Bases: django.forms.models.ModelForm

Form to add/update a household

class Media[Quellcode]

Bases: object

js = ('stemp/js/household.js',)
class Meta[Quellcode]

Bases: object

error_messages = {'heat_demand': {'required': 'Bitte geben Sie einen gültigen Wert ein.'}, 'name': {'required': 'Bitte geben Sie einen Namen für den neuen Haushalt an.'}, 'roof_area': {'required': 'Bitte geben Sie einen gültigen Wert ein.'}, 'square_meters': {'required': 'Bitte geben Sie einen gültigen Wert ein.'}}
fields = '__all__'
model

Alias von stemp.models.Household

widgets = {'heat_demand': <django.forms.widgets.HiddenInput object>, 'roof_area': <django.forms.widgets.HiddenInput object>, 'square_meters': <django.forms.widgets.HiddenInput object>, 'warm_water_per_day': <django.forms.widgets.TextInput object>}
base_fields = {'heat_demand': <django.forms.fields.FloatField object>, 'heat_demand_hand': <django.forms.fields.IntegerField object>, 'heat_type': <django.forms.fields.TypedChoiceField object>, 'house_type': <django.forms.fields.TypedChoiceField object>, 'name': <django.forms.fields.CharField object>, 'number_of_persons': <django.forms.fields.IntegerField object>, 'roof_area': <django.forms.fields.FloatField object>, 'roof_area_hand': <django.forms.fields.IntegerField object>, 'square_meters': <django.forms.fields.IntegerField object>, 'square_meters_hand': <django.forms.fields.IntegerField object>, 'warm_water_per_day': <django.forms.fields.IntegerField object>}
static create_hotwater_chart()[Quellcode]
declared_fields = {'heat_demand_hand': <django.forms.fields.IntegerField object>, 'number_of_persons': <django.forms.fields.IntegerField object>, 'roof_area_hand': <django.forms.fields.IntegerField object>, 'square_meters_hand': <django.forms.fields.IntegerField object>}
media
class stemp.forms.HouseholdSelectForm(only_house_type=None, *args, **kwargs)[Quellcode]

Bases: django.forms.forms.Form

Form to select a household from list

A summary is shown for current selected household (logic in .js file).

class Media[Quellcode]

Bases: object

js = ('stemp/js/household_select.js',)
base_fields = {'profile': <django.forms.models.ModelChoiceField object>}
declared_fields = {'profile': <django.forms.models.ModelChoiceField object>}
media
class stemp.forms.ParameterForm(parameters, data=None, *args, **kwargs)[Quellcode]

Bases: django.forms.forms.Form

Form to show a grouped edit form for all possible parameters

Depending on parameter best fitting field is automatically detected and added to the form. The field type depends on parameter type (int, char, etc.). In case of int ant float types, slider field is added if min and max values are given.

base_fields = {}
declared_fields = {}
delimiter = '-'
error_groups()[Quellcode]
static get_changed_parameters(parameters, data)[Quellcode]

Compare original parameters with user entries and return diffs

media
prepared_data(scenario=None)[Quellcode]

Reads out all (edited) parameters and returns them as dict.

Dict has the form dict[component: dict[parameter: value]].

Parameter:scenario (str) – If given, only parameters used in scenario are returned
Rückgabe:Nested dictionary of all related components and their parameter values
Rückgabetyp:dict
class stemp.forms.TechnologyForm(name, label=None, choices=None, initial=None, information=None, *args, **kwargs)[Quellcode]

Bases: django.forms.forms.Form

Form for technology checkboxes

Additional information is loaded within TechnologyWidget.

base_fields = {}
declared_fields = {}
media
class stemp.forms.ValueUnit(value, unit)

Bases: tuple

unit

Alias for field number 1

value

Alias for field number 0

stemp.models module

Database models to set up households and districts and to store simulations including related scenario, parameters and results

class stemp.models.District(*args, **kwargs)[Quellcode]

Bases: django.db.models.base.Model

Multiple households combined to a district

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

add_households(households)[Quellcode]

Adds multiple households to the district

Parameter:(dict[int, int]) (households) – Dictionary containing household-id as key and amount of this household type as value
annual_heat_demand()[Quellcode]

Returns combined annual heat demand for all households in district

annual_hot_water_demand()[Quellcode]

Returns combined annual hot water demand for all households in district

annual_total_demand()[Quellcode]

Returns combined annual totol demand (heat and warmwater) for all related households in district

contains_radiator()[Quellcode]

Returns True if any household in district contains a radiator

districthouseholds_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

households

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

max_pv_size

Returns summarized PV potential in district

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
class stemp.models.DistrictHouseholds(*args, **kwargs)[Quellcode]

Bases: django.db.models.base.Model

Relation between districts and related households (many-to-many)

Amount is given to provide possibility to add multiple households of same type as one entry.

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

amount

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

district

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

district_id
household

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

household_id
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
class stemp.models.HeatProfile(*args, **kwargs)[Quellcode]

Bases: django.db.models.base.Model

Model to hold heat profiles for different households and number of persons

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

layout = {'title': 'Wärmeverbrauch', 'x_title': 'Zeit [h]', 'y_title': 'Wärmeverbrauch [kWh]'}
name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
profile

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class stemp.models.Household(*args, **kwargs)[Quellcode]

Bases: django.db.models.base.Model

Household model contains all data to a single household

name(str)
Type:Name of the household
house_type(str)
Type:EFH (Einfamilienhaus) or MFH (Mehrfamilienhaus)
heat_demand(float)
Type:Total annual heat demand
number_of_persons(int)
Type:Persons belonging to the household
square_meters(int)
Type:Square meters of household
heat_type(str)
Type:radiator or floor
warm_water_per_day(int)
Type:Daily warm water consumption
roof_area(float)
Type:Potential photovoltaik area on roof of household
exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

annual_heat_demand()[Quellcode]
annual_hot_water_demand()[Quellcode]

Get annual hot water demand profile

Depending on warmwater consumption per day and number of persons in household.

Rückgabe:Annual hot water profile
Rückgabetyp:pandas.Series
annual_total_demand()[Quellcode]
contains_radiator()[Quellcode]
district_set

Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.

In the example:

class Pizza(Model):
    toppings = ManyToManyField(Topping, related_name='pizzas')

Pizza.toppings and Topping.pizzas are ManyToManyDescriptor instances.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

districthouseholds_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

get_heat_demand_profile()[Quellcode]

Get heat demand profile depending on given house type (EFH/MFH)

Rückgabe:Heat demand profile for given house type
Rückgabetyp:pandas.Series
get_heat_type_display(*, field=<django.db.models.fields.CharField: heat_type>)
get_house_type_display(*, field=<django.db.models.fields.CharField: house_type>)
get_oep_timeseries(name)[Quellcode]

Function to get household timeseries

This function allows one time DB access, in order to avoid multiple database look-ups.

Rückgabe:Heat demand profile for given house type
Rückgabetyp:pandas.Series
heat_demand

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

heat_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

house_type

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

max_pv_size

Photovoltaik potential for given roof area and PV-per-square-meters-ratio

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

number_of_persons

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
roof_area

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

square_meters

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

timeseries = None
warm_water_demand()[Quellcode]
warm_water_per_day

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class stemp.models.Parameter(*args, **kwargs)[Quellcode]

Bases: django.db.models.base.Model

Holds all parameters for a simulation run

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

data

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
simulation_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class stemp.models.Scenario(*args, **kwargs)[Quellcode]

Bases: django.db.models.base.Model

Holds name and date of simulation run

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

get_next_by_last_change(*, field=<django.db.models.fields.DateTimeField: last_change>, is_next=True, **kwargs)
get_previous_by_last_change(*, field=<django.db.models.fields.DateTimeField: last_change>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

last_change

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

name

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
simulation_set

Accessor to the related objects manager on the reverse side of a many-to-one relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Parent.children is a ReverseManyToOneDescriptor instance.

Most of the implementation is delegated to a dynamically defined manager class built by create_forward_many_to_many_manager() defined below.

class stemp.models.Simulation(*args, **kwargs)[Quellcode]

Bases: django.db.models.base.Model

Connects szenario with parameters to oemof results.

As oemof results are stored via sqlalchemy, relation between simulation and result is built via „result_id“ (not Foreign-key, thus loose coupled).

exception DoesNotExist

Bases: django.core.exceptions.ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: django.core.exceptions.MultipleObjectsReturned

date

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

classmethod delete_containing_household(hh_id)[Quellcode]

Deletes all simulations which contain given household ID

get_next_by_date(*, field=<django.db.models.fields.DateTimeField: date>, is_next=True, **kwargs)
get_previous_by_date(*, field=<django.db.models.fields.DateTimeField: date>, is_next=False, **kwargs)
id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

objects = <django.db.models.manager.Manager object>
parameter

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

parameter_id
result_id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

scenario

Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.

In the example:

class Child(Model):
    parent = ForeignKey(Parent, related_name='children')

Child.parent is a ForwardManyToOneDescriptor instance.

scenario_id

stemp.oep_models module

Database models to store scenario parameters and timeseries (including hot water).

Initially these models should be seperated from WAM-server and migrated to OEP instead. But due to OEP-latency, models are migrated to WAM-serverr right now.

class stemp.oep_models.OEPHotWater(**kwargs)[Quellcode]

Bases: sqlalchemy.ext.declarative.api.Base

Model to hold hot water timeseries related to given liter

data
id
liter
class stemp.oep_models.OEPScenario(**kwargs)[Quellcode]

Bases: sqlalchemy.ext.declarative.api.Base

Contains all parameters related to scenarios

Parameter:
  • scenario – Related scenario name (gas/oil/…)
  • component – Component which parameter belongs to (gas/bus/demand/…)
  • unit – unit of given param
  • parameter_type – costs/technologies - is used to distinguish parameters (different colors are used in parameters page)
  • parameter – Name of the parameter
  • value_type – int/str/float
  • value – Value of given parameter
component
classmethod get_scenario_parameters(scenario_name, demand_type)[Quellcode]

All scenario parameters for given scenario name and demand type are fetched

Scenario parameters are chained with default attributes; thus, default parameter values are used as fallback values, if scenario does not define special/individual values.

id
parameter
parameter_type
scenario
unit
value
value_type
class stemp.oep_models.OEPTimeseries(**kwargs)[Quellcode]

Bases: sqlalchemy.ext.declarative.api.Base

Model to hold timeseries with related metadata (json)

data
id
meta_data
name

stemp.settings module

stemp.tasks module

stemp.urls module

stemp.user_data module

stemp.views module

stemp.views_admin module

stemp.views_dynamic module

Functions to handle dynamic AJAX-requests

stemp.views_dynamic.get_heat_demand(request)[Quellcode]

Calculates heat demand related to square meters and household type

stemp.views_dynamic.get_household_summary(request)[Quellcode]

Provides household summary widget for given household ID

stemp.views_dynamic.get_next_household_name(request)[Quellcode]

Dynamic household naming

If household name is already present in DB, a counting number prefix is added

stemp.views_dynamic.get_roof_area(request)[Quellcode]

Calculates roof area related to square meters and household type

stemp.views_dynamic.get_square_meters(request)[Quellcode]

Calculates square meters related to number of persons

stemp.views_dynamic.get_warm_water_energy(request)[Quellcode]

Calculates warm water consumption related to number of persons

stemp.widgets module

Additional widgets used by forms or individually

class stemp.widgets.DistrictSubmitWidget(attrs=None)[Quellcode]

Bases: django.forms.widgets.Widget

media
template_name = 'widgets/district_submit.html'
class stemp.widgets.HouseholdSummary(household, use_header=True, count=None)[Quellcode]

Bases: utils.widgets.CustomWidget

Widget to show summary of a household

If „use_header“ is True, an accordion is used to hide summary at first.

get_context()[Quellcode]
class stemp.widgets.HouseholdWidget(attrs=None)[Quellcode]

Bases: django.forms.widgets.Widget

media
template_name = 'widgets/district_household.html'
class stemp.widgets.ParameterSummary(changed_parameters)[Quellcode]

Bases: utils.widgets.CustomWidget

Widget to show non-default parameters, changed by user

For each changed parameter, related icon and label is shown

get_context()[Quellcode]
template_name = 'widgets/summary_parameter.html'
class stemp.widgets.SelectWithDisabled(attrs=None, choices=())[Quellcode]

Bases: django.forms.widgets.Select

Subclass of Django’s select widget that allows disabling options. To disable an option, pass a dict instead of a string for its label, of the form: {‚label‘: ‚option label‘, ‚disabled‘: True} From: https://djangosnippets.org/snippets/2453/

create_option(name, value, label, selected, index, subindex=None, attrs=None)[Quellcode]
media
class stemp.widgets.SliderInput(step_size=1, attrs=None)[Quellcode]

Bases: django.forms.widgets.NumberInput

Widget to add slider to number input field

Step size can be chosen, defaults to 1. Precision of number is adapted automatically from step size.

get_context(name, value, attrs)[Quellcode]
input_type = 'number'
media
template_name = 'widgets/slider.html'
class stemp.widgets.SubmitWidget(attrs=None)[Quellcode]

Bases: django.forms.widgets.Widget

Widget for submit button

From https://djangosnippets.org/snippets/2312/

media
render(name, value, attrs=None, renderer=None)[Quellcode]

Render the widget as an HTML string.

class stemp.widgets.TechnologySummary(scenario_config)[Quellcode]

Bases: utils.widgets.CustomWidget

Widget to show chosen technology as icon plus name

get_context()[Quellcode]
template_name = 'widgets/summary_technology.html'
class stemp.widgets.TechnologyWidget(attrs=None, choices=(), information=None)[Quellcode]

Bases: django.forms.widgets.CheckboxSelectMultiple

Widget to add key-value-pairs to select component From: https://www.abidibo.net/blog/2017/10/16/add-data-attributes-option-tags-django-admin-select-field/

create_option(name, value, label, selected, index, subindex=None, attrs=None)[Quellcode]
media
template_name = 'widgets/technology.html'