Skip to content

Commit

Permalink
Handle no financial year in an empty dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
mjennings061 committed Aug 15, 2024
1 parent 8785247 commit 796e945
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import streamlit as st
from typing import List
from io import BytesIO
from datetime import datetime

# User defined modules.
from log_keeper.ingest import ingest_log_sheet, sanitise_log_sheets
Expand Down Expand Up @@ -61,7 +62,7 @@ def get_financial_year(df) -> int:
int: The financial year"""
# Check if the DataFrame is empty.
if df.empty:
return None
return datetime.now().year

# Get the last date in the DataFrame
last_date = df['Date'].iloc[0]
Expand Down
69 changes: 51 additions & 18 deletions src/log_keeper/get_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Get packages.
import inquirer
import logging
from datetime import datetime
import random
from datetime import datetime, timedelta
from pathlib import Path
from dataclasses import dataclass, field
from typing import Optional
Expand Down Expand Up @@ -162,23 +163,55 @@ def get_launches_dataframe(self):

@staticmethod
def dummy_launches_dataframe():
"""Create a dummy DataFrame."""
dummy_data = {
"Date": [datetime.now()],
"Aircraft": ["ZE123"],
"AircraftCommander": ["Sgt Smith"],
"SecondPilot": ["Cpl Jones"],
"Duty": ["Sesh"],
"FlightTime": [int(1)],
"TakeOffTime": [datetime.now()],
"LandingTime": [datetime.now()],
"SPC": [1],
"P1": False,
"P2": False,
}
# Repeat the dummy data to display the columns.
df = pd.DataFrame(dummy_data)
df = pd.concat([df] * 10, ignore_index=True)
"""Create a dummy DataFrame with varied data."""
n_days = 10
n_rep = 30
base_date = datetime.now().replace(
hour=0, minute=0, second=0, microsecond=0
)
dates = [base_date - timedelta(days=i*7) for i in range(n_days)]

all_data = []

aircraft_list = ["ZE123", "ZE456", "ZE321", "ZE654", "ZE118"]
commanders = ["Jennings", "White, C", "Abbott", "MacGregor", "Philips"]
second_pilots = ["Jones", "Clarke", "Taylor", "White", "Green"]
duties = ["SCT U/T", "GIF", "SCT QGI", "AGT", "G/S"]

for day in sorted(dates):
take_off_times = [
day + timedelta(hours=random.randint(6, 12))
for _ in range(n_rep)
]
flight_time = [random.randint(5, 10) for _ in range(n_rep)]
landing_times = [
take_off_times[i] + timedelta(minutes=flight_time[i])
for i in range(n_rep)
]

daily_data = {
"Date": [day for _ in range(n_rep)],
"Aircraft": [
random.choice(aircraft_list) for _ in range(n_rep)
],
"AircraftCommander": [
random.choice(commanders) for _ in range(n_rep)
],
"SecondPilot": [
random.choice(second_pilots) for _ in range(n_rep)
],
"Duty": [random.choice(duties) for _ in range(n_rep)],
"FlightTime": flight_time,
"TakeOffTime": take_off_times,
"LandingTime": landing_times,
"SPC": [random.randint(0, 5) for _ in range(n_rep)],
"P1": [random.choice([True, False]) for _ in range(n_rep)],
"P2": [random.choice([True, False]) for _ in range(n_rep)],
}

all_data.append(pd.DataFrame(daily_data))

df = pd.concat(all_data, ignore_index=True)
return df


Expand Down

0 comments on commit 796e945

Please sign in to comment.