API Views¶
API Views related to data table.
DataTableAPIView ¶
Bases: APIView
API view for retrieving data table reports.
get ¶
Handle GET request to retrieve data table reports. Params: request (Request) The HTTP request object.
get_queryset ¶
get_taxon_queryset ¶
post ¶
Handle POST request to retrieve data table reports. Params: request (Request) The HTTP request object.
process_request ¶
Handle request to retrieve data table reports. Params: request (Request) The HTTP request object.
Source code in django_project/frontend/api_views/data_table.py
API Views related to map.
AerialTile ¶
Bases: APIView
Proxy for aerial map.
get ¶
Retrieve aerial by x, y, z.
Source code in django_project/frontend/api_views/map.py
DefaultPropertiesLayerMVTTiles ¶
Bases: MapSessionBase
, LayerMVTTilesBase
Dynamic Vector Tile for properties layer based on active org.
generate_queries_for_map_default ¶
Generate layer queries for vector tile using active organisation.
Possible layers: properties, properties-point.
Source code in django_project/frontend/api_views/map.py
get_default_properties_layer_query ¶
Generate SQL query for properties/points using active org.
Source code in django_project/frontend/api_views/map.py
FindParcelByCoord ¶
FindPropertyByCoord ¶
Bases: APIView
Find property that contains coordinate.
LayerMVTTilesBase ¶
Bases: APIView
Base class for generating dynamic VT.
generate_tile ¶
Execute sql to generate vector tile bytes array.
Source code in django_project/frontend/api_views/map.py
get_mvt_sql ¶
Generate ST_MVT sql for single query.
Source code in django_project/frontend/api_views/map.py
gzip_tile ¶
Apply gzip to vector tiles bytes.
MapAuthenticate ¶
Bases: APIView
Check against the token of user.
get ¶
Return success 200, so nginx can cache the auth result.
Source code in django_project/frontend/api_views/map.py
MapSessionBase ¶
Bases: APIView
Base class for map filter session.
generate_session ¶
Generate map filter session from POST data.
Session will have expiry in 6 hours after creation and this expiry date is updated when the session filter is changed.
Source code in django_project/frontend/api_views/map.py
get_current_session_or_404 ¶
Retrieve map filter session or return 404.
Source code in django_project/frontend/api_views/map.py
get_map_query_type ¶
Check map query type: default (by active org) or filter session.
Source code in django_project/frontend/api_views/map.py
MapStyles ¶
Bases: MapSessionBase
Fetch map styles.
get ¶
Retrieve map styles.
Source code in django_project/frontend/api_views/map.py
PopulationCountLegends ¶
SessionPropertiesLayerMVTTiles ¶
Bases: MapSessionBase
, LayerMVTTilesBase
Dynamic Vector Tile for properties layer based on filter session.
generate_queries_for_map_session ¶
Generate layer queries for vector tiles using filter session.
Possible layers: province_population, properties, properties-point.
Source code in django_project/frontend/api_views/map.py
get_properties_layer_query ¶
Generate SQL query for properties/points using filter session.
Source code in django_project/frontend/api_views/map.py
get_province_layer_query ¶
Generate SQL query for province layer using filter session.
Source code in django_project/frontend/api_views/map.py
should_generate_layer ¶
API Views related to metrics.
ActivityPercentageAPIView ¶
Bases: APIView
API view to retrieve activity percentage data for species.
get ¶
Handle the GET request to retrieve activity percentage data. Params: request (Request): The HTTP request object.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
Returns a filtered queryset of Taxon objects representing species within the specified organisation.
Source code in django_project/frontend/api_views/metrics.py
BasePropertyCountAPIView ¶
Bases: APIView
Base class for property count APIView
get_queryset ¶
Returns a filtered queryset of Taxon objects
Source code in django_project/frontend/api_views/metrics.py
PopulationPerAgeGroupAPIView ¶
Bases: APIView
API endpoint to retrieve population of age group.
get ¶
Handle the GET request to retrieve population of age groups. Params:request (Request): The HTTP request object.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
Get the filtered queryset taxon owned by the organisation.
Source code in django_project/frontend/api_views/metrics.py
PropertiesPerPopulationCategoryAPIView ¶
Bases: APIView
API endpoint to retrieve population categories for properties within an organisation.
get ¶
Handle GET request to retrieve population categories for properties.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
Get the filtered queryset of properties owned by the organisation.
Source code in django_project/frontend/api_views/metrics.py
PropertyCountPerAreaCategoryAPIView ¶
Bases: BasePropertyCountAPIView
API endpoint to property count per area category
get ¶
Handle GET request to retrieve property count per area category.
Source code in django_project/frontend/api_views/metrics.py
PropertyCountPerPopulationSizeCategoryAPIView ¶
Bases: BasePropertyCountAPIView
API endpoint to property count per population size category
get ¶
Handle GET request to retrieve property count per population size category.
Source code in django_project/frontend/api_views/metrics.py
PropertyPerAreaAvailableCategoryAPIView ¶
Bases: BasePropertyCountAPIView
API endpoint to property count per area available to species category
get ¶
Handle GET request to retrieve property count per area available to species category.
Source code in django_project/frontend/api_views/metrics.py
PropertyPerPopDensityCategoryAPIView ¶
Bases: BasePropertyCountAPIView
API endpoint to property count per population density category
get ¶
Handle GET request to retrieve property count per population density category.
Source code in django_project/frontend/api_views/metrics.py
SpeciesPopulationCountPerProvinceAPIView ¶
Bases: APIView
API view to retrieve species pcount per province.
get ¶
Handle GET request to retrieve species count per province.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
SpeciesPopulationCountPerYearAPIView ¶
Bases: APIView
An API view to retrieve species population count per year.
get ¶
Handles HTTP GET requests and returns a serialized JSON response. Params: The HTTP request object containing the user's request data.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
Returns a filtered queryset of Taxon objects representing species within the specified organisation.
Source code in django_project/frontend/api_views/metrics.py
SpeciesPopulationDensityPerPropertyAPIView ¶
Bases: APIView
API view to retrieve species population density per property.
get ¶
Handle the GET request to retrieve species population density per property. Params:request (Request): The HTTP request object.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
Returns a filtered queryset of property objects within the specified organisation.
Source code in django_project/frontend/api_views/metrics.py
TotalAreaAvailableToSpeciesAPIView ¶
Bases: APIView
An API view to retrieve total area available to species.
get ¶
Retrieve the calculated total area available to species and return it as a Response.
Source code in django_project/frontend/api_views/metrics.py
TotalAreaPerPropertyTypeAPIView ¶
Bases: APIView
API endpoint to retrieve total area per property type for properties within an organisation.
get ¶
Handle GET request to retrieve total area per property type.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
Get the filtered queryset of properties owned by the organisation.
Source code in django_project/frontend/api_views/metrics.py
TotalCountPerActivityAPIView ¶
Bases: APIView
API view to retrieve total counts per activity for species.
get ¶
Handle the GET request to retrieve total counts per activity data. Params:request (Request): The HTTP request object.
Source code in django_project/frontend/api_views/metrics.py
get_queryset ¶
Returns a filtered queryset of Taxon objects representing species within the specified organisation.
Source code in django_project/frontend/api_views/metrics.py
TotalCountPerPopulationEstimateAPIView ¶
Bases: APIView
API view to retrieve total counts per population estimate category for species.
API Views related to uploading population data.
CanWritePopulationData ¶
Bases: APIView
API to check whether user can update the data.
can_overwrite_data ¶
Check if user is able to overwrite annual_population record.
Source code in django_project/frontend/api_views/population.py
DeletePopulationAPIView ¶
Bases: APIView
API to remove population data by id.
DraftPopulationUpload ¶
Bases: APIView
API to fetch draft list and save as draft.
FetchDraftPopulationUpload ¶
Bases: APIView
API to fetch draft upload.
FetchPopulationData ¶
Bases: APIView
Fetch existing annual population data.
PopulationMeanSDChartApiView ¶
Bases: BasePropertyCountAPIView
API view for calculating and presenting statistical data related to population means and standard deviations (SD) based on different age classes.
age_group_by_property_type ¶
Organizes and calculates percentage distribution of age classes by property type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
property_type |
PropertyType
|
The property type for which data is organized. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary with percentage distributions for each age class, organized by year and property type. |
Source code in django_project/frontend/api_views/population.py
calculate_percentage ¶
Calculates the percentage of male and female populations in a given age class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
annual_population |
AnnualPopulation
|
object representing annual population data. |
required |
age_class |
str
|
age class for which the percentage calculation is done. |
required |
Returns:
Type | Description |
---|---|
dict
|
dictionary with percentage values for males and females in the specified age class. |
Source code in django_project/frontend/api_views/population.py
calculate_sd_and_mean ¶
Aggregates mean and standard deviation calculations across all age classes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
A dictionary containing detailed population data segregated by age classes. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary with aggregated mean and SD values for each age class and gender. |
Source code in django_project/frontend/api_views/population.py
calculate_sd_and_mean_by_age_class ¶
Calculates the mean and standard deviation (SD) for male and female data within a specified age class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
A dictionary containing population data. |
required | |
age_class |
str
|
The age class for which calculations are performed. |
required |
Source code in django_project/frontend/api_views/population.py
get ¶
Handle GET request
Source code in django_project/frontend/api_views/population.py
PopulationMetadataList ¶
Bases: APIView
Get metadata for uploading population.
UploadPopulationAPIVIew ¶
API Views related to property.
CheckPropertyNameIsAvailable ¶
Bases: APIView
Validate if property name is available.
CreateNewProperty ¶
ListPropertyTypeAPIView ¶
Bases: APIView
API to list Property Type
ListProvince ¶
Bases: APIView
API to list Property Type
PropertyDetail ¶
Bases: APIView
Fetch property detail.
PropertyList ¶
Bases: APIView
Get properties that the current user owns.
PropertyMetadataList ¶
Bases: APIView
Get metadata for property: type, organisation, province.
PropertySearch ¶
Bases: APIView
Search property and roads.
UpdatePropertyBoundaries ¶
UpdatePropertyInformation ¶
API Views for uploading file.
BoundaryFileGeoJson ¶
Bases: APIView
Get geojson from search request.
BoundaryFileList ¶
Bases: APIView
Retrieve Uploaded Boundary Files.
BoundaryFileRemove ¶
Bases: APIView
Remove Boundary File.
BoundaryFileSearch ¶
Bases: APIView
Find parcel by boundary files.
BoundaryFileSearchStatus ¶
Bases: APIView
Check status search parcel by boundary files.
BoundaryFileUpload ¶
Bases: APIView
Upload Boundary File.
NationalActivityCountPerPropertyView ¶
Bases: APIView
API to retrieve activity count as % of the the total population per property type
get ¶
Handle GET request to retrieve population categories for properties.
get_activity_count ¶
Get activity count of the total population as percentage
Source code in django_project/frontend/api_views/national_statistic.py
NationalActivityCountPerProvinceView ¶
Bases: APIView
API to retrieve activity count as % of the the total population for per province
get ¶
Handle GET request to retrieve population categories for properties.
get_activity_count ¶
Get activity count of the total population as percentage
Source code in django_project/frontend/api_views/national_statistic.py
NationalActivityCountView ¶
Bases: APIView
API to retrieve activity count as % of the the total population for each species
get ¶
Handle GET request to retrieve population categories for properties.
get_activity_count ¶
Get activity count of the total population as percentage
Source code in django_project/frontend/api_views/national_statistic.py
NationalPropertiesView ¶
Bases: APIView
An API view to retrieve the statistics for the national report.
get ¶
Handle GET request to retrieve population categories for properties.
Source code in django_project/frontend/api_views/national_statistic.py
get_properties_per_population_category ¶
Get the filtered queryset of properties owned by the organisation.
Source code in django_project/frontend/api_views/national_statistic.py
NationalSpeciesView ¶
Bases: APIView
An API view to retrieve the statistics for the national report.
NationalStatisticsView ¶
Bases: APIView
An API view to retrieve the statistics for the national report.
get ¶
Handles the request and returns a serialized JSON response.
Source code in django_project/frontend/api_views/national_statistic.py
get_statistics ¶
This method calculates the property count, total property area, and total property area available for species (national).
Source code in django_project/frontend/api_views/national_statistic.py
SpatialFilterList ¶
Bases: LoginRequiredMixin
, APIView
A view that returns a list of layers marked as spatial filters.
get ¶
Handles the GET request and returns the list of spatial filter layers
Source code in django_project/frontend/api_views/spatial_filter.py
API Views related to statistical.
DownloadTrendDataAsJson ¶
SpeciesNationalTrend ¶
Bases: APIView
Fetch national trend of species.
SpeciesTrend ¶
Bases: SpeciesNationalTrend
Fetch trend of species.
Returns: Response: JSON response containing trend data.
Filters¶
Filters in Data table.
DataContributorsFilter ¶
Bases: FilterSet
filter_property ¶
Filter queryset by given property Params: queryset (QuerySet): The queryset to be filtered. name (str): The name of the property to filter by. value (str): A comma-separated list of property IDs.
Source code in django_project/frontend/filters/data_table.py
Filters in metrics.
ActivityBaseMetricsFilter ¶
Bases: BaseMetricsFilter
Filter the queryset based on the start year and end year of activity data. Params: queryset (QuerySet): The base queryset of Taxon model. value (str): The start year of the annual population. name (str): The name of the field to be filtered (property).
BaseMetricsFilter ¶
Bases: FilterSet
Filter class for metrics based on species, start year, and property.
filter_organisation ¶
Filter organisation based on annual population.
Params: queryset (QuerySet): The base queryset of Taxon model. value (str): Comma-separated property IDs. name (str): The name of the field to be filtered (organisation).
Source code in django_project/frontend/filters/metrics.py
filter_property ¶
Filter properties based on annual population.
Params: queryset (QuerySet): The base queryset of Taxon model. value (str): Comma-separated property IDs. name (str): The name of the field to be filtered (property).
Source code in django_project/frontend/filters/metrics.py
filter_species ¶
Filter species based on common_name_verbatim.
Params: queryset (QuerySet): The base queryset of Taxon model. value (str): Comma-separated species names. name (str): The name of the field to be filtered (property).
Source code in django_project/frontend/filters/metrics.py
filter_start_year ¶
Filter annual populations based on range from start_year to end_year.
Params: queryset (QuerySet): The base queryset of Taxon model. value (str): The start year of the annual population. name (str): The name of the field to be filtered (property).
Source code in django_project/frontend/filters/metrics.py
PropertyFilter ¶
Bases: FilterSet
A custom filter for filtering Property objects based on a comma-separated list of property IDs.
filter_property ¶
Custom filter method to filter properties by their IDs. params: queryset (QuerySet): The initial queryset of Property objects. name (str): The name of the field to be filtered (property). value (str): A comma-separated list of property IDs.
Source code in django_project/frontend/filters/metrics.py
filter_start_year ¶
Filter property based on range from start_year to end_year.
Params: queryset (QuerySet): The base queryset of Taxon model. value (str): The start year of the annual population. name (str): The name of the field to be filtered (property).
Source code in django_project/frontend/filters/metrics.py
Models¶
Base model for task.
Classes for map filter session.
MapSession ¶
Bases: Model
Store session for map.
Classes for Statistical R Model.
OutputTypeCategoryIndex ¶
Bases: Model
Define a sort index for output type of categories.
OutputTypeCategoryIndexManager ¶
Bases: Manager
Manager class for output type category index.
SpeciesModelOutput ¶
Bases: BaseTaskRequest
Store statistical model output for a species.
StatisticalModel ¶
Bases: Model
Model that stores R code of statistical model.
StatisticalModelOutput ¶
Bases: Model
Output of statistical model.
Views¶
AboutView ¶
Bases: OrganisationBaseView
AboutView displays the about page by rendering the 'about.html' template.
OrganisationBaseView ¶
Bases: TemplateView
Base view to provide organisation context
RegisteredOrganisationBaseView ¶
Bases: LoginRequiredMixin
, OrganisationBaseView
Base view to provide organisation context for logged-in users.
get_user_notifications ¶
Method checks if there are new notifications to send the user, these notifications are updated from stakeholder.tasks.
Source code in django_project/frontend/views/base_view.py
validate_user_permission ¶
Check if user has permission to upload data.
ContactUsView ¶
HelpView ¶
HomeView ¶
MapView ¶
Bases: RegisteredOrganisationBaseView
MapView displays the map page by rendering the 'map.html' template.
OnlineFormView ¶
View to switch organisation.
switch_organisation ¶
Switch organisation.
Source code in django_project/frontend/views/switch_organisation.py
OrganisationUsersView ¶
Bases: RegisteredOrganisationBaseView
, TemplateView
OrganisationUsersView displays the organisations users page by rendering the 'users.html' template.
is_new_invitation ¶
Check if an entry with the given email and organisation already exists. Returns True if exists, False otherwise.
Source code in django_project/frontend/views/users.py
OrganisationsView ¶
Bases: RegisteredOrganisationBaseView
, TemplateView
OrganisationsView displays the organisations the user can access.
Serializers¶
Serializer for BoundaryFile model.
BoundaryFileSerializer ¶
Bases: ModelSerializer
Serializer for BoundaryFile.
Base serializer for common classes.
NameObjectBaseSerializer ¶
Bases: ModelSerializer
Base Serializer for object with id and name.
ActivityMatrixSerializer ¶
Bases: ModelSerializer
Serializer class for serializing activity percentage data for species.
get_activities ¶
Calculate activity percentage data for species. Params: obj (Taxon): The Taxon instance.
Source code in django_project/frontend/serializers/metrics.py
get_species_name ¶
get_total ¶
Get the total count of species. Params: obj (Taxon): The Taxon instance.
Source code in django_project/frontend/serializers/metrics.py
AnnualPopulationSerializer ¶
Bases: ModelSerializer
Serializer class for serializing AnnualPopulation.
PopulationPerAgeGroupSerialiser ¶
Bases: ModelSerializer
Serializer class for serializing population per age group.
get_age_group ¶
Calculate population per age group. Params: obj (Taxon): The Taxon instance.
Source code in django_project/frontend/serializers/metrics.py
SpeciesPopuationCountPerYearSerializer ¶
Bases: ModelSerializer
Serializer class for serializing population count per year for a species.
get_annualpopulation_count ¶
Get the population count per year for the species. Params: obj (Taxon): The Taxon instance representing the species.
Source code in django_project/frontend/serializers/metrics.py
get_species_colour ¶
Get the color of the species. Params: obj (Taxon): The Taxon instance representing the species.
get_species_name ¶
Get the common name of the species. Params: obj (Taxon): The Taxon instance representing the species.
SpeciesPopulationDensityPerPropertySerializer ¶
Bases: ModelSerializer
Serializer class for serializing species population total and density.
TotalCountPerActivitySerializer ¶
Bases: ModelSerializer
Serializer class for serializing the total count per activity data.
get_activities ¶
Calculate total count per activity for species. Params: obj (Taxon): The Taxon instance.
Source code in django_project/frontend/serializers/metrics.py
get_species_name ¶
get_total ¶
Get the total count of species. Params: obj (Taxon): The Taxon instance.
Source code in django_project/frontend/serializers/metrics.py
TotalCountPerPopulationEstimateSerializer ¶
Bases: Serializer
get_total_counts_per_population_estimate ¶
Retrieves and calculates the total counts per population estimate category.
This function filters AnnualPopulation records based on the provided parameters (species_name, property_ids). It then iterates through the filtered records and calculates the total counts per population estimate category, along with the most recent year and total sums associated with each category.
Returns: - result (dict): A dictionary containing total counts per population estimate category. Each category includes count, years, total, and percentage.
Source code in django_project/frontend/serializers/metrics.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|
SpeciesListSerializer ¶
Bases: ModelSerializer
Serializer class for serializing species.
get_annualpopulation_count ¶
Get the population count per year for the species. Params: obj (Taxon): The Taxon instance representing the species.
Source code in django_project/frontend/serializers/national_statistics.py
get_species_colour ¶
Get the color of the species. Params: obj (Taxon): The Taxon instance representing the species.
get_species_icon ¶
Get the icon of the species. Params: obj (Taxon): The Taxon instance representing the species.
get_species_name ¶
Get the common name of the species. Params: obj (Taxon): The Taxon instance representing the species.
Serializer for place classes.
PlaceBaseSearchSerializer ¶
Bases: ModelSerializer
Return id, name, bbox of place.
Serializer for property classes.
ParcelSerializer ¶
Bases: ModelSerializer
Parcel Serializer.
PropertyDetailSerializer ¶
PropertySearchSerializer ¶
PropertySerializer ¶
Bases: ModelSerializer
Property Serializer.
PropertyTypeColourSerializer ¶
Bases: ModelSerializer
Property Type Serializer with Colour.
PropertyTypeSerializer ¶
Bases: NameObjectBaseSerializer
Property Type Serializer.
ProvinceSerializer ¶
Bases: NameObjectBaseSerializer
Province Serializer.
ActivityReportSerializer ¶
Bases: ModelSerializer
, BaseReportSerializer
Serializer for Activity Report. The serializer uses dynamic column based on the selected activity.
Source code in django_project/frontend/serializers/report.py
BaseReportSerializer ¶
Bases: Serializer
Base Serializer for Report.
BaseSpeciesReportSerializer ¶
Bases: ModelSerializer
, BaseReportSerializer
Serializer for Species Report (for exporting to csv/excel).
PropertyReportSerializer ¶
SamplingReportSerializer ¶
SpeciesReportSerializer ¶
Tasks¶
Task to generate statistical model for a species.
add_json_area_available_growth ¶
Generate area available vs total area data.
Source code in django_project/frontend/tasks/generate_statistical_model.py
add_json_metadata ¶
Generate metadata for category values sorted by OutputTypeCategoryIndex.
Source code in django_project/frontend/tasks/generate_statistical_model.py
calculate_area_diff ¶
Compare property dict with the current year property dict.
Source code in django_project/frontend/tasks/generate_statistical_model.py
check_affected_model_output ¶
Triggered when model is created/updated.
Source code in django_project/frontend/tasks/generate_statistical_model.py
check_oudated_model_output ¶
Check for outdated model output and trigger a job to generate.
CSV Data Upload Flow: CSV Upload -> List of species -> mark latest model output as outdated
Online Form Flow: Input data for a species -> mark latest model output as outdated
R Code Update: StatisticalModel Update -> mark latest model output as outdated -> restart plumber -> Plumber ready -> trigger check_oudated_model_output manually
R Code Create: StatisticalModel Create -> create model output with outdated=True -> restart plumber -> Plumber ready -> trigger check_oudated_model_output manually
This check_outdated_model_output will check every model output that needs to be refreshed.
Source code in django_project/frontend/tasks/generate_statistical_model.py
clean_old_model_output ¶
Remove old model output that has more recent model.
Source code in django_project/frontend/tasks/generate_statistical_model.py
export_annual_population_data ¶
Export annual population to csv data.
Source code in django_project/frontend/tasks/generate_statistical_model.py
generate_species_statistical_model ¶
Generate species statistical model.
Source code in django_project/frontend/tasks/generate_statistical_model.py
save_model_data_input ¶
Store csv data of annual population data.
Source code in django_project/frontend/tasks/generate_statistical_model.py
save_model_output_on_failure ¶
Store failure from execution R statistical model.
Source code in django_project/frontend/tasks/generate_statistical_model.py
save_model_output_on_success ¶
Store the result from successful execution of R statistical model.
Source code in django_project/frontend/tasks/generate_statistical_model.py
sort_output_type_categories ¶
Sort set of categories by OutputTypeCategoryIndex list.
Source code in django_project/frontend/tasks/generate_statistical_model.py
trigger_generate_species_model_output ¶
Trigger generate species model output job.
Source code in django_project/frontend/tasks/generate_statistical_model.py
resume_ongoing_vector_tile_task ¶
Resume any ongoing vector tile task.
This should be called at startup.
Source code in django_project/frontend/tasks/generate_vector_tile.py
clear_expired_map_session ¶
Clear expired map session.
This job will be run every 2 hours.
Source code in django_project/frontend/tasks/map_session.py
patch_province_in_properties ¶
Patch province field in properties.
Source code in django_project/frontend/tasks/patch_province.py
start_plumber_process ¶
Start plumber process when there is R code change.
Source code in django_project/frontend/tasks/start_plumber.py
Tests¶
Model factories for frontend.
BoundaryFileF ¶
Bases: DjangoModelFactory
Factory for BoundaryFile.
Meta ¶
Meta class Factory for BoundaryFile Model.
ContextLayerF ¶
Bases: DjangoModelFactory
Factory for ContextLayer Model.
Meta ¶
Meta class Factory for ContextLayer Model.
ContextLayerLegendF ¶
Bases: DjangoModelFactory
Factory for ContextLayerLegend Model.
Meta ¶
Meta class Factory for ContextLayerLegend Model.
FarmPortionF ¶
Bases: DjangoModelFactory
Factory for FarmPortion Model.
Meta ¶
Meta class Factory for FarmPortion Model.
HoldingF ¶
LayerF ¶
Bases: DjangoModelFactory
Factory for Layer Model
ParentFarmF ¶
Bases: DjangoModelFactory
Factory for ParentFarm Model.
Meta ¶
Meta class Factory for ParentFarm Model.
SpatialDataModelF ¶
Bases: DjangoModelFactory
Factor for SpatialData model
SpatialDataModelValueF ¶
Bases: DjangoModelFactory
Factor for SpatialDataModelValue model
SpeciesModelOutputF ¶
Bases: DjangoModelFactory
Factory for SpeciesModelOutput Model.
Meta ¶
Meta class Factory for SpeciesModelOutput Model.
StatisticalModelF ¶
Bases: DjangoModelFactory
Factory for StatisticalModel Model.
Meta ¶
Meta class Factory for StatisticalModel Model.
StatisticalModelOutputF ¶
Bases: DjangoModelFactory
Factory for StatisticalModelOutput Model.
Meta ¶
Meta class Factory for StatisticalModelOutput Model.
AnnualPopulationTestCase ¶
Bases: AnnualPopulationTestMixins
, TestCase
test_data_table_activity_report ¶
Test data table activity report
Source code in django_project/frontend/tests/test_data_table.py
test_data_table_filter_by_activity_type ¶
Test data table filter by activity type
Source code in django_project/frontend/tests/test_data_table.py
test_data_table_filter_by_no_activity ¶
Test data table filter without specifying any activity. It will return all data.
Source code in django_project/frontend/tests/test_data_table.py
test_data_table_filter_by_species_name ¶
Test data table filter by species name
Source code in django_project/frontend/tests/test_data_table.py
test_data_table_post ¶
Test data table with post request
Source code in django_project/frontend/tests/test_data_table.py
test_data_table_sampling_report ¶
Test data table sampling report
Source code in django_project/frontend/tests/test_data_table.py
test_filter_by_property ¶
Test data table filter by property
Source code in django_project/frontend/tests/test_data_table.py
test_filter_by_year_and_report ¶
Test data table filter by year and report
Source code in django_project/frontend/tests/test_data_table.py
test_filter_without_property ¶
Test data table filter without property
Source code in django_project/frontend/tests/test_data_table.py
test_show_all_reports ¶
Test showing report for a species.
Source code in django_project/frontend/tests/test_data_table.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
DataScientistTestCase ¶
Bases: TestCase
setUp ¶
Setup test case
Source code in django_project/frontend/tests/test_data_table.py
test_regional_data_scientist ¶
Test data table filter by regional data scientist
Source code in django_project/frontend/tests/test_data_table.py
DownloadDataDataConsumerTestCase ¶
Bases: AnnualPopulationTestMixins
, TestCase
Test Case for download data
test_download_all_reports_by_all_activity_type ¶
Test download data table filter by activity name
Source code in django_project/frontend/tests/test_data_table.py
test_download_one_report ¶
Test download data table with only one report
Source code in django_project/frontend/tests/test_data_table.py
test_download_xlsx_data_all_reports_by_all_activity_type ¶
Test download data table filter by activity name
Source code in django_project/frontend/tests/test_data_table.py
test_path_not_exist ¶
Test download data table when file path does not exist
Source code in django_project/frontend/tests/test_data_table.py
DownloadDataTestCase ¶
Bases: AnnualPopulationTestMixins
, TestCase
Test Case for download data
test_download_all_reports_by_all_activity_type ¶
Test download data table filter by activity name
Source code in django_project/frontend/tests/test_data_table.py
test_download_xlsx_data_all_reports_by_all_activity_type ¶
Test download data table filter by activity name
Source code in django_project/frontend/tests/test_data_table.py
test_download_xlsx_data_all_reports_without_activity_filter ¶
Test download data table filter by activity name
Source code in django_project/frontend/tests/test_data_table.py
NationalUserTestCase ¶
Bases: TestCase
setUp ¶
Setup test case
Source code in django_project/frontend/tests/test_data_table.py
test_national_activity_report_all_activity ¶
Test activity report for national data consumer
Source code in django_project/frontend/tests/test_data_table.py
test_national_property_report_all_activity ¶
Test property report for national data consumer
Source code in django_project/frontend/tests/test_data_table.py
test_national_province_report_all_activity ¶
Test property report for national data consumer
Source code in django_project/frontend/tests/test_data_table.py
test_national_species_report_all_activity ¶
Test species report for national data consumer
Source code in django_project/frontend/tests/test_data_table.py
test_national_user_reports ¶
Test national data consumer reports
Source code in django_project/frontend/tests/test_data_table.py
RegionalUserTestCase ¶
Bases: TestCase
setUp ¶
Setup test case
Source code in django_project/frontend/tests/test_data_table.py
test_has_province_data ¶
Test data table filter by regional data consumer. The response would not be empty since there are Annual Population data for the user's organisation's province.
Source code in django_project/frontend/tests/test_data_table.py
test_no_province_data ¶
Test data table filter by regional data consumer. The response would be empty since there are no Annual Population data for the user's organisation's province.
Source code in django_project/frontend/tests/test_data_table.py
Test Frontend Models.
TestUploadSpeciesCSV ¶
Bases: TestCase
Test upload species csv model.
test_create_new_upload_species_csv ¶
Test creating new upload species csv.
Source code in django_project/frontend/tests/test_frontend_models.py
test_delete_upload_species_csv ¶
Test deleting upload species csv.
Source code in django_project/frontend/tests/test_frontend_models.py
test_update_upload_species_csv ¶
Test updating a upload species csv.
Source code in django_project/frontend/tests/test_frontend_models.py
ActivityPercentageTestCase ¶
Bases: BaseTestCase
Test the activity percentage API endpoint.
setUp ¶
test_activity_percentage ¶
Test activity percentage calculation.
Source code in django_project/frontend/tests/test_metrics.py
test_activity_percentage_filter_by_year ¶
Test activity percentage calculation with year-based filters.
Source code in django_project/frontend/tests/test_metrics.py
BaseTestCase ¶
Bases: TestCase
setUp ¶
Set up test data and environment for the test cases.
This method creates necessary test objects like TaxonRank, Taxon, User, Organisation, Property, and AnnualPopulation. It also sets up the client and session for testing.
Source code in django_project/frontend/tests/test_metrics.py
PopulationEstimateCategoryTestCase ¶
Bases: BaseTestCase
This is to test if the API is reachable and returns a success response.
PopulationPerAgeGroupTestCase ¶
Bases: BaseTestCase
Test case for the endpoint that retrieves population per age group.
setUp ¶
test_species_population_count_filter_by_year ¶
Test spopulation per age group filtered by year.
Source code in django_project/frontend/tests/test_metrics.py
test_total_area_per_property_type ¶
Test population per age group
Source code in django_project/frontend/tests/test_metrics.py
test_total_area_per_property_type_filter_by_property ¶
Test population per age group filtered by property.
Source code in django_project/frontend/tests/test_metrics.py
PropertiesPerPopulationCategoryTestCase ¶
Bases: BaseTestCase
Test case for the endpoint that retrieves properties population categories.
setUp ¶
test_properties_per_population_category ¶
Test properties per population category.
Source code in django_project/frontend/tests/test_metrics.py
SpeciesPopuationCountPerProvinceTestCase ¶
Bases: BaseTestCase
This is to test if the API is reachable and returns a success response.
SpeciesPopuationCountPerYearTestCase ¶
Bases: BaseTestCase
Test the species population count API endpoint.
setUp ¶
test_species_population_count ¶
Test species population count.
Source code in django_project/frontend/tests/test_metrics.py
test_species_population_count_filter_by_name ¶
Test species population count filtered by species name.
Source code in django_project/frontend/tests/test_metrics.py
test_species_population_count_filter_by_property ¶
Test species population count filtered by property.
Source code in django_project/frontend/tests/test_metrics.py
test_species_population_count_filter_by_year ¶
Test species population count filtered by year.
Source code in django_project/frontend/tests/test_metrics.py
SpeciesPopulationDensityPerPropertyTestCase ¶
Bases: BaseTestCase
Test the species population total density API endpoint.
setUp ¶
test_species_population_density_filter_by_year ¶
Test species population density per property filtered by year.
Source code in django_project/frontend/tests/test_metrics.py
test_species_population_density_per_property ¶
Test species population density per property.
Source code in django_project/frontend/tests/test_metrics.py
TestPropertyCountPerAreaAvailableToSpeciesCategory ¶
Bases: TestPropertyCountPerCategoryMixins
, BaseTestCase
Test case for the endpoint that retrieves property count per area available to species category.
setUp ¶
test_filter ¶
Test filtered total property count per area available to species category.
Source code in django_project/frontend/tests/test_metrics.py
TestPropertyCountPerAreaCategory ¶
Bases: TestPropertyCountPerCategoryMixins
, BaseTestCase
Test case for the endpoint that retrieves property count per area category.
setUp ¶
test_filter ¶
Test filtered total property count per area category.
Source code in django_project/frontend/tests/test_metrics.py
TestPropertyCountPerCategoryMixins ¶
test_empty_result ¶
Test empty result when there is no data.
Source code in django_project/frontend/tests/test_metrics.py
TestPropertyCountPerPopulationDensityCategory ¶
Bases: TestPropertyCountPerCategoryMixins
, BaseTestCase
Test case for the endpoint that retrieves property count per population density category.
setUp ¶
test_filter ¶
Test filtered total property count per population density category.
Source code in django_project/frontend/tests/test_metrics.py
TestPropertyCountPerPopulationSizeCategory ¶
Bases: TestPropertyCountPerCategoryMixins
, BaseTestCase
Test case for the endpoint that retrieves property count per population size category.
setUp ¶
Set up the test case.
Source code in django_project/frontend/tests/test_metrics.py
test_filter ¶
Test filtered total property count per population category.
Source code in django_project/frontend/tests/test_metrics.py
test_lower_bound_negative ¶
Test negative lower bound.
Source code in django_project/frontend/tests/test_metrics.py
test_lower_bound_zero ¶
Test zero lower bound.
Source code in django_project/frontend/tests/test_metrics.py
test_with_activity_spatial_filters ¶
Test filtered total property count per population category.
Source code in django_project/frontend/tests/test_metrics.py
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 |
|
TotalAreaAvailableToSpeciesTestCase ¶
Bases: BaseTestCase
Test case for the endpoint that retrieves total area available to species.
setUp ¶
test_total_area_available_to_species ¶
Test total area available to species.
Source code in django_project/frontend/tests/test_metrics.py
test_total_area_available_to_species_filter_by_property ¶
Test total area available to species filtered by property.
Source code in django_project/frontend/tests/test_metrics.py
TotalAreaPerPropertyTypeTestCase ¶
Bases: BaseTestCase
Test case for the endpoint that retrieves total area per property type.
setUp ¶
test_total_area_per_property_type ¶
Test total area per property type
Source code in django_project/frontend/tests/test_metrics.py
test_total_area_per_property_type_filter_by_property ¶
Test total area per property type filtered by property.
Source code in django_project/frontend/tests/test_metrics.py
TotalCountPerActivityTestCase ¶
Bases: BaseTestCase
Test the total count per activity API endpoint.
setUp ¶
Set up the test case.
test_total_count_per_activity ¶
Test total count per activity calculation.
Source code in django_project/frontend/tests/test_metrics.py
TestOrganisationAPIView ¶
Bases: TestCase
test_organisation_list ¶
Test organisation for organisation member
Source code in django_project/frontend/tests/test_organisations.py
test_organisation_list_for_national ¶
Test organisation for national roles
Source code in django_project/frontend/tests/test_organisations.py
test_organisation_list_for_provincial ¶
Test organisation for provincial roles
Source code in django_project/frontend/tests/test_organisations.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
TestPropertyAPIViews ¶
Bases: TestCase
test_get_property_list_for_organisations ¶
Taxon list API test for organisations.
Source code in django_project/frontend/tests/test_property.py
test_property_list_multiple_organisations_data_contributor ¶
Test property list for data contributor, which will only return property directly related to their current organisation.
Source code in django_project/frontend/tests/test_property.py
test_property_list_multiple_organisations_data_scientist ¶
Test property list for data scientist, which will return all property related to the organisation ID supplied in parameter.
Source code in django_project/frontend/tests/test_property.py
StatisticalModelAdminTestCase ¶
Bases: TestCase
StatisticalModel admin test case.
OrganisationUsersViewTest ¶
Bases: TestCase
This covers the testcases on the view functions
UserApiTest ¶
Bases: TestCase
test_get_user_info ¶
Test getting non superuser user info.
Source code in django_project/frontend/tests/test_users_view.py
test_get_user_info_superuser ¶
Test getting superuser user info. All permissions should be assigned.
Source code in django_project/frontend/tests/test_users_view.py
TestVectorTileUtils ¶
Bases: TestCase
Test Vector tile utils.
Utils¶
cancel_task ¶
Cancel task if it's ongoing.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id |
str
|
task identifier |
required |
Source code in django_project/frontend/utils/celery.py
Helper function for colors.
Reference: https://github.com/bsouthga/blog/blob /master/public/posts/color-gradients-with-python.md
RGB_to_hex ¶
[255,255,255] -> "#FFFFFF"
color_dict ¶
Takes in a list of RGB sub-lists and returns dictionary of colors in RGB and hex form for use in a graphing function defined later on
Source code in django_project/frontend/utils/color.py
hex_to_RGB ¶
linear_gradient ¶
returns a gradient list of (n) colors between two hex colors. start_hex and finish_hex should be the full six-digit color string, inlcuding the number sign ("#FFFFFF")
Source code in django_project/frontend/utils/color.py
activity_report ¶
Generate property reports based on the user's request. Params: queryset (QuerySet): Properties queryset to generate reports from. request: The HTTP request object.
Source code in django_project/frontend/utils/data_table.py
activity_report_rows ¶
Generate property reports for csv and Excel file based on the user's request. Params: queryset (QuerySet): Properties queryset to generate reports from. request: The HTTP request object.
Source code in django_project/frontend/utils/data_table.py
common_filters ¶
Generate common filters for data retrieval based on the user's role and request parameters.
Params: request : The HTTP request object containing query parameters. user_roles : The roles of the user.
Source code in django_project/frontend/utils/data_table.py
data_table_reports ¶
Generate data table reports based on the user's request. Params: queryset (QuerySet): The initial queryset to generate reports from. request: The HTTP request object.
Source code in django_project/frontend/utils/data_table.py
national_level_activity_report ¶
Generate a national-level activity report based on the provided queryset and request parameters.
Args: queryset : The initial queryset containing species data. request : The HTTP request object containing query parameters.
Source code in django_project/frontend/utils/data_table.py
national_level_property_report ¶
Generate a national-level property report based on the provided queryset and request parameters.
Args: queryset : The initial queryset containing species data. request : The HTTP request object containing query parameters.
Source code in django_project/frontend/utils/data_table.py
national_level_province_report ¶
Generate a national-level species report based on the provided queryset and request parameters.
Args: queryset : The initial queryset containing species data. request : The HTTP request object containing query parameters.
Source code in django_project/frontend/utils/data_table.py
national_level_species_report ¶
Generate a national-level species report based on the provided queryset and request parameters.
Args: queryset : The initial queryset containing species data. request : The HTTP request object containing query parameters.
Source code in django_project/frontend/utils/data_table.py
national_level_user_table ¶
Generate national-level reports for a user based on their role.
Params: queryset : The initial queryset for data retrieval. request : The HTTP request object containing query parameters.
Source code in django_project/frontend/utils/data_table.py
property_report ¶
Generate property reports based on the user's request. Params: queryset (QuerySet): Properties queryset to generate reports from. request: The HTTP request object.
Source code in django_project/frontend/utils/data_table.py
sampling_report ¶
Generate sampling reports based on the user's request. Params: queryset (QuerySet): Properties queryset to generate reports from. request: The HTTP request object.
Source code in django_project/frontend/utils/data_table.py
species_report ¶
Generate species reports based on the user's request. Params: queryset (QuerySet): Properties queryset to generate reports from. request: The HTTP request object.
Source code in django_project/frontend/utils/data_table.py
write_report_to_rows ¶
Write report rows.
Source code in django_project/frontend/utils/data_table.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
|
Helper function for map.
create_map_materialized_view ¶
Execute sql to create materialized view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view_name |
str
|
name of the materialized view |
required |
sql |
str
|
the SQL for the materialized view |
required |
query_values |
list of query values |
required |
Source code in django_project/frontend/utils/map.py
delete_expired_map_materialized_view ¶
Remove expired materialized view.
Source code in django_project/frontend/utils/map.py
drop_map_materialized_view ¶
Execute sql to drop materialized view.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
view_name |
str
|
name of the materialized view |
required |
Source code in django_project/frontend/utils/map.py
generate_map_view ¶
generate_map_view(
session,
is_province_view,
filter_year=None,
filter_species_name=None,
filter_organisation=None,
filter_activity=None,
filter_spatial=None,
filter_property=None,
)
Generate materialized view from map filter session.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
MapSession
|
map filter session |
required |
is_province_view |
bool
|
True only if there is filter_species_name and user can view province layer |
required |
filter_year |
int
|
filter by year |
None
|
filter_species_name |
str
|
filter by species name |
None
|
filter_organisation |
str
|
filter by organisation id list |
None
|
filter_activity |
str
|
filter by activity list |
None
|
filter_spatial |
str
|
property spatial filter list |
None
|
filter_property |
str
|
filter by property id list |
None
|
Source code in django_project/frontend/utils/map.py
generate_population_count_categories ¶
Generate population count categories from species. This function will read from materialized view from MapSession.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_province_layer |
bool
|
True if this is for province layer |
required |
session |
MapSession
|
map filter session |
required |
filter_species_name |
str
|
map filter by species name |
required |
Returns:
Type | Description |
---|---|
list of dict of minLabel, maxLabel, value and color |
Source code in django_project/frontend/utils/map.py
generate_population_count_categories_base ¶
Generate population count categories for choropleth map. Using equal interval classification. http://wiki.gis.com/wiki/index.php/Equal_Interval_classification
Parameters:
Name | Type | Description | Default |
---|---|---|---|
min |
int
|
minimum population count |
required |
max |
int
|
maximum population count |
required |
base_color |
str
|
base color in hex to calculate color gradient |
required |
Returns:
Type | Description |
---|---|
list of dict of minLabel, maxLabel, value and color. |
Source code in django_project/frontend/utils/map.py
get_count_summary_of_population ¶
Return (Min, Max) for population query count. Materialized view for current session must be created.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
is_province_layer |
bool
|
True if the summary is for province layer |
required |
session |
MapSession
|
map filter session |
required |
Returns:
Type | Description |
---|---|
Tuple[int, int]: A tuple of (Min, Max) population count |
Source code in django_project/frontend/utils/map.py
get_map_template_style ¶
Fetch map template style from file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theme_choice |
int
|
0 light, 1 dark |
0
|
Returns:
Type | Description |
---|---|
json map style |
Source code in django_project/frontend/utils/map.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
|
get_properties_population_query ¶
get_properties_population_query(
filter_year,
filter_species_name,
filter_organisation,
filter_activity,
filter_spatial,
filter_property,
)
Generate query for population count in properties level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_year |
int
|
filter by year |
required |
filter_species_name |
str
|
filter by species name |
required |
filter_organisation |
str
|
filter by organisation id list |
required |
filter_activity |
str
|
filter by activity list |
required |
filter_spatial |
str
|
property spatial filter list |
required |
filter_property |
str
|
filter by property id list |
required |
Returns:
Type | Description |
---|---|
SQL for materialized view and query values |
Source code in django_project/frontend/utils/map.py
get_properties_query ¶
Generate query for properties layer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_organisation |
str
|
filter by organisation id list |
required |
filter_spatial |
str
|
property spatial filter list |
required |
filter_property |
str
|
filter by property id list |
required |
Returns:
Type | Description |
---|---|
SQL for materialized view and query values |
Source code in django_project/frontend/utils/map.py
get_province_population_query ¶
get_province_population_query(
filter_year,
filter_species_name,
filter_organisation,
filter_activity,
filter_spatial,
filter_property,
)
Generate query for population count in province level.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_year |
int
|
filter by year |
required |
filter_species_name |
str
|
filter by species name |
required |
filter_organisation |
str
|
filter by organisation id list |
required |
filter_activity |
str
|
filter by activity list |
required |
filter_spatial |
str
|
property spatial filter list |
required |
filter_property |
str
|
filter by property id list |
required |
Returns:
Type | Description |
---|---|
SQL for materialized view and query values |
Source code in django_project/frontend/utils/map.py
get_query_condition_for_population_query ¶
Generate query condition from species filters.
Filters that are used for choropleth: - species (mandatory) - end year - activity
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_year |
int
|
filter by year |
required |
filter_species_name |
str
|
filter by species name |
required |
filter_activity |
str
|
filter by activity list |
required |
Returns:
Type | Description |
---|---|
list of SQL conditions and list of query values |
Source code in django_project/frontend/utils/map.py
get_query_condition_for_properties_query ¶
get_query_condition_for_properties_query(
filter_organisation,
filter_spatial,
filter_property,
property_alias_name="p",
)
Generate query condition from properties filters.
Filters that are used for properties layer: - organisation - property - spatial
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_organisation |
str
|
filter by organisation id list |
required |
filter_spatial |
str
|
property spatial filter list |
required |
filter_property |
str
|
filter by property id list |
required |
property_alias_name |
str
|
alias for property table in the query |
'p'
|
Returns:
Type | Description |
---|---|
list of SQL conditions and list of query values |
Source code in django_project/frontend/utils/map.py
replace_maptiler_api_key ¶
Replace maptiler_key.
Source code in django_project/frontend/utils/map.py
calculate_base_population_of_species ¶
Calculate base population of species and modify the input data. Params: data (List[Dict[str, Any]]): List of dictionaries representing species data. Returns: Dict[str, Any]: A dictionary containing modified species data with base percentages and activity colors.
Source code in django_project/frontend/utils/metrics.py
calculate_population_categories ¶
Calculate population categories for a given queryset of properties.
Args: queryset (QuerySet): A queryset of properties. species_name (str): The name of the species. year_range (Tuple[int]): Start year and end year.
Returns: Dict[str, Any]: A dictionary containing: - CATEGORY_LABELS: List of population category labels. - YEAR_LABELS: List of years for which the data is available. - CATEGORY_DATA: List of dictionaries with year, property count, and population category details.
This function takes a queryset of properties and the name of a species. It calculates population categories based on annual population data for the specified species across the provided properties. It retrieves the annual population data, calculates the minimum and maximum populations, creates 6 population categories, and counts the number of properties in each category for each year.
Source code in django_project/frontend/utils/metrics.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
calculate_total_area_per_property_type ¶
Calculate the total area per property type for a given queryset of properties. Params: queryset (QuerySet): The queryset of Property objects. species_name: filter results by species Returns: list[dict]: A list of dictionaries, each containing property_type and total_area keys representing the property type name and the aggregated total area respectively.
Source code in django_project/frontend/utils/metrics.py
round_with_precision_check ¶
Calculate rounded number of value with decimal precision. If given precision makes the rounded number becomes 0, then increase the precision. Params: value: positive number precision: number of decimal to be rounded of max_precision: maximum precision Return: A rounded number
Source code in django_project/frontend/utils/metrics.py
Common functions for parcel.
find_layer_by_cname ¶
Find layer name+id by cname.
Source code in django_project/frontend/utils/parcel.py
find_parcel_base ¶
Base function to find parcel.
Source code in django_project/frontend/utils/parcel.py
find_province ¶
Find province for given geometry (SRID 3857).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geom |
GEOSGeometry
|
Geometry |
required |
default |
Province
|
Default Province if no result |
required |
Returns:
Type | Description |
---|---|
Province that has biggest overlap with geom |
Source code in django_project/frontend/utils/parcel.py
get_geom_size_in_ha ¶
Calculate geometry size in ha.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geom |
GEOSGeometry
|
Geometry |
required |
Returns:
Type | Description |
---|---|
Size in ha |
Source code in django_project/frontend/utils/parcel.py
select_parcel_by_centroid ¶
Select parcel by using its centroid.
Source code in django_project/frontend/utils/parcel.py
Utilities function for process management.
kill_process_by_pid ¶
Kill process by PID.
Source code in django_project/frontend/utils/process.py
read_pid_from_pidfile ¶
Read the PID recorded in the named PID file.
Read and return the numeric PID recorded as text in the named
PID file. If the PID file cannot be read, or if the content is
not a valid PID, return None
.
Source code in django_project/frontend/utils/process.py
clear_species_model_output_cache ¶
Clear all output from species statistical model in the cache.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_output |
SpeciesModelOutput
|
SpeciesModelOutput |
required |
Source code in django_project/frontend/utils/statistical_model.py
execute_statistical_model ¶
Execute R model from exported data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_filepath |
file path of exported csv |
required | |
taxon |
Taxon
|
species |
required |
model |
StatisticalModel
|
optional model to be executed, if model=None, then generic one will be used |
None
|
Returns:
Type | Description |
---|---|
tuple of is_success, json response |
Source code in django_project/frontend/utils/statistical_model.py
init_species_model_output_from_generic_model ¶
Create species model output from generic model.
Source code in django_project/frontend/utils/statistical_model.py
init_species_model_output_from_non_generic_model ¶
Create species model output specific to a taxon in model.
Source code in django_project/frontend/utils/statistical_model.py
kill_r_plumber_process ¶
mark_model_output_as_outdated_by_model ¶
Mark latest output as outdated so it can be refreshed.
This is triggered when R code in a model is updated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
StatisticalModel
|
StatisticalModel |
required |
Source code in django_project/frontend/utils/statistical_model.py
mark_model_output_as_outdated_by_species_list ¶
Mark latest output as outdated so it can be refreshed.
This is triggered when a new data of species are added.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
taxon |
species |
required |
Source code in django_project/frontend/utils/statistical_model.py
plumber_health_check ¶
Check whether API is up and running.
This will be called from worker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_retry |
maximum retry of checking |
5
|
Returns:
Type | Description |
---|---|
True if successful number of check is less than max_retry |
Source code in django_project/frontend/utils/statistical_model.py
remove_plumber_data ¶
Remove csv data file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_filepath |
filepath to the csv file |
required |
Source code in django_project/frontend/utils/statistical_model.py
spawn_r_plumber ¶
Run a Plumber API server.
Source code in django_project/frontend/utils/statistical_model.py
store_species_model_output_cache ¶
Store output types to cache.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_output |
SpeciesModelOutput
|
SpeciesModelOutput |
required |
json_data |
dictionary from plumber response |
required |
Source code in django_project/frontend/utils/statistical_model.py
write_plumber_data ¶
Write csv data to file in plumber_data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
headers |
list of header name |
required | |
csv_data |
list of row |
required |
Returns:
Type | Description |
---|---|
file path of exported csv |
Source code in django_project/frontend/utils/statistical_model.py
write_plumber_file ¶
Write R codes to plumber.R
Source code in django_project/frontend/utils/statistical_model.py
Utility functions for shapefile.
get_uploaded_file_crs ¶
Get CRS from uploaded file.
Source code in django_project/frontend/utils/upload_file.py
normalize_geometry ¶
This function will do following: - strip z dimension - convert polygon to multipoylgon
Source code in django_project/frontend/utils/upload_file.py
search_parcels_by_boundary_files ¶
Search parcels by uploaded boundary files.
Source code in django_project/frontend/utils/upload_file.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
|
validate_shapefile_zip ¶
Validate if shapefile zip has correct necessary files.
Note: fiona will throw exception only if dbf or shx is missing if there are 2 layers inside the zip, and 1 of them is invalid, then fiona will only return 1 layer
Source code in django_project/frontend/utils/upload_file.py
check_user_has_permission ¶
Test if a user has permission.
get_user_permissions ¶
Retrieve the permissions associated with a given user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
User
|
The user object |
required |
Returns:
Type | Description |
---|---|
Set[str]
|
A set containing the names of all permissions associated with the user |
Source code in django_project/frontend/utils/user_roles.py
get_user_roles ¶
Retrieve the roles associated with a given user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
User
|
The user object |
required |
Returns:
Type | Description |
---|---|
List[str]
|
A list containing the names of all roles associated with the user |
Source code in django_project/frontend/utils/user_roles.py
is_organisation_manager ¶
Determines whether a user is a manager of the currently active organisation or of the organisation specified as a parameter, if provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
User
|
The user object to check. |
required |
organisation |
Organisation
|
Optional organisation object to check against. |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if the user is a manager of the organisation, otherwise False. |
Source code in django_project/frontend/utils/user_roles.py
is_organisation_member ¶
Determine if a user is a member of the currently active organisation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user |
User
|
The user object |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the user is a member, otherwise False |
Source code in django_project/frontend/utils/user_roles.py
calculate_vector_tile_size ¶
convert_size ¶
Convert size in bytes to readable text.
Source code in django_project/frontend/utils/vector_tile.py
generate_configuration_file ¶
Generate tegola config file.
Source code in django_project/frontend/utils/vector_tile.py
generate_vector_tiles ¶
Generate vector tiles for static context layers.
Source code in django_project/frontend/utils/vector_tile.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|
get_country_bounding_box ¶
Get South Africa bbox.
Source code in django_project/frontend/utils/vector_tile.py
get_folder_size ¶
Get directory size in bytes.