Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Prereq Check #987

Merged
merged 15 commits into from
Jul 8, 2020
Merged
Prev Previous commit
Next Next commit
add queries to pre-bin histogram data
  • Loading branch information
liljonnystyle committed Jul 1, 2020
commit b83f0308d1f12928e3e3d76351fbb3db7a595ddb
56 changes: 56 additions & 0 deletions flow/data_pipeline/query.py
Original file line number Diff line number Diff line change
@@ -37,12 +37,18 @@
"fact_network_metrics_by_time_agg", {"FACT_VEHICLE_TRACE",
"POWER_DEMAND_MODEL_DENOISED_ACCEL"}
),
"FACT_VEHICLE_FUEL_EFFICIENCY_BINNED": (
"fact_vehicle_fuel_efficiency_binned", {"FACT_VEHICLE_FUEL_EFFICIENCY_AGG"}
),
"FACT_NETWORK_FUEL_EFFICIENCY_AGG": (
"fact_network_fuel_efficiency_agg", {"FACT_VEHICLE_FUEL_EFFICIENCY_AGG"}
),
"FACT_SAFETY_METRICS_AGG": (
"fact_safety_metrics_agg", {"FACT_SAFETY_METRICS"}
),
"FACT_SAFETY_METRICS_BINNED": (
"fact_safety_metrics_binned", {"FACT_SAFETY_METRICS"}
),
"LEADERBOARD_CHART": (
"leaderboard_chart", {"FACT_NETWORK_THROUGHPUT_AGG",
"FACT_NETWORK_FUEL_EFFICIENCY_AGG",
@@ -74,9 +80,11 @@
"fact_vehicle_counts_by_time",
"fact_safety_metrics",
"fact_safety_metrics_agg",
"fact_safety_metrics_binned",
"fact_network_throughput_agg",
"fact_network_inflows_outflows",
"fact_vehicle_fuel_efficiency_agg",
"fact_vehicle_fuel_efficiency_binned",
"fact_network_metrics_by_distance_agg",
"fact_network_metrics_by_time_agg",
"fact_network_fuel_efficiency_agg",
@@ -260,6 +268,30 @@ class QueryStrings(Enum):
AND date = \'{date}\'
AND partition_name = \'{partition}_FACT_SAFETY_METRICS\'
GROUP BY 1
;
"""

FACT_SAFETY_METRICS_BINNED = """
WITH bins AS (
SELECT
ROW_NUMBER() - 51 AS lb,
ROW_NUMBER() - 50 AS ub
FROM fact_safety_metrics
HAVING 1 = 1
AND lb >= -10
AND ub <= 10
)
SELECT
CONCAT('[', bins.lb, ', ', bins.ub, ')') AS safety_value_bin,
COUNT() AS count
FROM bins, fact_safety_metrics fsm
WHERE 1 = 1
AND fsm.date = \'{date}\'
AND fsm.partition_name = \'{partition}_FACT_SAFETY_METRICS\'
AND fsm.safety_value >= bins.lb
AND fsm.safety_value < bins.ub
GROUP BY 1
;
"""

FACT_NETWORK_THROUGHPUT_AGG = """
@@ -331,6 +363,30 @@ class QueryStrings(Enum):
;
"""

FACT_VEHICLE_FUEL_EFFICIENCY_BINNED = """
WITH bins AS (
SELECT
ROW_NUMBER() - 1 AS lb,
ROW_NUMBER() AS ub
FROM fact_safety_metrics
HAVING 1 = 1
AND lb >= 0
AND ub <= 20
)
SELECT
CONCAT('[', bins.lb, ', ', bins.ub, ')') AS fuel_efficiency_bin,
COUNT() AS count
FROM bins, fact_vehicle_fuel_efficiency_agg agg
WHERE 1 = 1
AND agg.date = \'{date}\'
AND agg.partition_name = \'{partition}_FACT_FUEL_EFFICIENCY_AGG\'
AND agg.energy_model_id = 'POWER_DEMAND_MODEL_DENOISED_ACCEL'
AND 1000 * agg.efficiency_meters_per_joules >= bins.lb
AND 1000 * agg.efficiency_meters_per_joules < bins.ub
GROUP BY 1
;
"""

FACT_NETWORK_FUEL_EFFICIENCY_AGG = """
SELECT
source_id,