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

Feature Request : logbook query to shows hours by aircraft #1026

Closed
joeaudette opened this issue May 8, 2023 · 8 comments
Closed

Feature Request : logbook query to shows hours by aircraft #1026

joeaudette opened this issue May 8, 2023 · 8 comments

Comments

@joeaudette
Copy link

I would like to see a new logbook query to show me how many hours I have in each aircraft.
I was able to write a query for it using external sqlite gui, but wish it could be built in.

SELECT
aircraft_name,
aircraft_type,
SUM(hours_flown) as total_hours
FROM
(
select
logbook_id,
aircraft_name,
aircraft_type,
CAST ((julianday(destination_time) - julianday(departure_time)) * 24 AS REAL) AS hours_flown
from logbook
WHERE
departure_time IS NOT NULL
AND destination_time IS NOT NULL
)
GROUP BY
aircraft_name,
aircraft_type
ORDER BY total_hours DESC
;

@albar965 albar965 self-assigned this May 9, 2023
@albar965 albar965 added this to the Release 2.8.11 milestone May 9, 2023
@albar965
Copy link
Owner

albar965 commented May 9, 2023

Makes sense since the other queries cannot be sorted by traveling time.
Thanks a lot for the query. 👍

@albar965
Copy link
Owner

Fixed (and much more) with 5dcb3ba

@joeaudette
Copy link
Author

I wish I had thought of it sooner, but it is trivial to also include count of flights per aircraft in the same query.

SELECT aircraft_name, aircraft_type, SUM(hours_flown) as total_hours, COUNT(*) AS total_flights
FROM (select logbook_id, aircraft_name, aircraft_type,
CAST ((julianday(destination_time) - julianday(departure_time)) * 24 AS REAL) AS hours_flown
from logbook
WHERE departure_time IS NOT NULL AND destination_time IS NOT NULL)
GROUP BY
aircraft_name,
aircraft_type
ORDER BY total_hours DESC
;

@albar965
Copy link
Owner

No problem. Still fixing small bugs here and there anyway. 🙂

@joeaudette
Copy link
Author

I promise, this is the last one, but this occurred to me tonight and seems very nice to have, last_flight and first_flight per aircraft.
Note it requires adding departure_time to the sub query in main from clause.

SELECT aircraft_name, aircraft_type, SUM(hours_flown) as total_hours, COUNT(*) AS total_flights, MAX(departure_time) AS last_flight, MIN(departure_time) AS first_flight
FROM (select logbook_id, aircraft_name, aircraft_type, departure_time,
CAST ((julianday(destination_time) - julianday(departure_time)) * 24 AS REAL) AS hours_flown
from logbook
WHERE departure_time IS NOT NULL AND destination_time IS NOT NULL)
GROUP BY
aircraft_name,
aircraft_type
ORDER BY total_hours DESC
;

@joeaudette
Copy link
Author

maybe avg_flt_hours is also interesting..

SELECT aircraft_name, aircraft_type, SUM(hours_flown) as total_hours, COUNT(*) AS total_flights, AVG(hours_flown) as avg_flt_hours, MAX(departure_time) AS last_flight, MIN(departure_time) AS first_flight
FROM (select logbook_id, aircraft_name, aircraft_type, departure_time,
CAST ((julianday(destination_time) - julianday(departure_time)) * 24 AS REAL) AS hours_flown
from logbook
WHERE departure_time IS NOT NULL AND destination_time IS NOT NULL)
GROUP BY
aircraft_name,
aircraft_type
ORDER BY total_hours DESC
;

@joeaudette
Copy link
Author

total_distance and avg_distance are also easy to include

SELECT aircraft_name, aircraft_type,
COUNT(*) AS total_flights,
SUM(hours_flown) as total_hours,
AVG(hours_flown) as avg_hours,
SUM(distance_flown) AS total_distance,
AVG(distance_flown) AS avg_distance,
MAX(departure_time) AS last_flight,
MIN(departure_time) AS first_flight
FROM (select logbook_id, aircraft_name, aircraft_type, departure_time, ifnull(distance_flown,0) AS distance_flown,
CAST ((julianday(destination_time) - julianday(departure_time)) * 24 AS REAL) AS hours_flown
from logbook
WHERE departure_time IS NOT NULL AND destination_time IS NOT NULL)
GROUP BY
aircraft_name,
aircraft_type
ORDER BY total_hours DESC
;

@albar965
Copy link
Owner

albar965 commented Jun 3, 2023

Good I made the stats code more flexible. 🙂
I can add these too. No problem. Still reorganizing code and fixing bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants