AssemblyLine.al_courts
Package for a very simple / MVP list of courts that is mostly signature compatible w/ MACourts for now
ALCourt Objects
class ALCourt(Court)
Object representing a court in Massachusetts. We use a function on the CourtList object that filters courts by address and can use any of those three features of the court to do the filtering.
<!-- TODO: it could be interesting to store a jurisdiction on a court. But this is non-trivial. Should it be geo boundaries? A list of cities? A list of counties? Instead, we use a function on the CourtList object that filters courts by address and can use any of those three features of the court to do the filtering.-->
init
def init(*pargs, **kwargs) -> None
Create a new court object.
Arguments
*pargs
- Standard DAObject positional arguments**kwargs
- Standard DAObject keyword arguments
short_label
def short_label() -> str
Returns a string that represents a nice, disambiguated label for the court. This may not match the court's name. If the name omits city, we append city name to the court name. This is good for a drop-down selection list.
Returns
str
- string representing the court's name, with city if needed to disambiguate
short_label_and_address
def short_label_and_address() -> str
Returns a markdown formatted string with the name and address of the court. More concise version without description; suitable for a responsive case.
Returns
str
- string representing the court's name and address
short_description
def short_description() -> str
Returns a Markdown formatted string that includes the disambiguated name and the description of the court, for inclusion in the results page with radio buttons.
Returns
str
- string representing the court's name and description
from_row
def from_row(df_row: Union[pd.Series, pd.DataFrame],
ensure_lat_long: bool = True) -> None
Loads data from a single Pandas Dataframe into the current court object. Note: It will try to convert column names that don't make valid attributes. Best practice is to use good attribute names (no spaces) that don't interfere with existing attributes or methods of DAObject
Arguments
df_row
- Pandas Series objectensure_lat_long
- bool, whether to use Google Maps to geocode the address if we don't have coordinates
geolocate
def geolocate() -> None
Use Google Maps to geocode the court's address and store the result in the location attribute.
Deprecated: use geocode() instead.
geocode
def geocode() -> None
Use Google Maps to geocode the court's address and store the result in the location attribute.
ALCourtLoader Objects
class ALCourtLoader(DAObject)
Object to hold some methods surrounding loading/filtering courts.
Built around Pandas dataframe.
Attributes
filename
str - Path to the file containing court information.converters
Dict[str, Callable] - A dictionary of functions to apply to columns in the dataframe.
init
def init(*pargs, **kwargs) -> None
Create a new courtloader object.
Arguments
*pargs
- Standard DAObject positional arguments**kwargs
- Standard DAObject keyword arguments
all_courts
def all_courts() -> List[Tuple[int, str]]
Return a list of all courts in the spreadsheet.
Returns
List[Tuple[int, str]]: List of tuples where each tuple contains (dataframe_index, display_value). The dataframe_index (int) can be used with as_court() to retrieve the full court object. The display_value (str) is the court's name or other display column value.
unique_column_values
def unique_column_values(column_name: str) -> Set[str]
Retrieve a set of unique values present in a specified dataframe column.
Arguments
column_name
str - The name of the column in the dataframe.
Returns
Set[str]:
- A set containing unique values from the specified column.
- Returns an empty set if the column does not exist or an error occurs.
county_list
def county_list(column_name: str = "address_county") -> Set[str]
Get a set of all unique names for the specified column in the given spreadsheet. Typically used to get a list of all possible counties that have a court.
Arguments
column_name
str - The name of the column in the dataframe.
Returns
Set[str]
- A list of all unique values in the specified row in the given spreadsheet
county_has_one_court
def county_has_one_court(county_name: str,
county_column: str = "address_county") -> bool
Returns True if there is only one court associated with the specified county in the spreadsheet. Returns False otherwise.
Arguments
county_name
str - The name of the county to check.county_column
str - The name of the column in the dataframe that contains the county names. Defaults to "address_county".
Returns
bool
- True if there is only one court associated with the specified county in the spreadsheet.
county_court
def county_court(intrinsicName: str,
county_name: str,
county_column: str = "address_county") -> ALCourt
Return the first court matching the county name. Should only be used when you know there is exactly one match
Arguments
intrinsicName
str - The intrinsic name you want the newly returned object to have (used for DA namespace searching).county_name
str - The name of the county to check.county_column
str - The name of the column in the dataframe that contains the county names. Defaults to "address_county".
Returns
ALCourt
- The first court matching the county name.
matching_courts_in_county
def matching_courts_in_county(
county_name: str,
county_column: str = "address_county",
display_column: str = "name",
search_string: Optional[str] = None,
search_columns: Optional[Union[List[str], str]] = None
) -> List[Tuple[int, str]]
Retrieve a list of all courts in the specified county.
This function fetches courts suitable for displaying as a drop-down or radio button list in Docassemble. The results are tuples where the first element is the dataframe index (useful for retrieving the court's full details later using the as_court() method) and the second element is the display value from the specified display_column.
Arguments
county_name
str - Name of the county.county_column
str, optional - Column heading which contains county name. Defaults to "address_county".display_column
str, optional - Column heading used for display in the drop-down. Defaults to "name".search_string
Optional[str], optional - A keyword to filter the list of results. Defaults to None.search_columns
Optional[Union[List[str], str]], optional - Columns to aggregate and search across with the search_string in a case-insensitive manner. Defaults to None.
Returns
List[Tuple[int, str]]: List of tuples where each tuple contains (dataframe_index, display_value). The dataframe_index (int) can be used with as_court() to retrieve the full court object. The display_value (str) is the court's name or other display column value.
filter_courts
def filter_courts(
court_types: Optional[Union[List[str], str]],
column: str = "department",
display_column: str = "name",
search_string: Optional[str] = None,
search_columns: Optional[Union[List[str], str]] = None
) -> List[Tuple[int, str]]
Return a filtered subset of courts represented as a list of tuples.
Each tuple has the format (index, display_value), where "index" refers to the dataframe index and "display_value"
is determined by the display_column
.
Arguments
court_types
Optional[Union[List[str], str]] - Exact string match or matches used to filter results (inclusive). Examples include "District" or ["Municipal","Superior"].column
str, optional - Column heading to search. Defaults to "department".display_column
str, optional - Column heading used for display in the drop-down. Defaults to "name".search_string
Optional[str], optional - A keyword to filter the list of results. Defaults to None.search_columns
Optional[Union[List[str], str]], optional - Columns to aggregate and search across with the search_string in a case-insensitive manner. Defaults to None.
Returns
List[Tuple[int, str]]: List of tuples where each tuple contains (dataframe_index, display_value). The dataframe_index (int) can be used with as_court() to retrieve the full court object. The display_value (str) is the court's name or other display column value.
as_court
def as_court(intrinsicName: str,
index: Union[int, str],
ensure_lat_long: bool = True) -> ALCourt
Retrieve the court at the specified index as an ALCourt object.
Arguments
intrinsicName
str - The intrinsic name you want to assign to the returned object (used for DA namespace searching).index
Union[int, str] - The index position of the court in the dataframe.ensure_lat_long
bool, optional - Whether to ensure the presence of latitude and longitude data. Defaults to True.
Returns
ALCourt
- An ALCourt object initialized with data from the specified index.