Exemplo n.º 1
0
def get_elements_within_set(gc):
    # Get Elements within set
    elements = gc.execute_operation(
        g.GetElementsWithinSet(
            input=[
                g.EntitySeed('M5'),
                g.EntitySeed('M5:10'),
                g.EntitySeed('M5:11')
            ],
            view=g.View(
                edges=[
                    g.ElementDefinition(
                        group='RoadUse',
                        group_by=[]
                    ),
                    g.ElementDefinition(
                        group='RoadHasJunction',
                        group_by=[]
                    )
                ]
            )
        )
    )
    print('Elements within set')
    print(elements)
    print()
Exemplo n.º 2
0
def get_elements_in_ranges(gc):
    # Get Elements in ranges
    elements = gc.execute_operation(
        g.GetElementsInRanges(
            input=[g.SeedPair(g.EntitySeed('M5:10'), g.EntitySeed('M5:12'))],
            view=g.View(
                edges=[g.ElementDefinition(group='RoadUse', group_by=[])])))
    print('Elements in ranges')
    print(elements)
    print()
Exemplo n.º 3
0
def get_elements_between_sets(gc):
    # Get Elements
    elements = gc.execute_operation(
        g.GetElementsBetweenSets(
            input=[g.EntitySeed('M5')],
            input_b=[g.EntitySeed('M5:10'),
                     g.EntitySeed('M5:11')],
            view=g.View(edges=[
                g.ElementDefinition(group='RoadUse', group_by=[]),
                g.ElementDefinition(group='RoadHasJunction', group_by=[])
            ])))
    print('Elements between sets')
    print(elements)
    print()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
def named_operation(gc):
    result = gc.execute_operation(
        g.NamedOperation(operation_name='2-hop-with-limit',
                         parameters={'param1': 2},
                         input=[g.EntitySeed('M5')]))
    print('Execute named operation')
    print(result)
    print()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
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()
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
def get_sub_graph(gc):
    # Export and Get to/from an in memory set
    entity_seeds = gc.execute_operations([
        g.GetAdjacentIds(input=[g.EntitySeed('South West')],
                         include_incoming_out_going=g.InOutType.OUT),
        g.ExportToSet(),
        g.GetAdjacentIds(include_incoming_out_going=g.InOutType.OUT),
        g.ExportToSet(),
        g.DiscardOutput(),
        g.GetSetExport()
    ])
    print('Export and Get to/from an in memory set')
    print(entity_seeds)
    print()
Exemplo n.º 12
0
def get_adj_seeds(gc):
    # Adjacent Elements - chain 2 adjacent entities together
    adj_seeds = gc.execute_operations([
        g.GetAdjacentIds(
            input=[g.EntitySeed(vertex='M5')],
            view=g.View(
                edges=[g.ElementDefinition('RoadHasJunction', group_by=[])]),
            include_incoming_out_going=g.InOutType.OUT),
        g.GetAdjacentIds(
            view=g.View(edges=[g.ElementDefinition('RoadUse', group_by=[])]),
            include_incoming_out_going=g.InOutType.OUT)
    ])
    print('Adjacent entities - 2 hop')
    print(adj_seeds)
    print()
Exemplo n.º 13
0
def get_job_details(gc):
    # Get all job details
    job_details_initial = gc.execute_operations([
        g.GetAdjacentIds(input=[g.EntitySeed('1')], ),
        g.ExportToGafferResultCache(),
        g.DiscardOutput(),
        g.GetJobDetails()
    ])

    job_id = job_details_initial['jobId']

    job_details = gc.execute_operation(g.GetJobDetails(job_id=job_id), )
    print('Get job details')
    print(job_details)
    print()
    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)
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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()
Exemplo n.º 17
0
def export_to_gaffer_result_cache(gc):
    # Export to Gaffer Result Cache and Get from Gaffer Result Cache
    job_details = gc.execute_operations([
        g.GetAdjacentIds(input=[g.EntitySeed('South West')],
                         include_incoming_out_going=g.InOutType.OUT),
        g.ExportToGafferResultCache(),
        g.DiscardOutput(),
        g.GetJobDetails()
    ])
    print('Export to Gaffer Result Cache. Job Details:')
    print(job_details)
    print()

    job_id = job_details['jobId']
    entity_seeds = gc.execute_operation(
        g.GetGafferResultCacheExport(job_id=job_id), )
    print('Get Gaffer Result Cache Export.')
    print(entity_seeds)
    print()
Exemplo n.º 18
0
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()
Exemplo n.º 19
0
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()