Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,36 @@ export class OriginDestinationComponent implements OnInit, OnDestroy {
private xScale: d3.ScaleBand<string>;
private yScale: d3.ScaleBand<string>;

private extractNumericODValues(odList: OriginDestination[], field: FieldName): number[] {
return odList.filter((od) => od["found"]).map((od) => od[field]);
private extractNumericODValues(odList: OriginDestination[], field: FieldName): any {
let minValue = undefined;
let maxValue = undefined;
odList
.filter((od) => od["found"])
.map((od) => {
const v = od[field];
if (minValue !== undefined) {
if (v < minValue) {
minValue = v;
} else {
if (v > maxValue) {
maxValue = v;
}
}
} else {
minValue = v;
maxValue = minValue;
}
});
if (minValue === undefined) {
return {
minValue: 0,
maxValue: 1,
};
}
return {
minValue: minValue,
maxValue: maxValue,
};
}

ngOnInit(): void {
Expand Down Expand Up @@ -236,9 +264,7 @@ export class OriginDestinationComponent implements OnInit, OnDestroy {

// compute color scale
const numericValues = this.extractNumericODValues(this.matrixData, this.colorBy);
const maxValue = numericValues.length ? Math.max(...numericValues) : 1;
const minValue = numericValues.length ? Math.min(...numericValues) : 0;
this.colorScale = this.getColorScale(minValue, maxValue);
this.colorScale = this.getColorScale(numericValues.minValue, numericValues.maxValue);

// Prepare nodeNameMap and tooltip
const nodeNameMap = new Map(this.nodeNames.map((n) => [n.shortName, n.fullName]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {DataService} from "../../../data/data.service";
import {TrainrunService} from "../../../data/trainrun.service";
import {
buildEdges,
clearComputeShortestPathsCache,
computeNeighbors,
computeShortestPaths,
topoSort,
Expand Down Expand Up @@ -78,12 +79,14 @@ export class OriginDestinationService {
);
// Perf.Opt.: this map is used to cache the keys and thus the JSON.stringify will not be called for each key request
const cachedKey = new Map<Vertex, string>();
clearComputeShortestPathsCache();

const neighbors = computeNeighbors(edges, cachedKey);
const vertices = topoSort(neighbors, cachedKey);
// In theory we could parallelize the pathfindings, but the overhead might be too big.
const res = new Map<string, [number, number]>();
odNodes.forEach((origin) => {
odNodes.forEach((origin, idx) => {
console.log("computeShortestPaths", idx, odNodes.length);
computeShortestPaths(origin.getId(), neighbors, vertices, tsSuccessor, cachedKey).forEach(
(value, key) => {
res.set([origin.getId(), key].join(","), value);
Expand All @@ -93,7 +96,9 @@ export class OriginDestinationService {

const rows = [];
odNodes.sort((a, b) => a.getBetriebspunktName().localeCompare(b.getBetriebspunktName()));
odNodes.forEach((origin) => {
odNodes.forEach((origin, idx) => {
console.log("compute o/d pairs", idx, odNodes.length);

odNodes.forEach((destination) => {
if (origin.getId() === destination.getId()) {
return;
Expand Down
Loading