MATSIM
Private Member Functions | Static Private Attributes | List of all members
org.matsim.analysis.PersonWriter Class Reference

Private Member Functions

void writePerson (Person p, List< String > attributes, CSVPrinter csvPrinter) throws IOException
 
String [] prepareHeader (List< String > attributes)
 
List< String > prepareAttributes ()
 

Static Private Attributes

static final Logger log = LogManager.getLogger(PersonWriter.class)
 

Detailed Description

Definition at line 22 of file PersonWriter.java.

Member Function Documentation

◆ writePerson()

void org.matsim.analysis.PersonWriter.writePerson ( Person  p,
List< String >  attributes,
CSVPrinter  csvPrinter 
) throws IOException
private

Definition at line 57 of file PersonWriter.java.

References org.matsim.api.core.v01.population.Activity.getCoord(), org.matsim.api.core.v01.population.Activity.getType(), org.matsim.api.core.v01.Coord.getX(), and org.matsim.api.core.v01.Coord.getY().

57  {
58  if (p.getSelectedPlan() == null) {
59  log.error("Found person without a selected plan: " + p.getId().toString() + " will not be added to output_persons.csv");
60  return;
61  }
62  List<String> line = new ArrayList<>();
63  line.add(p.getId().toString());
64  line.add(p.getSelectedPlan().getScore() == null ? "null" : p.getSelectedPlan().getScore().toString());
65  String x = "";
66  String y = "";
67  String actType = "";
68  if (!p.getSelectedPlan().getPlanElements().isEmpty()) {
69  Activity firstAct = (Activity) p.getSelectedPlan().getPlanElements().get(0);
70  if (firstAct.getCoord() != null) {
71  x = Double.toString(firstAct.getCoord().getX());
72  y = Double.toString(firstAct.getCoord().getY());
73  }
74  actType = firstAct.getType();
75  }
76  line.add(x);
77  line.add(y);
78  line.add(actType);
79  for (String attribute : attributes) {
80  Object value = p.getAttributes().getAttribute(attribute);
81  String result = value != null ? String.valueOf(value) : "";
82  line.add(result);
83  }
84  csvPrinter.printRecord(line);
85  }
Here is the call graph for this function:

◆ prepareHeader()

String [] org.matsim.analysis.PersonWriter.prepareHeader ( List< String >  attributes)
private

Definition at line 87 of file PersonWriter.java.

87  {
88  List<String> header = new ArrayList<>();
89  header.add("person");
90  header.add("executed_score");
91  header.add("first_act_x");
92  header.add("first_act_y");
93  header.add("first_act_type");
94  header.addAll(attributes);
95  return header.toArray(String[]::new);
96  }

◆ prepareAttributes()

List<String> org.matsim.analysis.PersonWriter.prepareAttributes ( )
private

Definition at line 98 of file PersonWriter.java.

98  {
99  List<String> attributes = scenario.getPopulation().getPersons().values().parallelStream()
100  .flatMap(p -> p.getAttributes().getAsMap().keySet().stream()).distinct()
101  .collect(Collectors.toList());
102  attributes.remove("vehicles");
103  return attributes;
104  }
Map< Id< Person >,? extends Person > getPersons()

Member Data Documentation

◆ log

final Logger org.matsim.analysis.PersonWriter.log = LogManager.getLogger(PersonWriter.class)
staticprivate

Definition at line 33 of file PersonWriter.java.


The documentation for this class was generated from the following file: