distribution_fit_utils.DistributionFitUtils
distribution_fit_utils.DistributionFitUtils(
file_path,
calculate_school_holidays=False,
school_holidays_years=0,
)The DistributionFitUtils classa
This class will import a CSV, undertake some light wrangling and then determine distributions and probabilities required for the Discrete Event Simulation
example usage: my_data = DistributionFitUtils(‘data/my_data.csv’) my_data.import_and_wrangle()
Methods
| Name | Description |
|---|---|
| activity_time_distributions | Determine the ‘best’ distribution for each phase of a call |
| ad_hoc_unavailability | Calculate aircraft availability and unavailability probabilities based on scheduled rotas and ad-hoc downtime. |
| age_distributions | Determine the ‘best’ distribution for age stratified by |
| callsign_group | Calculates the probabilty of a specific callsign being allocated to |
| callsign_group_by_ampds_card_and_hour_probs | Calculates the probabilty of a specific callsign being allocated to |
| callsign_group_by_ampds_card_probs | Calculates the probabilty of a specific callsign being allocated to |
| enhanced_or_critical_care_by_ampds_card_probs | Calculates the probabilty of enhanced or critical care resource beign required |
| getBestFit | Convenience function for Fitter. |
| hems_result_by_callsign_group_and_vehicle_type_probs | Calculates the probabilty of a specific HEMS result being allocated to |
| hems_results_by_patient_outcome_and_time_of_day_and_quarter_and_vehicle_type_and_callsign_group_probs | Calculates the probabilty of a given HEMS result based on |
| historical_care_cat_counts | Process historical incident data to categorize care types and compute hourly counts. |
| historical_median_time_of_activities_by_month_and_resource_type | Calculate the median time for each of the job cycle phases stratified by month and vehicle type |
| historical_monthly_resource_utilisation | Calculates number of, and time spent on, incidents per month stratified by callsign |
| historical_monthly_totals | Calculates monthly incident totals from provided dataset of historical data |
| historical_monthly_totals_all_calls | Calculates monthly incident totals from provided dataset of historical data stratified by callsign |
| historical_monthly_totals_by_callsign | Calculates monthly incident totals from provided dataset of historical data stratified by callsign |
| historical_monthly_totals_by_day_of_week | Calculates number of incidents per month stratified by day of the week |
| historical_monthly_totals_by_hour_of_day | Calculates monthly incident totals from provided dataset of historical data stratified by hour of the day |
| hour_by_ampds_card_probs | Calculates the proportions of calls that are triaged with |
| hourly_arrival_by_qtr_probs | Calculates the proportions of calls arriving in any given hour |
| import_and_wrangle | Function to import CSV, add additional columns that are required |
| incidents_per_day | Fit distributions for number of incidents per day using actual daily counts, |
| incidents_per_day_samples | Create weighted empirical samples of incidents per day by season and quarter. |
| patient_outcome_by_care_category_and_quarter_probs | Calculates the probabilty of a patient outcome based on care category and yearly quarter |
| removeExistingResults | Removes results from previous fitting |
| school_holidays | ” |
| sex_by_ampds_card_probs | Calculates the probability that the patient will be female |
| upper_allowable_time_bounds | Calculates the maximum permissable time for each phase on an incident based on supplied historical data. |
| vehicle_type_by_quarter_probs | Calculates the probabilty of a car/helicopter being allocated to |
| vehicle_type_probs | Calculates the probabilty of a car/helicopter being allocated to |
activity_time_distributions
distribution_fit_utils.DistributionFitUtils.activity_time_distributions()Determine the ‘best’ distribution for each phase of a call i.e. Allocation time, Mobilisation time, Time to scene Time on scene, Travel time to hospital and handover, Time to clear. Not all times will apply to all cases, so the class ‘times_to_fit’ variable is a list of dictionaries, which contains the times to fit
The data is currently stratitied by HEMS_result and vehicle type fields.
age_distributions
distribution_fit_utils.DistributionFitUtils.age_distributions()Determine the ‘best’ distribution for age stratified by AMPDS card
callsign_group
distribution_fit_utils.DistributionFitUtils.callsign_group()Calculates the probabilty of a specific callsign being allocated to a call
callsign_group_by_ampds_card_and_hour_probs
distribution_fit_utils.DistributionFitUtils.callsign_group_by_ampds_card_and_hour_probs(
)Calculates the probabilty of a specific callsign being allocated to a call based on the AMPDS card category and hour of day
callsign_group_by_ampds_card_probs
distribution_fit_utils.DistributionFitUtils.callsign_group_by_ampds_card_probs()Calculates the probabilty of a specific callsign being allocated to a call based on the AMPDS card category
enhanced_or_critical_care_by_ampds_card_probs
distribution_fit_utils.DistributionFitUtils.enhanced_or_critical_care_by_ampds_card_probs(
)Calculates the probabilty of enhanced or critical care resource beign required based on the AMPDS card
getBestFit
distribution_fit_utils.DistributionFitUtils.getBestFit(
q_times,
distr=get_common_distributions(),
show_summary=False,
)Convenience function for Fitter. Returns model and parameters that is considered the ‘best fit’.
TODO: Determine how Fitter works this out
hems_result_by_callsign_group_and_vehicle_type_probs
distribution_fit_utils.DistributionFitUtils.hems_result_by_callsign_group_and_vehicle_type_probs(
)Calculates the probabilty of a specific HEMS result being allocated to a call based on the callsign group and hour of day
TODO: These probability calculation functions could probably be refactored into a single function and just specify columns and output name
hems_results_by_patient_outcome_and_time_of_day_and_quarter_and_vehicle_type_and_callsign_group_probs
distribution_fit_utils.DistributionFitUtils.hems_results_by_patient_outcome_and_time_of_day_and_quarter_and_vehicle_type_and_callsign_group_probs(
)Calculates the probabilty of a given HEMS result based on - patient outcome - yearly quarter - time of day (7am - 6pm, 7pm - 6am) - vehicle type - and callsign group
historical_care_cat_counts
distribution_fit_utils.DistributionFitUtils.historical_care_cat_counts()Process historical incident data to categorize care types and compute hourly counts.
This method performs the following steps: - Converts incident dates to datetime format. - Extracts month start and hour from the incident date. - Categorizes each incident into care categories based on benefit flags and attendance. - Counts the number of incidents by hour and care category. - Outputs these counts to a CSV file. - Computes and writes the proportion of regular care jobs with a helicopter benefit (excluding those not attended by a DAA resource) to a text file.
Outputs: - CSV file: ‘historical_data/historical_care_cat_counts.csv’ - Text file: ‘distribution_data/proportion_jobs_heli_benefit.txt’
historical_median_time_of_activities_by_month_and_resource_type
distribution_fit_utils.DistributionFitUtils.historical_median_time_of_activities_by_month_and_resource_type(
)Calculate the median time for each of the job cycle phases stratified by month and vehicle type
historical_monthly_resource_utilisation
distribution_fit_utils.DistributionFitUtils.historical_monthly_resource_utilisation(
)Calculates number of, and time spent on, incidents per month stratified by callsign
historical_monthly_totals
distribution_fit_utils.DistributionFitUtils.historical_monthly_totals()Calculates monthly incident totals from provided dataset of historical data
historical_monthly_totals_all_calls
distribution_fit_utils.DistributionFitUtils.historical_monthly_totals_all_calls(
)Calculates monthly incident totals from provided dataset of historical data stratified by callsign
historical_monthly_totals_by_callsign
distribution_fit_utils.DistributionFitUtils.historical_monthly_totals_by_callsign(
)Calculates monthly incident totals from provided dataset of historical data stratified by callsign
historical_monthly_totals_by_day_of_week
distribution_fit_utils.DistributionFitUtils.historical_monthly_totals_by_day_of_week(
)Calculates number of incidents per month stratified by day of the week
historical_monthly_totals_by_hour_of_day
distribution_fit_utils.DistributionFitUtils.historical_monthly_totals_by_hour_of_day(
)Calculates monthly incident totals from provided dataset of historical data stratified by hour of the day
hour_by_ampds_card_probs
distribution_fit_utils.DistributionFitUtils.hour_by_ampds_card_probs()Calculates the proportions of calls that are triaged with a specific AMPDS card. This is stratified by hour of day
TODO: Determine whether this should also be stratified by yearly quarter
hourly_arrival_by_qtr_probs
distribution_fit_utils.DistributionFitUtils.hourly_arrival_by_qtr_probs()Calculates the proportions of calls arriving in any given hour stratified by yearly quarter
import_and_wrangle
distribution_fit_utils.DistributionFitUtils.import_and_wrangle()Function to import CSV, add additional columns that are required and then sequentially execute other class functions to generate the probabilities and distributions required for the DES.
TODO: Additional logic is required to check the imported CSV for missing values, incorrect columns names etc.
incidents_per_day
distribution_fit_utils.DistributionFitUtils.incidents_per_day()Fit distributions for number of incidents per day using actual daily counts, applying year-based weighting to reflect trends (e.g., 2024 busier than 2023), stratified by season and quarter.
incidents_per_day_samples
distribution_fit_utils.DistributionFitUtils.incidents_per_day_samples(
weight_map=None,
scale_factor=10,
)Create weighted empirical samples of incidents per day by season and quarter.
patient_outcome_by_care_category_and_quarter_probs
distribution_fit_utils.DistributionFitUtils.patient_outcome_by_care_category_and_quarter_probs(
)Calculates the probabilty of a patient outcome based on care category and yearly quarter
removeExistingResults
distribution_fit_utils.DistributionFitUtils.removeExistingResults(folder)Removes results from previous fitting
school_holidays
distribution_fit_utils.DistributionFitUtils.school_holidays()” Function to generate a CSV file containing schoole holiday start and end dates for a given year. The Year range is determined by the submitted data (plus a year at the end of the study for good measure)
sex_by_ampds_card_probs
distribution_fit_utils.DistributionFitUtils.sex_by_ampds_card_probs()Calculates the probability that the patient will be female stratified by AMPDS card.
upper_allowable_time_bounds
distribution_fit_utils.DistributionFitUtils.upper_allowable_time_bounds()Calculates the maximum permissable time for each phase on an incident based on supplied historical data. This is currently set to 1.5x the upper quartile of the data distribution
vehicle_type_by_quarter_probs
distribution_fit_utils.DistributionFitUtils.vehicle_type_by_quarter_probs()Calculates the probabilty of a car/helicopter being allocated to a call based on the callsign group and quarter of the year
Quarter accounts for seasonal variation without being as affected by
vehicle_type_probs
distribution_fit_utils.DistributionFitUtils.vehicle_type_probs()Calculates the probabilty of a car/helicopter being allocated to a call based on the callsign group