viroconwebcontour.views module

Handles requests and outputs rendered html.

class contour.views.EnvironmentalContourHandler[source]

Bases: contour.views.Handler

Handler for EnvironmentalContour objects.

static delete(pk, collection=<class 'contour.models.EnvironmentalContour'>)[source]

Deletes an object from the data base.

Parameters:
  • request (HttpRequest,) – The request to delete the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
static overview(model_class=<class 'contour.models.EnvironmentalContour'>)[source]

Renders an overview about all objects of a Django Model (all data base entries).

Parameters:
  • request (HttpRequest,) – Request to show the overview.
  • model_class (class of models.Model,) – The class of a Django Model as defined in models.py, e.g. MeasurementFileModel or EnvironmentalContour.
Returns:

The rendered overview.

Return type:

HttpResponse,

static show(pk, model_class=<class 'contour.models.EnvironmentalContour'>)[source]

Shows an object from the data base, e.g. an EnvironmentalContour object.

Parameters:
  • request (HttpRequest,) – The HttpRequest to show the object.
  • pk (int,) – Primary key of the object in the data base.
  • model_class (models.Model,) – The class of the Django model, which should be shown. For example the class models.EnvronmentalContour.
Returns:

response – Renders an html response showing the object.

Return type:

HttpResponse,

static update(pk, model_class=<class 'contour.models.EnvironmentalContour'>)[source]

Updates an object in the data base.

Parameters:
  • request (HttpRequest,) – The request to update the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
class contour.views.Handler[source]

Bases: object

static add(*args)[source]

Adds an object to the data base.

Must be overwritten by the Handler specific to one Django Model.

Parameters:request (HttpRequest,) – The request to add the object to the data base.
static delete(pk, model_class)[source]

Deletes an object from the data base.

Parameters:
  • request (HttpRequest,) – The request to delete the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
static overview(model_class)[source]

Renders an overview about all objects of a Django Model (all data base entries).

Parameters:
  • request (HttpRequest,) – Request to show the overview.
  • model_class (class of models.Model,) – The class of a Django Model as defined in models.py, e.g. MeasurementFileModel or EnvironmentalContour.
Returns:

The rendered overview.

Return type:

HttpResponse,

static select()[source]

A reduced overview of all objects to guide the user through the work flow shown at the Dashboard.

Parameters:request (HttpRequest,) – Request to render the select view.
static show(pk, model_class)[source]

Shows an object from the data base, e.g. an EnvironmentalContour object.

Parameters:
  • request (HttpRequest,) – The HttpRequest to show the object.
  • pk (int,) – Primary key of the object in the data base.
  • model_class (models.Model,) – The class of the Django model, which should be shown. For example the class models.EnvronmentalContour.
Returns:

response – Renders an html response showing the object.

Return type:

HttpResponse,

static update(pk, model_class)[source]

Updates an object in the data base.

Parameters:
  • request (HttpRequest,) – The request to update the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
class contour.views.MeasureFileHandler[source]

Bases: contour.views.Handler

static add()[source]

Adds a MeasurementFileModel to the data base.

Parameters:request (HttpRequest,) – Request to add the model to the data base.
Returns:Renders the a response to the user after she/he added the model.
Return type:HttpResponse,
static delete(pk, model_class=<class 'contour.models.MeasureFileModel'>)[source]

Deletes an object from the data base.

Parameters:
  • request (HttpRequest,) – The request to delete the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
static fit_file(pk)[source]

Fits a probabilistic model to a measurement file and renders the result.

Parameters:
  • request (HttpRequest,) – Request to peform a fit.
  • pk (int,) – Primary key of the measurement file.
Returns:

Renders the fitting result.

Return type:

HttpResponse,

static new_fit(pk)[source]

Deletes the previous fit and returns the form to define a new fit.

Parameters:
  • request (HttpRequest,) – Request to perform a new fit.
  • pk (int,) – Primary key of the previous fit, which will be deleted.
Returns:

Renders the view to select a measurement file for fitting.

Return type:

HttpResponse,

static overview(model_class=<class 'contour.models.MeasureFileModel'>)[source]

Renders an overview about all objects of a Django Model (all data base entries).

Parameters:
  • request (HttpRequest,) – Request to show the overview.
  • model_class (class of models.Model,) – The class of a Django Model as defined in models.py, e.g. MeasurementFileModel or EnvironmentalContour.
Returns:

The rendered overview.

Return type:

HttpResponse,

static plot_file(pk)[source]

Plots and renders a measurement file.

Parameters:
  • request (HttpRequest,) – Request to plot a measurement file.
  • pk (int,) – Primary key of the measurement file, which will be plotted.
Returns:

Renders the plotted measurement file.

Return type:

HttpResponse,

static select()[source]

A reduced overview of all objects to guide the user through the work flow shown at the Dashboard.

Parameters:request (HttpRequest,) – Request to render the select view.
static update(pk, model_class=<class 'contour.models.MeasureFileModel'>)[source]

Updates an object in the data base.

Parameters:
  • request (HttpRequest,) – The request to update the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
class contour.views.ProbabilisticModelHandler[source]

Bases: contour.views.Handler

static add(*args)[source]

Adds a ProbabilisticModel to the data base.

Parameters:request (HttpRequest,) – Request to add the model to the data base.
Returns:Renders feedback to the user based on whether she/he is: * logged in (normal behaviour) * Sent a defined probabilistic model as a POST request (normal behaviour) * Requested a form with a GET request or (unexpected beavhiour)
Return type:HttpResponse,
static calculate(pk, method)[source]

Handles requests to calculate an environmental contour.

This method handles both requests, for an IFORM contour and for a highest density contour.

Parameters:
  • request (HttpRequest,) – Request to calculate a contour.
  • pk (int,) – Primary key of the probabilistic model, which the contour should be based on.
  • method (str,) – Defines, which method should be used. Must be either ‘I’ form IFORM contour or ‘H’ for highest density contour.
Returns:

Renders the form for inputing all preprocessing options to calculate a contour.

Return type:

HttpResponse,

static delete(pk, model_class=<class 'contour.models.ProbabilisticModel'>)[source]

Deletes an object from the data base.

Parameters:
  • request (HttpRequest,) – The request to delete the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
static hdc_calc(var_names, var_symbols, probabilistic_model)[source]

Calls the HDC calculation and handles errors if they occur.

Parameters:
  • request (HttpRequest,) – The HttpRequest to either show the calculation settings page or to calculate the contour (differentiated by POST or GET request).
  • var_names (list of str) – Names of the variables.
  • var_symbols (list of str) – Names of the symbols of the probabilistic model’s variables.
  • probabilistic_model (models.ProbabilisticModel) – Probabilistic model, which should be used for the environmental contour calculation.
Returns:

response – Renders an html response showing contour or the error message.

Return type:

HttpResponse,

static iform_calc(var_names, var_symbols, probabilistic_model)[source]

Calls the IFORM contour calculation and handles errors if they occur.

Parameters:
  • request (HttpRequest,) – The HttpRequest to either show the calculation settings page or to calculate the contour (differentiated by POST or GET request).
  • var_names (list of str) – Names of the variables.
  • var_symbols (list of str) – Names of the symbols of the probabilistic model’s variables.
  • probabilistic_model (models.ProbabilisticModel) – Probabilistic model, which should be used for the environmental contour calculation.
Returns:

response – Renders an html response showing contour or the error message.

Return type:

HttpResponse,

static overview(model_class=<class 'contour.models.ProbabilisticModel'>)[source]

Renders an overview about all objects of a Django Model (all data base entries).

Parameters:
  • request (HttpRequest,) – Request to show the overview.
  • model_class (class of models.Model,) – The class of a Django Model as defined in models.py, e.g. MeasurementFileModel or EnvironmentalContour.
Returns:

The rendered overview.

Return type:

HttpResponse,

static render_calculated_contour(environmental_contour, contour_coordinates, probabilistic_model, warn)[source]
Parameters:
  • request (HttpRequest,) – The HttpRequest to calculate the contour. It is a POST request.
  • environmental_contour (EnvironmentalContour,) – The EnvironmentalContour that just got computed.
  • contour_coordinates (list of list of np.ndarray,) – The contour’s coordinates. The format is defined in viroconcom.contours.Contour.
  • probabilistic_model (ProbabilisticModel,) – The ProbabilisticModel, which was used to calculate the EnvironmentalContour
  • warn (list of warning,) – Warnings can get raised during the calculation of the contour. Then the user will be presented these warnings.
Returns:

response – The rendered template ‘evnironmental_contour_show.html’ with the calculated EnvironmentalContour.

Return type:

HttpResponse,

static select()[source]

Renders an overview of the probabilistic models with the option to select one to calculate an environmental contour.

Parameters:request (HttpRequest,) – Request to select a probabilistic model to calculate a contour.
Returns:Renders an overview of the probabilistic models with the option to select one to calculate an environmental contour.
Return type:HttpResponse,
static set_variables_number()[source]

Sets the number of variables when a probabilistc model is defined directly.

Parameters:request (HttpRequest,) – Request to set the number of variables of the probabilistic model.
Returns:Either adds the probabilistic model to the data base (POST request) or renders the form to add a probabilistic model (GET request).
Return type:HttpResponse,
static show_model(pk)[source]

Shows a probabilistic model.

Parameters:
  • request (HttpRequest,) – Request to show a probabilistic model.
  • pk (int,) – Primary key of the probabilistic model.
Returns:

Renders the definition of the probabilistic model (its name, the probability density function, information about the fit)

Return type:

HttpResponse,

static update(pk, model_class=<class 'contour.models.ProbabilisticModel'>)[source]

Updates an object in the data base.

Parameters:
  • request (HttpRequest,) – The request to update the object.
  • pk (int,) – The object’s primary key.
  • model_class (class of models.Model,) – The class of the Django Model (as defined in models.py).
contour.views.get_header_info_from_reader(reader)[source]

Reads the variable names and symbols form a reader.

Parameters:reader (csv.Reader) – A Reader object that can read a file line by line. See https://docs.python.org/2/library/csv.html#reader-objects for a proper documentation.
Returns:
  • var_names (list of str,) – Names of the environmental variables used in csv file, e.g. [‘wind speed [m/s]’, ‘significant wave height [m]’]
  • var_symbols (list of str,) – Symbols of the environental variables used in the csv file, e.g. [‘V’, ‘Hs’]
contour.views.get_info_from_file(url)[source]

Reads the variable names and symbols form a csv file.

Parameters:url (str,) – Path to the csv file.
Returns:
  • var_names (list of str,) – Names of the environmental variables used in csv file, e.g. [‘wind speed [m/s]’, ‘significant wave height [m]’]
  • var_symbols (list of str,) – Symbols of the environental variables used in the csv file, e.g. [‘V’, ‘Hs’]
contour.views.index(request)[source]

Renders the landing page, i.e. the ‘Dashboard’.

contour.views.save_environmental_contour(environmental_contour, additional_contour_options, contour_coordinates, user)[source]

Saves an EnvironmentalContour object and its depending models to the data base.

Parameters:
  • environmental_contour (EnvironmentalContour,) – The environmental contour obect that should be saved.
  • additional_contour_options (list of AdditionalContourOption,) – Options, whch are specific to the contour and are not general environmental contour options.
  • contour_coordinates (list of list of numpy.ndarray,) – Contains the coordinates of points on the contour. The outer list contains can hold multiple contour paths if the distribution is multimodal. The inner list contains multiple numpy arrays of the same length, one per dimension. The values of the arrays are the coordinates in the corresponding dimension.
  • user (str,) – The user who should own the environmental contour.
Returns:

The saved environmental contour object.

Return type:

EnvironmentalContour,

contour.views.save_fitted_prob_model(fit, model_title, var_names, var_symbols, user, measure_file)[source]

Saves a probabilistic model which was fitted to measurement data.

Parameters:
  • fit (Fit,) – Calculated fit results of a measurement file.
  • model_title (str,) – Title of the probabilistic model.
  • var_names (list of str,) – Names of the variables.
  • var_symbols (list of str,) – Names of the symbols of the probabilistic model’s variables.
  • user (str,) – Name of a user.
  • measure_file (MeasureFileModel,) – MeasureFileModel object linked to the probabilistic model.
Returns:

ProbabilisticModel that was fitted to the measurement file.

Return type:

ProbabilisticModel

contour.views.save_parameter(parameter, distribution_model, dependency, name)[source]

Saves a fitted parameter and links it to a DistributionModel.

Parameters:
  • parameter (ConstantParam or FunctionParam) – ConstantParam is a float value. FunctionParam contains a whole function like power function or exponential.
  • distribution_model (DistributionModel) – The parameter will be linked to this DistributionModel.
  • dependency (int) – The dimension the dependency is based on.
  • name (str) – Name of the parameter (‘shape’, ‘loc’ or ‘scale’)