mysociety / mysoc-validator

Pydantic validators for mySociety democracy types
MIT License
0 stars 0 forks source link

Overlapping time ranges #2

Open ajparsons opened 3 weeks ago

ajparsons commented 3 weeks ago

Currently present in main people.json for about 230 memberships.

Generally I think the rule is these shouldn't happen - and could be added as a test (and fixed).

here is now twfy-votes-django is now sorting this:

def adjust_overlapping_time_ranges(popolo: Popolo, quiet: bool = False) -> Popolo:
    """
    Calculating down the line depend on consecutive time ranges rather than an overlap on the end date
    Ideally addressed at source.
    """
    count = 0
    for person in popolo.persons:
        person = person.self_or_redirect()
        memberships = person.memberships()
        memberships.sort(key=lambda m: m.start_date)
        for i, membership in enumerate(memberships[:-1]):
            next_membership = memberships[i + 1]
            if membership.end_date == next_membership.start_date:
                if membership.organization_id != next_membership.organization_id:
                    continue
                membership.end_date = membership.end_date - datetime.timedelta(days=1)  # type: ignore
                count += 1

    if not quiet:
        rich.print(f"Adjusted [blue]{count}[/blue] overlapping time ranges")

    return popolo

The org_id bit there isn't actually right - for what we want it should also check the post__org_id - but there's no actual error in doing it this way (just to be sure if validaoting future errors).

ajparsons commented 3 weeks ago

Note that there are a few lords even worse than this (and a set of 19th C MPs we care less about) - with completely overlapping memberships