from os import path, pardir
import sys
sys.path.append(path.join(path.dirname(path.realpath(__file__)), pardir))

tombolo_path = 'Desktop/TomboloDigitalConnector'
recipe_output_location = 'Desktop/london-no2.json'
model_output = 'Desktop/london-no2.geojson'

from recipe import Recipe, Field, Datasource, AttributeMatcher, Subject, Match_Rule, LatestValueField, Dataset

subjects = Subject(subject_type_label='airQualityControl', provider_label='erg.kcl.ac.uk')
datasources = Datasource(importer_class='uk.org.tombolo.importer.lac.LAQNImporter', datasource_id='airQualityControl')

attribute_matcher = AttributeMatcher(provider='erg.kcl.ac.uk', label='NO2 40 ug/m3 as an annual me')
lvf = LatestValueField(attribute_matcher=attribute_matcher, label='Anual NO2')

dataset = Dataset(subjects=[subjects], datasources=[datasources], fields=[lvf])
recipe = Recipe(dataset=dataset)
recipe.build_recipe(output_location=recipe_output_location)
recipe.run_recipe(tombolo_path=tombolo_path, output_path=model_output)
    geography_scope=['London'])
m_datasource_4 = Datasource(
    importer_class='uk.org.tombolo.importer.lac.LAQNImporter',
    datasource_id='airQualityControl')

# Creating Fields
# There are two high level fields in this recipe, one is GeographicAggregationField (for NO2 data) and
# other one is ArithmeticField for getting the fraction of BicycleCount and CarCount

# Here we are creating LatestValueField for NO2 40 ug/m3 to get the mean value of it
# For that we are creating AttributeMatcher to tell DC what needs to be pulled from Database
# That AttributeMatcher object is then passed to the Field Object and then we are passing everything to
# GeographicAggregationField
pf_subject = Subject(provider_label='erg.kcl.ac.uk',
                     subject_type_label='airQualityControl')
attribute = AttributeMatcher(provider='erg.kcl.ac.uk',
                             label='NO2 40 ug/m3 as an annual mean')
l_v_f = LatestValueField(attribute_matcher=attribute)
parent_field = GeographicAggregationField(subject=pf_subject,
                                          label='NitrogenDioxide',
                                          function='mean',
                                          field=l_v_f)

# Below we are creating 3 Fields 2 LatestValueFields and 1 ArithmeticField
# ArithmeticField is the parent field which contains two child fields (2 LatestValueFields)
# First LatestValueField is taking sum of all BicycleCount in a LocalAuthority
# Second LatestValueField is taking sum of all CarsTaxis in a LocalAuthority
# Then they both are passed to ArithmeticField which takes the
# fraction of BicycleCount, with first field as divisor and second as dividend
a_sub = Subject(provider_label='uk.gov.dft',
                subject_type_label='trafficCounter')
attr = AttributeMatcher(provider='uk.gov.dft', label='CountPedalCycles')
예제 #3
0
sys.path.append(path.join(path.dirname(path.realpath(__file__)), pardir))

# Importing all the relevant objects which are necessary
from recipe import Dataset, Subject, AttributeMatcher, GeographicAggregationField, LatestValueField, Match_Rule, Datasource, Recipe

# Creating match rule for London
match_rule = Match_Rule(attribute_to_match_on='label', pattern='E090%')
subject = Subject(subject_type_label='localAuthority', provider_label='uk.gov.ons', match_rule=match_rule)

# Creating datasource to tell DC which importers to call in order to download dataset
datasource_1 = Datasource(importer_class='uk.org.tombolo.importer.ons.OaImporter', datasource_id='localAuthority')
datasource_2 = Datasource(importer_class='uk.org.tombolo.importer.dft.TrafficCountImporter', 
                        datasource_id= 'trafficCounts', geography_scope=["London"])

# Creating Attribute matcher, which means getting only those values from database where 
# attribute name is CountPedalCycles
attribute_matcher = AttributeMatcher(provider='uk.gov.dft', label='CountPedalCycles')
field = LatestValueField(attribute_matcher=attribute_matcher, label='CountPedalCycles')

# Creating Subject for Geographic aggregation field
subject_2 = Subject(subject_type_label='trafficCounter', provider_label='uk.gov.dft')
geo_agg_field = GeographicAggregationField(subject=subject_2, field=field, function='sum', label='SumCountPedalCycles')

# Creating the dataset and calling DC to run the recipe
dataset = Dataset(subjects=[subject], datasources=[datasource_1, datasource_2], fields=[geo_agg_field])
_recipe = Recipe(dataset=dataset)
_recipe.build_recipe(output_location='Desktop/aggregate-traffic-count-data-within-localauthorities.json')
_recipe.run_recipe(tombolo_path='Desktop/UptodateProject/TomboloDigitalConnector', output_path='Desktop/aggregate-traffic-count-data-within-localauthorities.geojson')