deseasion.backend.models package
- class deseasion.backend.models.AttributeType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- nominal = 2
- ordinal = 3
- quantitative = 1
- class deseasion.backend.models.BaseData(name, features=[], description=None, **kwargs)
Bases:
HasPermissions
,TimestampMixin
,Model
- Permission
alias of
BaseDataPermission
- attributes
- created_at
- description
- features
- id
- is_public
- load_properties(force=False)
Load the model properties and save them to the database
- Args:
force (bool): to force the loading of the properties
- modified_at
- name
- original_name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- type
- class deseasion.backend.models.BaseGeoData(name, features=[], description=None, **kwargs)
Bases:
BaseData
- as_geojson()
- attributes
- created_at
- description
- extent
- extent_filter
- features
- id
- is_public
- load_extent()
- modified_at
- name
- original_name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- type
- class deseasion.backend.models.ContinuousRule(rule='', default_values=[], **kwargs)
Bases:
PrefDefaultValues
Used to create a geo-data containing continuous values from a rule
- cut_to_extent
- data_generator
- data_generator_id
- default_values
- id
- model_type
- name
- rule
- class deseasion.backend.models.DataAttribute(**kwargs)
Bases:
ModelMixin
,Model
- data
- data_id
- get_value_class()
- id
- load_statistics()
Load statistics about the attribute values.
The stats are calculated using pandas’ describe function.
- mrsort_criteria
- name
- new_copy()
- same_as(other) bool
Check attribute is same as other.
- Parameters:
other – other data attribute or
None
- Returns:
True
if they are the same,False
otherwise
Warning
This does not check values or statistics
- statistics
- type
- values
- class deseasion.backend.models.DataAttributeNominal(**kwargs)
Bases:
DataAttribute
- data
- data_id
- get_value_class()
- id
- mrsort_criteria
- name
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- statistics
- type
- values
- class deseasion.backend.models.DataAttributeOrdinal(**kwargs)
Bases:
DataAttribute
- data
- data_id
- get_value_class()
- id
- mrsort_criteria
- name
- new_copy()
- order
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- same_as(other) bool
Check attribute is same as other.
- Parameters:
other – other data attribute or
None
- Returns:
True
if they are the same,False
otherwise
Warning
This does not check values or statistics
- statistics
- type
- values
- class deseasion.backend.models.DataAttributeQuantitative(**kwargs)
Bases:
DataAttribute
- data
- data_id
- get_value_class()
- id
- mrsort_criteria
- name
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- statistics
- type
- values
- class deseasion.backend.models.DataGenerator(processing_model=None, **kwargs)
Bases:
DynamicData
- active_model_id
- created_at
- data
- data_id
- data_type
- description
- id
- input_data
- last_update
- modified_at
- name
- output_data
- property processing_model
- project
- project_id
- class deseasion.backend.models.DataGeo(data=None, data_id=None, **kwargs)
Bases:
ProjectData
- add_input(project_data)
Add input (always fail).
- Parameters:
project_data –
- Raises:
TypeError – data doesn’t accept inputs
- create()
Persist the object in the database, with a creation, modification and last updat edate
- created_at
- data
- data_id
- data_type
- description
- id
- input_data
- is_outdated()
Checks if input data are more recent than this object
- last_update
- modified_at
- name
- output_data
- project
- project_id
Bases:
ModelMixin
,Model
- class deseasion.backend.models.DataStream(stream=None, stream_id=None, **kwargs)
Bases:
DynamicData
- add_input(project_data)
Add input (always fail).
- Parameters:
project_data –
- Raises:
TypeError – data doesn’t accept inputs
- classes
- created_at
- data
- data_id
- data_type
- description
- id
- input_data
- last_update
- modified_at
- name
- output_data
- project
- project_id
- resolution
- start
- step
- stop
- stream
- stream_id
- class deseasion.backend.models.DataType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- data_stream = 4
- generator = 2
- geo_data = 1
- global_data = 3
- class deseasion.backend.models.DataValue(**kwargs)
Bases:
ModelMixin
,Model
- attribute
- attribute_id
- feature
- feature_id
- id
- type
- value
- class deseasion.backend.models.DiscreteCategory(name, **kwargs)
Bases:
ModelMixin
,Model
Model for creating data using discrete values (categories).
- id
- name
- position
- preference_model
- preference_model_id
- type
- class deseasion.backend.models.DiscreteRules(categories=[], **kwargs)
Bases:
DiscreteModel
Used to create a geo-data containing discrete values (ie. categories) from rules.
- categories
- cut_to_extent
- data_generator
- data_generator_id
- explain(feature)
Explain feature wrt the model.
- Parameters:
feature – feature computed by the model
- Returns:
explanation as a dict
- id
- model_type
- name
- class deseasion.backend.models.DiscreteRulesCategory(rules=[], **kwargs)
Bases:
DiscreteCategory
- evaluate_data(data, stats=None)
- id
- name
- position
- preference_model
- preference_model_id
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- rules
- type
- class deseasion.backend.models.DynamicData(name=None, project=None, description='', input_data=[])
Bases:
ProjectData
- created_at
- data
- data_id
- data_type
- description
- id
- input_data
- last_update
- modified_at
- name
- output_data
- project
- project_id
- class deseasion.backend.models.Feature(*args, properties=[], execution_artifact=None, input_features=[], **kwargs)
Bases:
ModelMixin
,Model
Table for the data features.
- Attributes:
properties (dict): The properties or attributes of the feature. data_id (int): Reference to the data.
- data
- data_id
- execution_artifact
- explain()
Return explanation for feature values.
This is empty except for generated geo data features.
- Returns:
- get_input_data()
Returns the list of input data.
- get_input_features(data_id)
Returns the input features belonging to provided data.
- get_output_data()
Returns the list of output data.
- get_output_features(data_id)
Returns the output features belonging to provided data.
- get_property(prop)
Returns the value of the property
- id
- input_features
- output_features
- properties
- type
- class deseasion.backend.models.FeatureType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- feature = 1
- geo_feature = 2
- class deseasion.backend.models.GeneratedGeoData(name, features=[], description=None, **kwargs)
Bases:
BaseGeoData
Table for the geographical data generated by the processing model in the projects.
- attributes
- created_at
- description
- extent
- extent_filter
- features
- id
- is_public
- modified_at
- name
- original_name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- project_data
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- type
- class deseasion.backend.models.GeoBuffer(radius=None, **kwargs)
Bases:
ProcessingModel
Model to create a buffer around the geometry.
- cut_to_extent
- data_generator
- data_generator_id
- explain(feature)
Explain feature wrt the model.
- Parameters:
feature – feature computed by the model
- Returns:
explanation as a dict
- id
- model_type
- name
- radius
- class deseasion.backend.models.GeoData(*args, original_name=None, source_driver=None, is_public=False, **kwargs)
Bases:
UploadableData
,BaseGeoData
Table for the geographical data loaded from files.
- Attributes:
original_name (str): The name of the file. source_driver (str): Which format the original data used. upload_user_id (int): Reference to the user who uploaded the data. description (str): A description text.
- attributes
- created_at
- description
- extent
- extent_filter
- features
- id
- is_public
- modified_at
- name
- original_name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- source_driver
- type
- upload_user_id
- class deseasion.backend.models.GeoDataType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- generated_geo_data = 2
- geo_data = 1
- global_data = 3
- wfs = 4
- wms = 5
- class deseasion.backend.models.GeoFeature(geom, *args, **kwargs)
Bases:
Feature
Table for the geo-data features.
- Attributes:
geom: The geometry of the feature. properties (dict): The properties or attributes of the feature. data_id (int): Reference to the geo-data.
- as_geojson()
Return the feature as a GeoJSON data.
- data
- data_id
- execution_artifact
- geom
- id
- input_features
- output_features
- properties
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- type
- class deseasion.backend.models.GlobalData(feature, **kwargs)
Bases:
UploadableData
,BaseData
- attributes
- created_at
- description
- feature
- feature_id
- features
- get_property(prop)
Returns the value of the property
- id
- is_public
- modified_at
- name
- original_name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- properties
- set_property(prop, value)
Set property value.
Try to reuse existing attribute if type matches.
- Parameters:
prop – property name (attribute name)
value – new property value
- type
- upload_user_id
- class deseasion.backend.models.KeepOverlap(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- average = 4
- max = 2
- min = 1
- sum = 3
- class deseasion.backend.models.MRSort(criteria=[], categories=[], **kwargs)
Bases:
DiscreteModel
Used to create a geo-data using the MR-Sort algorithm.
- Attributes:
- categories (list): The categories for the sorting algorithm.
Best category first.
- majority_threshold (float): The cut threshold for the concordance
condition. At least half the sum of the criteria weights.
- categories
- check_category(attributes)
Execute the MR-Sort algorithm on the attributes.
- Args:
attributes (list): List of (‘name’, ‘attribute’, value).
- Raises:
- AttributeError: If the attribute (‘name’, ‘attribute’) does not
correspond to any criterion.
- compute_weights(attributes, profile_index, criteria_lookup=None)
Compute weights where feature is better than profile.
- Parameters:
attributes – list of (data name, attribute name, value)
profile_index – index of profile to compare to
criteria_lookup – dict mapping (data name, attribute name) to criteria, computed if absent
- Returns:
weights for attributes where feature is better than profile indexed by (data name, attribute name)
- criteria
- cut_to_extent
- data_generator
- data_generator_id
- explain(feature)
Explain feature wrt the model.
- Parameters:
feature – feature computed by the model
- Returns:
explanation as a dict
- id
- inference_alternatives
- init_criteria()
- majority_threshold
- model_type
- name
- validate_criteria(key, criterion)
Verify that the criterion references an input_data.
- class deseasion.backend.models.MRSortCriterion(mrsort=None, profiles=[], weight=0, maximize=True, **kwargs)
Bases:
BaseModelMixin
,Model
Contain the criterion data for the MR-Sort algorithm.
- Attributes:
- profiles: The values for the profiles of the categories.
Worst value first.
- weight (float):
The weight of the criterion in the algorithm.
- maximize (bool):
Preference direction (maximize if True, minimize if False). Default: True.
- attribute
- attribute_id
- inference_values
- is_better(value, profile_index)
Check if the value is better than the profile for the given index.
- Args:
value (number): The value to check. profile_index (int): Index of the profile in the profiles list.
- maximize
- mrsort
- mrsort_id
- profiles
- weight
- class deseasion.backend.models.ModelType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- categories_rule = 1
- continuous_rule = 2
- dissolve_adjacent = 7
- geo_buffer = 3
- merge_overlap = 6
- mrsort = 4
- weighted_sum = 5
- zone_proposition = 8
- class deseasion.backend.models.PermissionAbility(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- create_geo_data = 2
- create_project = 1
- class deseasion.backend.models.ProcessingModel(cut_to_extent=True, name='', **kwargs)
Bases:
ModelMixin
,Model
- cut_to_extent
- data_generator
- data_generator_id
- explain(feature: Feature) dict
Explain feature wrt the model.
- Parameters:
feature – feature computed by the model
- Returns:
explanation as a dict
- get_used_input_attributes() list[DataAttribute]
Get list of used input attributes in a model definition.
- Returns:
- id
- property input_data
- model_type
- name
- class deseasion.backend.models.Project(name, manager=None, description='', extent=None, is_public=False)
Bases:
ProjectBase
Represents a project and its data
- created_at
- data_list
- description
- extent
- classmethod from_template(template, manager=None)
Create a project from a template.
The manager of the project will be the owner of the template.
- Args:
template: the template to copy
- id
- is_public
- is_template
- manager_id
- modified_at
- name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- project_tasks
- class deseasion.backend.models.ProjectData(name=None, project=None, description='', input_data=[])
Bases:
TimestampMixin
,Model
- add_input(project_data)
Add input data.
- Parameters:
project_data –
- Raises:
ValueError – if project_data is from a different project
- created_at
- data
- data_id
- data_type
- description
- explain(feature: Feature) dict
Explain feature values wrt the project data.
- Parameters:
feature –
- Raises:
ValueError – if feature does not belong to this project data
- Returns:
explanation as a dict
- get_attributes_list()
Returns the list of attributes of the features for this data.
- Returns:
a dictionary with the following keys: “id”, “name”, “type”, “statistics”
- get_used_attributes() list[DataAttribute]
Get used attributes of project data if the user is authorized to access it.
This list contains all attributes used at least once in a processing model of the downstream project data.
- Returns:
Used attributes.
- get_used_input_attributes() list[DataAttribute]
Get used input attributes of project data if the user is authorized to access it.
This list contains al inputl attributes used at least once in a processing model of the project data.
- Returns:
Used input attributes.
- id
- input_data
- is_outdated()
Checks if input data are more recent than this object
- last_update
- modified_at
- name
- output_data
- project
- project_id
- update_full()
Update project data.
This makes sure that
ProjectData.last_update
field is equal toProjectData.modified_at
after update and database commit. SoProjectData.is_outdated()
method works as intended.- Returns:
- class deseasion.backend.models.ProjectGlobalData(data=None, data_id=None, **kwargs)
Bases:
ProjectData
- add_input(project_data)
Add input (always fail).
- Parameters:
project_data –
- Raises:
TypeError – data doesn’t accept inputs
- create()
Persist the object in the database, with a creation, modification and last updat edate
- created_at
- data
- data_id
- data_type
- description
- id
- input_data
- is_outdated()
Checks if input data are more recent than this object
- last_update
- modified_at
- name
- output_data
- project
- project_id
- query: t.ClassVar[Query]
A SQLAlchemy query for a model. Equivalent to
db.session.query(Model)
. Can be customized per-model by overridingquery_class
.Warning
The query interface is considered legacy in SQLAlchemy. Prefer using
session.execute(select())
instead.
- class deseasion.backend.models.ProjectTaskModel(task_id, project=None, started_at=None, finished_at=None)
Bases:
ModelMixin
,Model
Save the details of a celery task.
- Attributes:
task_id (str): The id of the Celery task. started_at (datetime): When the task was started. finished_at (datetime): When the task was finished. state:
The state of the task (‘PENDING’, ‘STARTED’, ‘FAILED’ or ‘REVOKED’)
error_message (str): A description of the error if the task failed. type:
The type of task (‘process_project_data’ or ‘update_stream’).
params: The arguments used for the task. project_id: The id of the project in which this task is executed.
- error_message
- finished_at
- classmethod get_by_task_id(task_id)
Returns the first task in the database with the given task id
- id
- params
- project
- project_id
- started_at
- state
- task_id
- type
- class deseasion.backend.models.ProjectTaskType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
Bases:
Enum
- process_project_data = 1
- update_stream = 2
- class deseasion.backend.models.StreamGeoData
Bases:
object
- keywords = Column(None, ARRAY(String(), dimensions=1), table=None)
- title = Column(None, String(), table=None)
- url = Column(None, String(), table=None, nullable=False)
- version = Column(None, String(), table=None)
- class deseasion.backend.models.Template(name, manager=None, description='', extent=None, is_public=False)
Bases:
ProjectBase
Represents the template of a project.
A template does not have permissions. Only the manager of the template should have access to it.
- created_at
- data_list
- description
- extent
- classmethod from_project(project, manager=None)
Create a new project template from an existing project.
- id
- is_public
- is_template
- manager_id
- modified_at
- name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- class deseasion.backend.models.User(username, email, password=None)
Bases:
ModelMixin
,Model
Represents a user
- check_password(password)
Check if the password is correct
- check_refresh_token(refresh_token)
Checks if the refresh is saved in the database for the current user.
WARNING: Does not check the validity of the token, checks only if it exists for the current user
- Args:
refresh_token - the token to check. Can be a str or a bytes object
- create_jwt()
Create a JSON Web Token for this user
- create_refresh_token()
Creates a JSON refresh token, and associates it to the user
- email
- classmethod get_by_email(email)
- classmethod get_by_username(username)
- classmethod get_from_jwt(token)
- classmethod get_from_refresh_token(token)
- id
- password_hash
- permissions
- set_password(password)
Set the password_hash from the given password
- tokens
- username
- class deseasion.backend.models.UserPermission(**kwargs)
Bases:
ModelMixin
,Model
- ability
- id
- user
- user_id
- class deseasion.backend.models.WFSGeoData(url, feature_type, name=None, original_name=None, is_public=False, title=None, description=None, keywords=None, **kwargs)
Bases:
UploadableData
,StreamGeoData
,BaseGeoData
- attributes
- created_at
- description
- extent
- extent_filter
- feature_type
- features
- id
- is_public
- keywords
- modified_at
- name
- original_name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- title
- type
- upload_user_id
- url
- version
- class deseasion.backend.models.WMSGeoData(url, layer, name=None, original_name=None, is_public=False, title=None, description=None, keywords=None, classes=None, start=None, step=None, stop=None, **kwargs)
Bases:
UploadableData
,StreamGeoData
,BaseGeoData
- attributes
- classes
- created_at
- description
- extent
- extent_filter
- features
- id
- is_public
- keywords
- layer
- modified_at
- name
- original_name
- permissions
Create new a permissions table linking a user with an object
The table created will be called ‘<name>_permission’, with <name> being the name of the table where this mixin is used
- resolution
- start
- step
- stop
- title
- type
- upload_user_id
- url
- version
Submodules
- deseasion.backend.models.genetic_algorithm module
- deseasion.backend.models.geo_data module
- deseasion.backend.models.geo_data_utils module
- deseasion.backend.models.mixins module
- deseasion.backend.models.mrsort_inference module
- deseasion.backend.models.permission module
- deseasion.backend.models.processing_model_utils module
- deseasion.backend.models.processing_models module
- deseasion.backend.models.project module
- deseasion.backend.models.project_data module
- deseasion.backend.models.project_data_utils module
- deseasion.backend.models.share module
- deseasion.backend.models.tasks module
- deseasion.backend.models.user module