示例#1
0
class Record:
    country_name: str = desert.field(
        marshmallow.fields.Str(data_key="Country Name"))
    country_code: str = desert.field(
        marshmallow.fields.Str(data_key="Country Code"))
    year: int = desert.field(marshmallow.fields.Int(data_key="Year"))
    value: float = desert.field(marshmallow.fields.Float(data_key="Value"))
class Sentence(DataclassSchema):
    """
    A Sentence object.

    Parameters
    ----------
    sentence_type :
        the sentence type
    program_period : optional
        the program period
    sentence_length : optional
        the length of the sentence
    sentence_dt :
        the date of the sentence
    """

    sentence_type: str
    sentence_dt: str = desert.field(
        TimeField(format="%m/%d/%Y", allow_none=True))
    program_period: str = ""
    sentence_length: str = ""

    def __repr__(self):
        cls = self.__class__.__name__
        if not pd.isna(self.sentence_dt):
            dt = self.sentence_dt.strftime("%m/%d/%y")
            dt = f"'{dt}'"
        else:
            dt = "NaT"
        s = f"sentence_dt={dt}, sentence_type='{self.sentence_type}'"
        return f"{cls}({s})"
示例#3
0
class Record:
    rowid: int
    day: datetime.date
    country_or_region: str
    province_or_state: Optional[str]
    admin2: Optional[str]
    fips: Optional[str]
    confirmed: Optional[int]
    deaths: Optional[int]
    recovered: Optional[int]
    active: Optional[int]
    latitude: Optional[str]
    longitude: Optional[str]
    last_update: datetime.datetime = desert.field(DateTime())
    combined_key: Optional[str]
示例#4
0
 class A:
     x: str = desert.field(marshmallow.fields.NaiveDateTime(),
                           metadata={"foo": 1})
示例#5
0
 class A:
     x: str = desert.field(marshmallow.fields.NaiveDateTime())
class Docket(DataclassSchema):
    """
    A Docket object.

    Parameters
    ----------
    docket_number :
        the docket number
    proc_status :
        the status of the docket proceedings
    dc_no :
        the DC incident number
    otn :
        the offense tracking number
    arrest_dt :
        the arrest date
    county :
        the PA county where case is being conducted
    status :
        the docket status as determined by the section on the court
        summary, e.g., "Active", "Closed", etc.
    extra :
        list of any additional header info for the docket
    psi_num : optional
        pre-sentence investigation number
    prob_num : optional
        the probation number
    disp_date : optional
        date of disposition
    disp_judge : optional
        the disposition judge
    def_atty : optional
        the name of the defense attorney
    trial_dt : optional
        the date of the trial
    legacy_no : optional
        the legacy number for the docket
    last_action : optional
        the last action in the case
    last_action_date : optional
        the date of the last action
    last_action_room : optional
        the room where last action occurred
    next_action : optional
        the next action to occur
    next_action_date : optional
        the date of the next action
    next_action_room : optional
        the room where next action will occur
    charges : optional
        a list of charges associated with this case
    """

    docket_number: str
    proc_status: str
    dc_no: str
    otn: str
    county: str
    status: str
    extra: List[Any]
    arrest_dt: str = desert.field(TimeField(format="%m/%d/%Y",
                                            allow_none=True))
    psi_num: str = ""
    prob_num: str = ""
    disp_judge: str = ""
    def_atty: str = ""
    legacy_no: str = ""
    last_action: str = ""
    last_action_room: str = ""
    next_action: str = ""
    next_action_room: str = ""
    next_action_date: Optional[str] = desert.field(TimeField(format="%m/%d/%Y",
                                                             allow_none=True),
                                                   default="")
    last_action_date: Optional[str] = desert.field(TimeField(format="%m/%d/%Y",
                                                             allow_none=True),
                                                   default="")
    trial_dt: Optional[str] = desert.field(TimeField(format="%m/%d/%Y",
                                                     allow_none=True),
                                           default="")
    disp_date: Optional[str] = desert.field(TimeField(format="%m/%d/%Y",
                                                      allow_none=True),
                                            default="")
    charges: List[Charge] = field(default_factory=list)

    def to_pandas(self) -> pd.DataFrame:
        """
        Return a dataframe representation of the data,
        where each row represents a separate charge.
        """
        # Each row is a Charge
        out = pd.DataFrame([c.to_dict() for c in self])

        # Convert sentences dicts to Sentence objects
        out["sentences"] = out["sentences"].apply(
            lambda l: [Sentence(**v) for v in l])
        return out

    @property
    def meta(self):
        """A dict of the meta info associated with the docket"""

        exclude = ["charges"]
        return {
            f.name: getattr(self, f.name)
            for f in fields(self) if f.name not in exclude
        }

    def __getitem__(self, index):
        """Index the charges."""
        return self.charges.__getitem__(index)

    def __iter__(self) -> Iterator[Charge]:
        """Iterate through the charges."""
        return iter(self.charges)

    def __len__(self):
        """The number of charges."""
        return len(self.charges)

    def __repr__(self):
        cls = self.__class__.__name__

        if not pd.isna(self.arrest_dt):
            dt = self.arrest_dt.strftime("%m/%d/%y")
            dt = f"'{dt}'"
        else:
            dt = "NaT"

        s = [
            f"{self.docket_number}",
            str(self.status),
            f"arrest_dt={dt}",
            f"num_charges={len(self)}",
        ]
        return f"{cls}({', '.join(s)})"
示例#7
0
 class A:
     x: datetime.datetime = desert.field(
         marshmallow.fields.NaiveDateTime(),
         metadata={"foo": 1},
     )
示例#8
0
 class A:
     x: datetime.datetime = desert.field(marshmallow.fields.NaiveDateTime())