use of uk.gov.gchq.gaffer.traffic.generator.RoadTrafficCsvElementGenerator in project gaffer-doc by gchq.
the class FullExample method run.
@Override
public Iterable<? extends String> run() throws OperationException, IOException {
// [graph] Create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
// ---------------------------------------------------------
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
try (final CSVParser parser = CSVParser.parse(getClass().getResource("/FullExample/data.txt"), Charset.defaultCharset(), CSVFormat.DEFAULT.withFirstRecordAsHeader())) {
final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<CSVRecord>().generator(new RoadTrafficCsvElementGenerator()).input(parser).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
}
// ---------------------------------------------------------
print("The elements have been added.");
// [get] Get all road junctions in the South West that were heavily used by buses in the year 2000.
// ---------------------------------------------------------
final OperationChain<Iterable<? extends String>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("South West")).view(new View.Builder().edge("RegionContainsLocation").build()).build()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("LocationContainsRoad").build()).build()).then(new ToSet<>()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("RoadHasJunction").build()).build()).then(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).entity("JunctionUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate", "endDate").execute(new InDateRangeDual.Builder().start("2000/01/01").end("2001/01/01").build()).build()).postAggregationFilter(new ElementFilter.Builder().select("countByVehicleType").execute(new PredicateMap<>("BUS", new IsMoreThan(1000L))).build()).transientProperty("busCount", Long.class).transformer(new ElementTransformer.Builder().select("countByVehicleType").execute(new FreqMapExtractor("BUS")).project("busCount").build()).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new Sort.Builder().comparators(new ElementPropertyComparator.Builder().groups("JunctionUse").property("busCount").reverse(true).build()).resultLimit(2).deduplicate(true).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
// ---------------------------------------------------------
printJsonAndPython("GET", opChain);
final Iterable<? extends String> results = graph.execute(opChain, user);
print("\nAll road junctions in the South West that were heavily used by buses in year 2000.");
for (final String result : results) {
print("RESULT", result);
}
return results;
}
Aggregations