6.1. ramascene package¶
6.1.1. Subpackages¶
6.1.2. Submodules¶
6.1.3. ramascene.analyze module¶
-
class
ramascene.analyze.
Analyze
(product_calc_indices, country_calc_indices, indicator_calc_indices, querySelection, idx_units, job_name, job_id, s_country_idx, Y_data, B_data, L_data)¶ Bases:
object
This class contains the method for calculations
-
route_four
()¶ Perform calculations according to route four.
Returns: json result data Return type: json
-
route_one
()¶ Perform calculations according to route one.
Returns: json result data Return type: json
-
route_three
()¶ Perform calculations according to route three.
Returns: json result data Return type: json
-
route_two
()¶ Perform calculations according to route two.
Returns: json result data Return type: json
-
6.1.4. ramascene.consumers module¶
-
class
ramascene.consumers.
RamasceneConsumer
(scope)¶ Bases:
channels.consumer.AsyncConsumer
This class represents the Django Channels web socket interface functionality.
-
celery_message
(event)¶ Sends Celery task status.
-
websocket_connect
(event)¶ websocket first connection, accept immediately
-
websocket_disconnect
(message)¶ Websocket disconnect function.
-
6.1.5. ramascene.exceptions module¶
6.1.6. ramascene.models module¶
-
class
ramascene.models.
Country
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Country model to store identifiers for the countries and aggregations
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
code
¶ The country code
-
global_id
¶ The global id representing the application coordinates as primary id
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
identifier
¶ an identifier determining if it is a leaf node or aggregate
-
leaf_children_global
¶ the global id’s of the leafs for this continent (if available)
-
leaf_children_local
¶ the local id’s of the leafs of this country (if available)
-
level
¶ The level of hierarchy this country is in
-
local_id
¶ The local id, only used if the hierarchy level is the lowest
-
name
¶ The name of the country
-
objects
= <django.db.models.manager.Manager object>¶
-
parent_id
¶ The id representing what parent this country belongs to (by parent global_id)
-
exception
-
class
ramascene.models.
Indicator
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Indicator model to store identifiers for indicators
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
global_id
¶ The global id representing the application coordinates as primary id
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
level
¶ The level of hierarchy this indicator is in
-
local_id
¶ The local id (unusedas there are no direct summing steps performed for the extensions)
-
name
¶ The name of the indicator
-
objects
= <django.db.models.manager.Manager object>¶
-
parent_id
¶ The id representing what parent this indicator belongs to (unused as there are no direct summing steps performed for the extensions)
-
unit
¶ The unit used for the indicator
-
exception
-
class
ramascene.models.
Job
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Job model to store Celery jobs
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
celery_id
¶ The unique identifier for retrieving the results of the job from Celery
-
completed
¶ The date the Celery job was completed
-
created
¶ The date the Celery job was created
-
get_next_by_created
(*, field=<django.db.models.fields.DateTimeField: created>, is_next=True, **kwargs)¶
-
get_previous_by_created
(*, field=<django.db.models.fields.DateTimeField: created>, 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.
-
name
¶ The name of the Celery job
-
objects
= <django.db.models.manager.Manager object>¶
-
status
¶ The status of the Celery job
-
exception
-
class
ramascene.models.
Product
(*args, **kwargs)¶ Bases:
django.db.models.base.Model
Product model to store identifiers for the products and aggregations
-
exception
DoesNotExist
¶ Bases:
django.core.exceptions.ObjectDoesNotExist
-
exception
MultipleObjectsReturned
¶ Bases:
django.core.exceptions.MultipleObjectsReturned
-
code
¶ The product category code
-
global_id
¶ The global id representing the application coordinates as primary id
-
id
¶ A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
-
identifier
¶ an identifier determining if it is a leaf node or aggregate
-
leaf_children_global
¶ the global id’s of the leafs for this product group (if available)
-
leaf_children_local
¶ the local id’s of the leafs of this product group (if available)
-
level
¶ The level of hierarchy this product is in
-
local_id
¶ The local id, only used if the hierarchy level is the lowest
-
name
¶ The name of the product category
-
objects
= <django.db.models.manager.Manager object>¶
-
parent_id
¶ The id representing what parent this product belongs to (by parent global_id)
-
exception
6.1.7. ramascene.productindexmanger module¶
-
class
ramascene.productindexmanger.
ProductIndexManager
(c_prd_ids, s_cntr_ids, p_prd_ids, p_cntr_ids)¶ Bases:
object
The ProductIndexManager provides functions to translate ids of selected countries and products into ids of the combination of selected countries and products and returns ids that cab be used directly to select columns and/or rows from final demand matrices, extension matrices and leontief inverse matrix.
The selected countries and products have to be supplied when initializing the ProductIndexManager. After initialisation no changes to the supplied ids are allowed.
Parameters: - c_prd_ids – ndarray 1D array containing integers indicating the ids of selected consumed products
- s_cntr_ids – ndarray 1D array containing integers indicating the ids of the selected countries selling final products
- p_prd_ids – ndarray 1D array containing integers indicating the ids of the selected produced products
- p_cntr_ids – 1D array containing integers indicating the ids of the selected producing countries
-
get_consumed_product_ids
()¶ Get the ids of the selected consumed products
Based on the ids of the selected consumed products and the ids of the selected countries selling final products the ids of all selected products in the final demand vector are generated. It allows to make a full selection of the selected consumed products from a final demand vector. A full selection means that if the id of the product bread was selected, now the ids of bread from Italy, bread from Belgium etc are generated as long as Italy, Belgium etc are within the ids of countries selling final products. The ids are zero based.
Returns: one dimensional numpy array with ids of type int
-
get_country_count
()¶ Get the number of countries and regions in EXIOBASE
Returns: integer object with the number of countries/regions.
-
get_full_selected_c_product_count
()¶ Get the full number of consuming products selected.
Products in different countries are counted as unique items, i.e. bread from Belgium and bread from Italy consumed in a particular country are considered two items.
Returns: integer object with the full count of consumed products selected.
-
get_full_selected_p_product_count
()¶ Get the full number of produced products selected.
Products in different countries are counted as unique items, i.e. cars produced in France and cars produced in Germany are considered two items.
Returns: integer object with the full count of produced products selected.
-
get_produced_product_ids
()¶ Get the ids of the selected produced products
Based on the ids of the selected produced products and the ids of the selected producing countries the ids of all selected produced products are generated. It allows to make a full selection of the selected produced products from the output vector. A full selection means that if the id of the product car was selected, now the ids of car from Germany, car from France etc are generated as long as Germany, France etc are within the ids of selected producing countries. The ids are zero based.Returns: one dimensional numpy array with ids of type int
-
get_product_count
()¶ Get the number of products per country in EXIOBASE
Returns: integer object with the number of products.
-
get_selected_c_product_count
()¶ Get the number of consumed products selected.
Returns: integer object with the number of consumed products selected.
-
get_selected_p_country_count
()¶ Get the number of selected producing countries.
Returns: integer object with the number of producing countries selected.
-
get_selected_p_product_count
()¶ Get the number of selected produced products.
Returns: integer object with the number of produced products selected.
-
get_selected_s_country_count
()¶ Get the number of selected countries selling final products.
Returns: integer object with the number of contries selling final products selected.
6.1.8. ramascene.querymanagement module¶
-
ramascene.querymanagement.
clean_indicators
(idx_lst)¶ Clean data as preprocessing step for calculation.
Clean the selected indicator by converting to integers and applying offset of -1.
Parameters: idx_lst (list) – indicators Returns: indicators(processed) Return type: list
-
ramascene.querymanagement.
clean_local_leafs
(a_list)¶ Clean data as preprocessing step for calculation.
Clean the country or product data for calculations by splitting and converting to integers.
Parameters: a_list (str) – country or product string of coordinates separated by # Returns: country or product list of coordinates as integers Return type: list
-
ramascene.querymanagement.
clean_single_leafs
(leaf, OFFSET)¶ Clean data as preprocessing step for calculation.
Clean the country or product data for calculations by splitting, applying offset (-1) and converting to integers.
Parameters: leaf (str) – single country or product coordinate (non-processed) Returns: country or product list of coordinates (single element, processed) Return type: list
-
ramascene.querymanagement.
convert_to_numpy
(products, countries, indicators)¶ Clean data as preprocessing step for calculation.
Convert processed country,product, indicator lists to numpy array.
Parameters: Returns: numpy arrays of products, countries, indicator coordinates
Return type:
-
ramascene.querymanagement.
get_aggregations_countries
(querySelection, result_data)¶ Sum to construct aggregates results for countries.
Invoked at Celery tasks to sum values that belong to a certain aggregate.
Parameters: Returns: dicitonary of result_data, but with aggregations if there are any
Return type:
-
ramascene.querymanagement.
get_aggregations_products
(querySelection, result_data)¶ Sum to construct aggregates results for products.
Invoked at Celery tasks to sum values that belong to a certain aggregate.
Parameters: Returns: dicitonary of result_data, but with aggregations if there are any
Return type:
-
ramascene.querymanagement.
get_calc_names_country
(country_result_data)¶ Get name of countries.
Uses the database/model to fetch names, used inside calculation as conversion step
Parameters: country_result_data (dict) – key/value pair product with key as global_id Returns: key/value pair country with key as name corresponding to querySelection global_id Return type: dict
-
ramascene.querymanagement.
get_calc_names_product
(prod_result_data)¶ Get name of products.
Uses the database/model to fetch names, used inside calculation as conversion step
Parameters: prod_result_data (dict) – key/value pair product with key as global_id Returns: key/value pair product with key as name corresponding to querySelection global_id Return type: dict
-
ramascene.querymanagement.
get_leafs
(product_global_ids, country_global_ids)¶ Returns the leaf nodes of a given global id
Uses the database/model to fetch leaf nodes.
Parameters: Returns: complete list of leaf ids (minus a offset of -1 for calculation purposes)
Return type:
-
ramascene.querymanagement.
get_names
(prod_ids, country_ids, indicator_ids)¶ Get name of countries, products and indicators
Uses the database/model to fetch names, used for sending selection information to front-end
Parameters: Returns: lists of products,countries and indicators as names
Return type:
6.1.9. ramascene.tasks module¶
-
ramascene.tasks.
async_send
(channel_name, job)¶ Send job message to front-end.
uses the channel_name and Job object. Send success or failure status.
Parameters:
-
ramascene.tasks.
calcOneHandler
(job_name, job_id, channel_name, ready_querySelection, querySelection)¶ invokes Celery function.
Handler for invoking Celery method.
Parameters: - job_name (str) – the name of the job
- job_id (int) – the id of the job
- channel_name (object) – the websocket channel name
- ready_querySelection (dict) – the querySelection preprocessed (only needs convertion to numpy array)
- querySelection (dict) – the original querySelection used for aggregations at later stage
-
ramascene.tasks.
job_update
(job_id)¶ Update job status to completion.
Update the job status by reference job id. :param job_id: job id :type job_id: int
6.1.10. ramascene.views module¶
-
ramascene.views.
ajaxHandling
(request)¶ AJAX handler.
Checks if the request is a post. Uses from the request the task/job id to fetch the Celery unique identifier. In turn it retrieves by using the Celery unique identifier the actual results
Parameters: object – request Returns: JSON response of result calculation
-
ramascene.views.
home
(request)¶