seems fine
This commit is contained in:
parent
48983e3b4b
commit
7a1696541f
37 changed files with 4999 additions and 1242 deletions
|
|
@ -65,7 +65,7 @@ public class App {
|
|||
String[] originNames = places.names();
|
||||
double[] originLats = places.lats(), originLons = places.lons();
|
||||
int nOrigins = originLats.length;
|
||||
System.err.printf(" %,d places (total)%n", nOrigins);
|
||||
System.err.printf(" %,d travel-eligible places%n", nOrigins);
|
||||
|
||||
// Filter places to England only (must be near at least one England postcode)
|
||||
Set<Integer> englandIndices = filterEnglandPlaces(
|
||||
|
|
@ -89,7 +89,7 @@ public class App {
|
|||
System.err.printf("DEMO MODE: %d places (transit only)%n", originIndices.length);
|
||||
for (int i : originIndices) System.err.printf(" - %s%n", originNames[i]);
|
||||
} else {
|
||||
// Normal mode: use all England places
|
||||
// Normal mode: use all travel-eligible England places
|
||||
originIndices = englandIndices.stream().sorted()
|
||||
.mapToInt(Integer::intValue).toArray();
|
||||
modes = MODES;
|
||||
|
|
|
|||
|
|
@ -59,9 +59,15 @@ public class Parquet {
|
|||
/** Load places deduplicated by lat/lon, write reference parquet, return names + flat lat/lon arrays. */
|
||||
static Places loadPlaces(String parquetPath, Path refOut) throws Exception {
|
||||
try (DuckDBConnection conn = connect(); Statement stmt = conn.createStatement()) {
|
||||
stmt.execute("CREATE TABLE all_places AS SELECT * FROM read_parquet('"
|
||||
+ escapePath(parquetPath) + "')");
|
||||
boolean hasTravelDestination = tableHasColumn(stmt, "all_places", "travel_destination");
|
||||
String source = hasTravelDestination
|
||||
? "(SELECT * FROM all_places WHERE COALESCE(travel_destination, true))"
|
||||
: "all_places";
|
||||
stmt.execute("CREATE TABLE places AS SELECT * EXCLUDE (rn) FROM ("
|
||||
+ "SELECT *, ROW_NUMBER() OVER (PARTITION BY lat, lon) AS rn "
|
||||
+ "FROM read_parquet('" + escapePath(parquetPath) + "')) WHERE rn = 1");
|
||||
+ "FROM " + source + " AS p) WHERE rn = 1");
|
||||
copyToParquet(stmt, "SELECT * FROM places", refOut);
|
||||
|
||||
try (ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM places")) {
|
||||
|
|
@ -85,6 +91,17 @@ public class Parquet {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean tableHasColumn(Statement stmt, String tableName, String columnName)
|
||||
throws Exception {
|
||||
try (ResultSet rs = stmt.executeQuery(
|
||||
"SELECT COUNT(*) FROM information_schema.columns "
|
||||
+ "WHERE table_name = '" + tableName + "' "
|
||||
+ "AND column_name = '" + columnName + "'")) {
|
||||
rs.next();
|
||||
return rs.getInt(1) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** Write postcode travel times as a ZSTD-compressed parquet (atomic via tmp + rename). */
|
||||
static void writeTravelTimes(DuckDBConnection conn, Path outPath, String[] postcodes, short[] times)
|
||||
throws Exception {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue