def named_view_summarise(gc): result = gc.execute_operation( g.GetElements(input=[g.EntitySeed(vertex='M32:1')], view=g.NamedView(name="summarise"))) print('Execute get elements with summarised named view') print(result) print()
def generate_domain_objects_chain(gc): # Generate Domain Objects - chain of get input then generate input input = gc.execute_operations( [ g.GetElements( input=[g.EntitySeed(vertex='M5')], seed_matching_type=g.SeedMatchingType.RELATED, view=g.View( edges=[ g.ElementDefinition( group='RoadHasJunction', group_by=[] ) ] ) ), g.GenerateObjects( element_generator=g.ElementGenerator( class_name='uk.gov.gchq.gaffer.rest.example.ExampleDomainObjectGenerator' ) ) ] ) print('Generated input from get input by seed') print(input) print()
def get_element_group_counts(gc): # Get Elements group_counts = gc.execute_operations( [g.GetElements(input=[g.EntitySeed('M5')]), g.CountGroups(limit=1000)]) print('Groups counts (limited to 1000 input)') print(group_counts) print()
def get_walks(gc): # Get walks from M32 traversing down RoadHasJunction then JunctionLocatedAt walks = gc.execute_operation( g.GetWalks( input=[ g.EntitySeed('M32'), ], operations=[ g.GetElements(view=g.View( edges=[g.ElementDefinition(group='RoadHasJunction')])), g.GetElements(view=g.View( edges=[g.ElementDefinition(group='JunctionLocatedAt')])) ])) print( 'Walks from M32 traversing down RoadHasJunction then JunctionLocatedAt' ) print(walks) print()
def complex_op_chain(gc): # All road junctions in the South West that were heavily used by buses in year 2000. junctions = gc.execute_operations(operations=[ g.GetAdjacentIds(input=[g.EntitySeed(vertex='South West')], view=g.View(edges=[ g.ElementDefinition( group='RegionContainsLocation', group_by=[]) ])), g.GetAdjacentIds(view=g.View(edges=[ g.ElementDefinition(group='LocationContainsRoad', group_by=[]) ])), g.ToSet(), g.GetAdjacentIds(view=g.View( edges=[g.ElementDefinition(group='RoadHasJunction', group_by=[]) ])), g.GetElements(view=g.View(entities=[ g.ElementDefinition( group='JunctionUse', group_by=[], transient_properties=[ g.Property('busCount', 'java.lang.Long') ], pre_aggregation_filter_functions=[ g.PredicateContext(selection=['startDate'], predicate=g.InDateRange( start='2000/01/01', end='2001/01/01')) ], post_aggregation_filter_functions=[ g.PredicateContext( selection=['countByVehicleType'], predicate=g.PredicateMap(predicate=g.IsMoreThan( value={'java.lang.Long': 1000}, or_equal_to=False), key='BUS')) ], transform_functions=[ g.FunctionContext(selection=['countByVehicleType'], function=g.FreqMapExtractor(key='BUS'), projection=['busCount']) ]) ]), include_incoming_out_going=g.InOutType.OUT), g.ToCsv(element_generator=g.CsvGenerator(fields={ 'VERTEX': 'Junction', 'busCount': 'Bus Count' }, quoted=False), include_header=True) ]) print( 'All road junctions in the South West that were heavily used by buses in year 2000.' ) print(junctions) print()
def to_vertices_to_entity_seeds(gc): # Get sorted Elements input = gc.execute_operations([ g.GetElements( input=[g.EntitySeed(vertex='South West')], view=g.View(edges=[ g.ElementDefinition('RegionContainsLocation', group_by=[]) ]), include_incoming_out_going=g.InOutType.OUT), g.ToVertices(edge_vertices=g.EdgeVertices.DESTINATION, use_matched_vertex=g.UseMatchedVertex.OPPOSITE), g.ToEntitySeeds(), g.GetElements(view=g.View( edges=[g.ElementDefinition('LocationContainsRoad', group_by=[])]), include_incoming_out_going=g.InOutType.OUT), g.Limit(5) ]) print('ToVertices then ToEntitySeeds') print(input) print()
def named_view_date_range(gc): result = gc.execute_operation( g.GetElements(input=[g.EntitySeed(vertex='M32:1')], view=g.NamedView(name="dateRange", parameters={ 'start': '2005/05/03 06:00', 'end': '2005/05/03 09:00' }))) print('Execute get elements with date range named view') print(result) print()
def test_execute_operation(self): gc = gaffer_connector.GafferConnector( 'http://localhost:8080/rest/latest') elements = gc.execute_operation( g.GetElements( input=[g.EntitySeed('M5:10')], view=g.View( edges=[g.ElementDefinition(group='JunctionLocatedAt')]))) self.assertEqual([ g.Edge("JunctionLocatedAt", "M5:10", "390466,225615", True, {}, "SOURCE") ], elements)
def test_dummy_header(self): """Test that the addition of a dummy header does not effect the standard test""" gc = gaffer_connector.GafferConnector( 'http://localhost:8080/rest/latest', headers={"dummy_Header": "value"}) elements = gc.execute_operation( g.GetElements( input=[g.EntitySeed('M5:10')], view=g.View( edges=[g.ElementDefinition(group='JunctionLocatedAt')]))) self.assertEqual([ g.Edge("JunctionLocatedAt", "M5:10", "390466,225615", True, {}, "SOURCE") ], elements)
def get_elements(gc): # Get Elements input = gc.execute_operation( g.GetElements( input=[ g.EntitySeed('M5:10'), # Edge input can be provided as follows g.EdgeSeed('M5:10', 'M5:11', g.DirectedType.EITHER), g.EdgeSeed('M5:10', 'M5:11', g.DirectedType.DIRECTED), # Or you can use True or False for the direction g.EdgeSeed('M5:10', 'M5:11', True) ], view=g.View( edges=[ g.ElementDefinition( group='RoadUse', group_by=[], transient_properties=[ g.Property('description', 'java.lang.String') ], pre_aggregation_filter_functions=[ g.PredicateContext( selection=['count'], predicate=g.IsMoreThan( value={'java.lang.Long': 1} ) ) ], transform_functions=[ g.FunctionContext( selection=['SOURCE', 'DESTINATION', 'count'], function=g.Function( class_name='uk.gov.gchq.gaffer.traffic.transform.DescriptionTransform'), projection=['description'] ) ] ) ] ), directed_type=g.DirectedType.EITHER ) ) print('Related input') print(input)
def complex_op_chain(gc): # All road junctions in the South West that were heavily used by buses in year 2000. junctions = gc.execute_operations( operations=[ g.GetAdjacentIds( input=[g.EntitySeed(vertex='South West')], view=g.View( edges=[ g.ElementDefinition( group='RegionContainsLocation', group_by=[] ) ] ) ), g.GetAdjacentIds( view=g.View( edges=[ g.ElementDefinition( group='LocationContainsRoad', group_by=[] ) ] ) ), g.ToSet(), g.GetAdjacentIds( view=g.View( edges=[ g.ElementDefinition( group='RoadHasJunction', group_by=[] ) ] ) ), g.GetElements( view=g.View( entities=[ g.ElementDefinition( group='JunctionUse', group_by=[], transient_properties=[ g.Property('busCount', 'java.lang.Long') ], pre_aggregation_filter_functions=[ g.PredicateContext( selection=['startDate'], predicate=g.IsMoreThan( value={'java.util.Date': 946684800000}, or_equal_to=True ) ), g.PredicateContext( selection=['startDate'], predicate=g.IsLessThan( value={'java.util.Date': 978307200000}, or_equal_to=False ) ) ], post_aggregation_filter_functions=[ g.PredicateContext( selection=['startDate'], predicate=g.IsMoreThan( value={'java.util.Date': 946684800000}, or_equal_to=True ) ), g.PredicateContext( selection=['countByVehicleType'], predicate=g.PredicateMap( predicate=g.IsMoreThan( value={'java.lang.Long': 1000}, or_equal_to=False ), key='BUS' ) ) ], transform_functions=[ g.FunctionContext( selection=['countByVehicleType'], function=g.Function( class_name='uk.gov.gchq.gaffer.types.function.FreqMapExtractor', fields={'key': 'BUS'} ), projection=['busCount'] ) ] ) ] ), include_incoming_out_going=g.InOutType.OUT ), g.ToCsv( element_generator={ 'class': 'uk.gov.gchq.gaffer.data.generator.CsvGenerator', 'fields': { 'VERTEX': 'Junction', 'busCount': 'Bus Count' }, 'quoted': False, 'header': 'Junction,Bus Count' } ) ] ) print( 'All road junctions in the South West that were heavily used by buses in year 2000.') print(junctions) print()