Esempio n. 1
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()
Esempio n. 2
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)
Esempio n. 3
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()