Commit 0aea5542 authored by Niklas Selke's avatar Niklas Selke
Browse files

activated the landcover service

parent 8ed692ad
Pipeline #96565 passed with stages
in 51 seconds
......@@ -55,6 +55,7 @@ INSTALLED_APPS = [
# 'services.htap_regions_tier1',
# 'services.htap_regions_tier2',
'services.population_number',
'services.landcover',
# 'services.built_up_area',
# 'services.population_density_ghs',
]
......
......@@ -19,6 +19,7 @@ urlpatterns = [
# re_path(r'htap_regions_tier1/', include('services.htap_regions_tier1.urls'), name='htap_regions_tier1'),
# re_path(r'htap_regions_tier2/', include('services.htap_regions_tier2.urls'), name='htap_regions_tier2'),
re_path(r'population_number/', include('services.population_number.urls'), name='population_number'),
re_path(r'landcover/', include('services.landcover.urls'), name='landcover'),
# re_path(r'built_up_area/', include('services.built_up_area.urls'), name='built_up_area'),
# re_path(r'population_density_ghs/', include('services.population_density_ghs.urls'), name='population_density_ghs')
]
......
......@@ -46,6 +46,7 @@ class LocationServicesRootView(APIView):
# ('htap_regions_tier1', request.build_absolute_uri()+'htap_regions_tier1/'),
# ('htap_regions_tier2', request.build_absolute_uri()+'htap_regions_tier2/'),
('population_number', request.build_absolute_uri()+'population_number/'),
('landcover', request.build_absolute_uri()+'landcover/'),
# ('built_up_area', request.build_absolute_uri()+'built_up_area/'),
# ('population_density_ghs', request.build_absolute_uri()+'population_density_ghs/')
]),
......
from django.apps import AppConfig
class LandcoverConfig(AppConfig): # pragma: no cover
name = 'services.landcover'
"""serializer for landcover
"""
from utils.agg_serializer import GeneralAggSerializer
# serializer classes
class AggSerializer(GeneralAggSerializer):
def __init__(self, instance):
instance['unit'] = ''
super(AggSerializer, self).__init__(instance)
from django.test import TestCase
from services.landcover.serializers import AggSerializer
from services.landcover.views import LandcoverView
import geo_location_services.settings as settings
from collections import OrderedDict
class TestSerializers(TestCase):
def test_AggSerializer(self):
rawdata = OrderedDict([
("lat", settings.DEFAULT_LAT),
("lon", settings.DEFAULT_LON),
("radius", 5000),
("direction", None),
("bins", None),
("agg_function", 'mean'),
('mean', 10),
])
serializer = AggSerializer(rawdata)
self.assertEqual(serializer.instance["unit"], "")
self.assertEqual(serializer.instance["radius"], 5000)
class TestViews(TestCase):
def test_LandcoverView(self):
view = LandcoverView()
self.assertEqual(view.min_valid, 1)
self.assertEqual(view.max_valid, 220)
self.assertTrue(view.AggSerializer is AggSerializer)
self.assertListEqual(view.AGG_ALLOWED, ['maxclass', 'frequency'])
self.assertEqual(view.STATS["frequency"].keywords["bins"], 220)
from django.urls import re_path
from .views import LandcoverView
urlpatterns = [
re_path(r'^$', LandcoverView.as_view()),
]
from rest_framework.views import APIView
from .serializers import AggSerializer
from utils.views_commons import CommonViewsWithYear
from .apps import LandcoverConfig as Config
from utils.statistics import most_common_value, relative_frequency
class LandcoverView(APIView, CommonViewsWithYear):
def __init__(self):
opts = dict(min_valid=1,
max_valid=220,
serializer=AggSerializer,
service_type=Config.name)
CommonViewsWithYear.__init__(self, **opts)
self.keep_only_given_agg_allowed(dict(maxclass=most_common_value,
frequency=relative_frequency),
frequency=dict(bins=220,
missing_value=self.default_value))
......@@ -15,6 +15,7 @@ class GeoCube:
'services.climatic_zones': 'climatic_zone__ipcc',
'services.population_number': 'population_number__ghsl_09ss',
'services.population_number_coarse': 'population_number__ghsl_30ss',
'services.landcover': 'land_cover_class__esa',
# 'rice_production': 'rice',
# 'wheat_production': 'wheat'
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment