def compute_analysis_end_date(conn, curr_date):
    'Function to get the end of the analysis window based on current operator data.'
    end_date = curr_date
    if (end_date is None):
        with conn.cursor() as cursor:
            monthly_country_child_tbl_list = child_table_names(conn, 'monthly_network_triplets_country')
            year_month_list_in_child_tbls_records = table_invariants_list(conn, monthly_country_child_tbl_list, ['triplet_year', 'triplet_month'])
            year_month_tuple_list = [(x.triplet_year, x.triplet_month) for x in year_month_list_in_child_tbls_records]
            if (len(year_month_tuple_list) > 0):
                year_month_tuple_list.sort(key=(lambda x: (x[0], x[1])), reverse=True)
                (latest_year, latest_month) = year_month_tuple_list[0]
                cursor.execute(sql.SQL('SELECT MAX(last_seen)\n                                            FROM monthly_network_triplets_country\n                                           WHERE triplet_year = %s\n                                             AND triplet_month = %s'), [latest_year, latest_month])
                end_date = cursor.fetchone()[0]
    if (end_date is None):
        end_date = datetime.date.today()
    return (end_date + datetime.timedelta(days=1))
Function to get the end of the analysis window based on current operator data.
def compute_analysis_end_date(conn, curr_date):
    
    end_date = curr_date
    if (end_date is None):
        with conn.cursor() as cursor:
            monthly_country_child_tbl_list = child_table_names(conn, 'monthly_network_triplets_country')
            year_month_list_in_child_tbls_records = table_invariants_list(conn, monthly_country_child_tbl_list, ['triplet_year', 'triplet_month'])
            year_month_tuple_list = [(x.triplet_year, x.triplet_month) for x in year_month_list_in_child_tbls_records]
            if (len(year_month_tuple_list) > 0):
                year_month_tuple_list.sort(key=(lambda x: (x[0], x[1])), reverse=True)
                (latest_year, latest_month) = year_month_tuple_list[0]
                cursor.execute(sql.SQL('SELECT MAX(last_seen)\n                                            FROM monthly_network_triplets_country\n                                           WHERE triplet_year = %s\n                                             AND triplet_month = %s'), [latest_year, latest_month])
                end_date = cursor.fetchone()[0]
    if (end_date is None):
        end_date = datetime.date.today()
    return (end_date + datetime.timedelta(days=1))