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 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()
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()
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 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()
示例#6
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()