def sla_daily_miss(sla_run_detail):
    """SLA miss table which gives us details about the date, SLA miss % on that date and top DAG violators for the long timeframe.

    Args:
        sla_run_detail (dataframe): Table consiting of details of all the dag runs that happened

    Returns:
        dataframe: sla_daily_miss output dataframe
    """
    try:

        sla_pastweek_run_count_df = sla_run_detail[sla_run_detail["start_date"].between(
            long_timeframe_start_date, today)]

        daily_sla_miss_count = sla_run_detail[sla_run_detail["duration"] > sla_run_detail["sla"]][
            sla_run_detail["start_date"].between(long_timeframe_start_date, today)].sort_values(["start_date"])

        daily_sla_miss_count_datewise = (daily_sla_miss_count.groupby(
            ["start_dt"]).size().to_frame(name="slamiss_count_datewise").reset_index())
        daily_sla_count_df = (daily_sla_miss_count.groupby(["start_dt", "dag_id",
                                                            "task_id"]).size().to_frame(name="size").reset_index())
        daily_sla_totalcount_datewise = (sla_pastweek_run_count_df.groupby(
            ["start_dt"]).size().to_frame(name="total_count").sort_values("start_dt", ascending=False).reset_index())
        daily_sla_totalcount_datewise_taskwise = (sla_pastweek_run_count_df.groupby(
            ["start_dt", "dag_id",
             "task_id"]).size().to_frame(name="totalcount").sort_values("start_dt", ascending=False).reset_index())
        daily_sla_miss_pct_df = pd.merge(daily_sla_miss_count_datewise, daily_sla_totalcount_datewise, on=["start_dt"])
        daily_sla_miss_pct_df["sla_miss_percent"] = (daily_sla_miss_pct_df["slamiss_count_datewise"] * 100 /
                                                     daily_sla_miss_pct_df["total_count"]).round(2)
        daily_sla_miss_pct_df["sla_miss_percent(missed_tasks/total_tasks)"] = daily_sla_miss_pct_df.apply(
            lambda x: "%s%s(%s/%s)" % (x["sla_miss_percent"], "% ", x["slamiss_count_datewise"], x["total_count"]),
            axis=1,
        )

        daily_sla_miss_percent = daily_sla_miss_pct_df.filter(
            ["start_dt", "sla_miss_percent(missed_tasks/total_tasks)"], axis=1)
        daily_sla_miss_df_pct1 = pd.merge(
            daily_sla_count_df,
            daily_sla_totalcount_datewise_taskwise,
            on=["start_dt", "dag_id", "task_id"],
        )
        daily_sla_miss_df_pct1["pct_violator"] = (daily_sla_miss_df_pct1["size"] * 100 /
                                                  daily_sla_miss_df_pct1["totalcount"]).round(2)
        daily_sla_miss_df_pct_kpi = (daily_sla_miss_df_pct1.sort_values("pct_violator",
                                                                        ascending=False).groupby("start_dt",
                                                                                                 sort=False).head(1))

        daily_sla_miss_df_pct_kpi["top_pct_violator"] = daily_sla_miss_df_pct_kpi.apply(
            lambda x: "%s: %s (%s%s" % (x["dag_id"], x["task_id"], x["pct_violator"], "%)"),
            axis=1,
        )

        daily_slamiss_percent_violator = daily_sla_miss_df_pct_kpi.filter(["start_dt", "top_pct_violator"], axis=1)
        daily_slamiss_df_absolute_kpi = (daily_sla_miss_df_pct1.sort_values("size", ascending=False).groupby(
            "start_dt", sort=False).head(1))

        daily_slamiss_df_absolute_kpi["top_absolute_violator"] = daily_slamiss_df_absolute_kpi.apply(
            lambda x: "%s: %s (%s/%s)" % (x["dag_id"], x["task_id"], x["size"], x["totalcount"]),
            axis=1,
        )

        daily_slamiss_absolute_violator = daily_slamiss_df_absolute_kpi.filter(["start_dt", "top_absolute_violator"],
                                                                               axis=1)
        daily_slamiss_pct_last7days = pd.merge(
            pd.merge(daily_sla_miss_percent, daily_slamiss_percent_violator, on="start_dt"),
            daily_slamiss_absolute_violator,
            on="start_dt",
        ).sort_values("start_dt", ascending=False)

        daily_slamiss_pct_last7days = daily_slamiss_pct_last7days.rename(
            columns={
                "top_pct_violator": "Top Violator (%)",
                "top_absolute_violator": "Top Violator (absolute)",
                "start_dt": "Date",
                "sla_miss_percent(missed_tasks/total_tasks)": "SLA Miss % (Missed/Total Tasks)",
            })
        return daily_slamiss_pct_last7days
    except:
        daily_slamiss_pct_last7days = pd.DataFrame(
            columns=["Date", "SLA Miss % (Missed/Total Tasks)", "Top Violator (%)", "Top Violator (absolute)"])
        return daily_slamiss_pct_last7days
SLA miss table which gives us details about the date, SLA miss % on that date and top DAG violators for the long timeframe.

    Args:
        sla_run_detail (dataframe): Table consiting of details of all the dag runs that happened

    Returns:
        dataframe: sla_daily_miss output dataframe
    
sla-miss-report/airflow-sla-miss-report.py