better ui

This commit is contained in:
didier committed 2025-01-05 19:43:30 -05:00
1 parent e0b0ca48f2
commit 84abee712d
6 files changed
+66 -17

No files matched your search

+9 -9
View File
@@ -4,9 +4,9 @@ namespace YongeStreet.Services;
public record Road(int RelationId, List<List<double>> Points);
public record CityOverview(string Name, double TotalStreetSize, IList<int> AvailableYears);
public record CityOverview(string Name, double TotalStreetSize, IList<DateOnly> AvailableDates);
public record CityRoadLengthStats(string Name, double MunicipalRoadLength, int Year);
public record CityRoadLengthStats(string Name, double MunicipalRoadLength, DateOnly Date);
public class DataService
{
@@ -20,7 +20,7 @@ public class DataService
"unclassified"];
private readonly string path = "/home/didier/dev/YongeStreet/real.duckdb";
public IList<Road> GetRoads(string city, int year)
public IList<Road> GetRoads(string city, DateOnly extractDate)
{
using var duckDBConnection = new DuckDBConnection($"Data Source={path};ACCESS_MODE=READ_ONLY");
duckDBConnection.Open();
@@ -34,7 +34,7 @@ public class DataService
AND list_contains($allowed_highway, highway)
""";
command.Parameters.Add(new DuckDBParameter("city_name", city));
command.Parameters.Add(new DuckDBParameter("extract_date", new DateOnly(year, 1, 1)));
command.Parameters.Add(new DuckDBParameter("extract_date", extractDate));
command.Parameters.Add(new DuckDBParameter("allowed_highway", CITY_STREET_HIGHWAY));
using var reader = command.ExecuteReader();
@@ -57,7 +57,7 @@ public class DataService
command.CommandText = """
SELECT city_name,
SUM(length) FILTER (list_contains($allowed_highway, highway) AND extract_date = (Date '2025-01-01')) AS length,
LIST(DISTINCT extract('year' FROM extract_date)) AS available_years
LIST(DISTINCT extract_date) AS available_years
FROM city_road
GROUP BY city_name
ORDER BY length desc
@@ -70,7 +70,7 @@ public class DataService
while (reader.Read())
ret.Add(new CityOverview(reader.GetString(0),
reader.GetDouble(1),
reader.GetFieldValue<List<int>>(2)));
reader.GetFieldValue<List<DateOnly>>(2)));
return ret;
}
@@ -83,11 +83,11 @@ public class DataService
using var command = duckDBConnection.CreateCommand();
command.CommandText = """
SELECT SUM(length) FILTER (list_contains($allowed_highway, highway)) AS length,
extract('year' FROM extract_date) AS year
extract_date AS date
FROM city_road
WHERE city_name = $city_name
GROUP BY extract_date
ORDER BY year DESC
ORDER BY date DESC
""";
command.Parameters.Add(new DuckDBParameter("city_name", city));
command.Parameters.Add(new DuckDBParameter("allowed_highway", CITY_STREET_HIGHWAY));
@@ -98,7 +98,7 @@ public class DataService
{
ret.Add(new CityRoadLengthStats(city,
reader.GetInt32(0),
reader.GetInt32(1)));
reader.GetFieldValue<DateOnly>(1)));
}
return ret;