blob: 780fcdc043750f9bd19a6d9e7f9cd6e50a8f1397 [file] [log] [blame]
--
-- Copyright 2019 The Android Open Source Project
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
CREATE VIEW battery_view AS
SELECT
all_ts.ts as ts,
current_avg_ua,
capacity_percent,
charge_uah,
current_ua
FROM (SELECT distinct(ts) AS ts
FROM counters
WHERE name LIKE 'batt.%') AS all_ts
LEFT JOIN(
SELECT ts, value AS current_avg_ua
FROM counters
WHERE name='batt.current.avg_ua')
USING(ts)
LEFT JOIN(
SELECT ts, value AS capacity_percent
FROM counters
WHERE name='batt.capacity_pct')
USING(ts)
LEFT JOIN(
SELECT ts, value AS charge_uah
FROM counters
WHERE name='batt.charge_uah')
USING(ts)
LEFT JOIN(
SELECT ts, value AS current_ua
FROM counters
WHERE name='batt.current_ua')
USING(ts)
ORDER BY ts;
CREATE VIEW android_batt_output AS
SELECT AndroidBatteryMetric(
'battery_counters', (
SELECT RepeatedField(BatteryCounters(
'timestamp_ns', ts,
'charge_counter_uah', charge_uah,
'capacity_percent', capacity_percent,
'current_ua', current_ua,
'current_avg_ua', current_avg_ua)) FROM battery_view)
);