Skip to content

Commit

Permalink
Remove estimated_cells value in the response.
Browse files Browse the repository at this point in the history
  • Loading branch information
danpat committed Nov 2, 2018
1 parent 985ab58 commit 364e35a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 75 deletions.
5 changes: 0 additions & 5 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ curl 'http://router.project-osrm.org/table/v1/driving/13.388860,52.517037;13.397
the i-th waypoint to the j-th waypoint. Values are given in meters. Can be `null` if no route between `i` and `j` can be found. Note that computing the `distances` table is currently only implemented for CH. If `annotations=distance` or `annotations=duration,distance` is requested when running a MLD router, a `NotImplemented` error will be returned.
- `sources` array of `Waypoint` objects describing all sources in order
- `destinations` array of `Waypoint` objects describing all destinations in order
- `estimated_cells` (optional) array of arrays containing `i,j` pairs indicating which cells contain estimated values based on `fallback_speed`. Will be absent if `fallback_speed` is not used.

In case of error the following `code`s are supported in addition to the general ones:

Expand Down Expand Up @@ -385,10 +384,6 @@ All other properties might be undefined.
2361.73,
0
]
],
"estimated_cells": [
[ 0, 1 ],
[ 1, 0 ]
]
}
```
Expand Down
1 change: 0 additions & 1 deletion docs/nodejs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
Values are given in seconds.
**`sources`**: array of [`Ẁaypoint`](#waypoint) objects describing all sources in order.
**`destinations`**: array of [`Ẁaypoint`](#waypoint) objects describing all destinations in order.
**`estimated_cells`**: (optional) if `fallback_speed` is used, will be an array of arrays of `row,column` values, indicating which cells contain estimated values.

### tile

Expand Down
32 changes: 7 additions & 25 deletions features/step_definitions/distance_matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ var util = require('util');
module.exports = function () {
const durationsRegex = new RegExp(/^I request a travel time matrix I should get$/);
const distancesRegex = new RegExp(/^I request a travel distance matrix I should get$/);
const estimatesRegex = new RegExp(/^I request a travel time matrix I should get estimates for$/);

const DURATIONS_NO_ROUTE = 2147483647; // MAX_INT
const DISTANCES_NO_ROUTE = 3.40282e+38; // MAX_FLOAT

this.When(durationsRegex, function(table, callback) {tableParse.call(this, table, DURATIONS_NO_ROUTE, 'durations', callback);}.bind(this));
this.When(distancesRegex, function(table, callback) {tableParse.call(this, table, DISTANCES_NO_ROUTE, 'distances', callback);}.bind(this));
this.When(estimatesRegex, function(table, callback) {tableParse.call(this, table, DISTANCES_NO_ROUTE, 'estimated_cells', callback);}.bind(this));
};

const durationsParse = function(v) { return isNaN(parseInt(v)); };
const distancesParse = function(v) { return isNaN(parseFloat(v)); };
const estimatesParse = function(v) { return isNaN(parseFloat(v)); };

function tableParse(table, noRoute, annotation, callback) {

const parse = annotation == 'distances' ? distancesParse : (annotation == 'durations' ? durationsParse : estimatesParse);
const parse = annotation == 'distances' ? distancesParse : durationsParse;
const params = this.queryParams;
params.annotations = ['durations','estimated_cells'].includes(annotation) ? 'duration' : 'distance';
params.annotations = annotation == 'distances' ? 'distance' : 'duration';

var tableRows = table.raw();

Expand Down Expand Up @@ -64,26 +61,11 @@ function tableParse(table, noRoute, annotation, callback) {

var json = JSON.parse(response.body);

var result = {};
if (annotation === 'estimated_cells') {
result = table.raw().map(row => row.map(cell => ''));
json[annotation].forEach(pair => {
result[pair[0]+1][pair[1]+1] = 'Y';
});
result = result.slice(1).map(row => {
var hashes = {};
row.slice(1).forEach((v,i) => {
hashes[tableRows[0][i+1]] = v;
});
return hashes;
});
} else {
result = json[annotation].map(row => {
var hashes = {};
row.forEach((v, i) => { hashes[tableRows[0][i+1]] = parse(v) ? '' : v; });
return hashes;
});
}
var result = json[annotation].map(row => {
var hashes = {};
row.forEach((v, i) => { hashes[tableRows[0][i+1]] = parse(v) ? '' : v; });
return hashes;
});

var testRow = (row, ri, cb) => {
for (var k in result[ri]) {
Expand Down
7 changes: 0 additions & 7 deletions features/testbot/duration_matrix.feature
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,6 @@ Feature: Basic Duration Matrix
| f | 18 | 12 | 0 | 30 |
| 1 | 30 | 24 | 30 | 0 |

When I request a travel time matrix I should get estimates for
| | a | b | f | 1 |
| a | | | Y | Y |
| b | | | Y | Y |
| f | Y | Y | | |
| 1 | Y | Y | | |

Scenario: Testbot - Filling in noroutes with estimates - use input coordinate
Given a grid size of 300 meters
Given the extract extra arguments "--small-component-size 4"
Expand Down
28 changes: 0 additions & 28 deletions include/engine/api/table_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ namespace api
class TableAPI final : public BaseAPI
{
public:
struct TableCellRef
{
TableCellRef(const std::size_t &row, const std::size_t &column) : row{row}, column{column}
{
}
std::size_t row;
std::size_t column;
};

TableAPI(const datafacade::BaseDataFacade &facade_, const TableParameters &parameters_)
: BaseAPI(facade_, parameters_), parameters(parameters_)
{
Expand All @@ -48,7 +39,6 @@ class TableAPI final : public BaseAPI
virtual void
MakeResponse(const std::pair<std::vector<EdgeDuration>, std::vector<EdgeDistance>> &tables,
const std::vector<PhantomNode> &phantoms,
const std::vector<TableCellRef> &estimated_cells,
util::json::Object &response) const
{
auto number_of_sources = parameters.sources.size();
Expand Down Expand Up @@ -87,11 +77,6 @@ class TableAPI final : public BaseAPI
MakeDistanceTable(tables.second, number_of_sources, number_of_destinations);
}

if (parameters.fallback_speed > 0)
{
response.values["estimated_cells"] = MakeEstimatesTable(estimated_cells);
}

response.values["code"] = "Ok";
}

Expand Down Expand Up @@ -178,19 +163,6 @@ class TableAPI final : public BaseAPI
return json_table;
}

virtual util::json::Array
MakeEstimatesTable(const std::vector<TableCellRef> &estimated_cells) const
{
util::json::Array json_table;
std::for_each(estimated_cells.begin(), estimated_cells.end(), [&](const auto &cell) {
util::json::Array row;
row.values.push_back(util::json::Number(cell.row));
row.values.push_back(util::json::Number(cell.column));
json_table.values.push_back(std::move(row));
});
return json_table;
}

const TableParameters &parameters;
};

Expand Down
6 changes: 1 addition & 5 deletions src/engine/plugins/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
return Error("NoTable", "No table found", result);
}

std::vector<api::TableAPI::TableCellRef> estimated_pairs;

// Scan table for null results - if any exist, replace with distance estimates
if (params.fallback_speed > 0)
{
Expand Down Expand Up @@ -127,15 +125,13 @@ Status TablePlugin::HandleRequest(const RoutingAlgorithmsInterface &algorithms,
{
result_tables_pair.second[table_index] = distance_estimate;
}

estimated_pairs.emplace_back(row, column);
}
}
}
}

api::TableAPI table_api{facade, params};
table_api.MakeResponse(result_tables_pair, snapped_phantoms, estimated_pairs, result);
table_api.MakeResponse(result_tables_pair, snapped_phantoms, result);

return Status::Ok;
}
Expand Down
6 changes: 2 additions & 4 deletions test/nodejs/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ tables.forEach(function(annotation) {
});

test('table: ' + annotation + ' table in Monaco without motorways', function(assert) {
assert.plan(2);
assert.plan(1);
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
var options = {
coordinates: two_test_coordinates,
Expand All @@ -243,12 +243,11 @@ tables.forEach(function(annotation) {
};
osrm.table(options, function(err, response) {
assert.equal(response[annotation].length, 2);
assert.strictEqual(response.estimated_cells, undefined);
});
});

test('table: ' + annotation + ' table in Monaco with fallback speeds', function(assert) {
assert.plan(2);
assert.plan(1);
var osrm = new OSRM({path: mld_data_path, algorithm: 'MLD'});
var options = {
coordinates: two_test_coordinates,
Expand All @@ -258,7 +257,6 @@ tables.forEach(function(annotation) {
};
osrm.table(options, function(err, response) {
assert.equal(response[annotation].length, 2);
assert.equal(response['estimated_cells'].length, 0);
});
});

Expand Down

0 comments on commit 364e35a

Please sign in to comment.