Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label Refactor #1712

Merged
merged 10 commits into from
Sep 16, 2023
Merged

Label Refactor #1712

merged 10 commits into from
Sep 16, 2023

Conversation

JeremyC3
Copy link
Contributor

@JeremyC3 JeremyC3 commented Sep 7, 2023

Refactored label grouping algorithm as per #1711. As a result, one backend test case was changed to list charge grouping as "Eligible NOW If Balance Paid on case with Ineligible charge".

Changed grouping algorithm to sort by label and case number only, removed secondary date sort to ensure that charges with the same case number are properly grouped. Will re-introduce if users find new sorting less useful.

@@ -38,6 +38,8 @@ def build_charges_for_summary_panel(record: Record) -> ChargesForSummaryPanel:
@staticmethod
def _primary_sort(charge: Charge, record: Record):
charge_eligibility = charge.expungement_result.charge_eligibility

charge_dict = {"nma":0,"ine":1,"nnn":2, "nni":3, "ncn":4, "nci":5, "fnn":6, "fcn":7, "fni":8, "fci":9 }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use an str, Enum and spell these out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can spell out the different charges, but could you elaborate a bit on the benefits of enum vs. a regular dict for this? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't that different - just a bit more robust. I also just prefer not to abbreviate. For example, I don't know what fni means.

@@ -15,10 +15,10 @@ def build_charges_for_summary_panel(record: Record) -> ChargesForSummaryPanel:
]
eligible_charges_by_date: List[Tuple[str, List[Tuple[str, List[Tuple[str, str]]]]]] = []
sorted_charges = sorted(
sorted(visible_charges, key=ChargesSummarizer._secondary_sort, reverse=True),
visible_charges,
#sorted(visible_charges, key=ChargesSummarizer._secondary_sort, reverse=True),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to delete all comments as the git history keeps them anyways

@JeremyC3
Copy link
Contributor Author

@KentShikama changes made to utilize an str,Enum with written-out classifications instead of a dict. Removed pre-existing comment about order now each classification is written out. Manually cast Enum back into an int on line 83 due to typecasting errors occurring when using IntEnum

Copy link
Member

@KentShikama KentShikama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do something like

ChargeList.NEEDS_MORE_ANALYSIS

It effectively just acts as a labelled integer. I realized since you just want an integer here you can just use class Foo(Enum):

Copy link
Member

@KentShikama KentShikama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore what I said earlier. I finally understand what you were trying to do with the +=. Basically a clever way to append on a prefix. I would prefer if we just built up boolean variables and then had a function at the end instead of int(ChargeList[classification]).

def function(foo, bar, baz):
    if foo and bar and baz:
        return 7
    if foo and bar and not baz:
        return 8

@JeremyC3
Copy link
Contributor Author

Reverted the sorting logic back to if statements, changed no_balance label to has_balance to match the other variable case_has_ineligible_charge

@@ -5,7 +5,7 @@
from expungeservice.models.record_summary import ChargesForSummaryPanel
from expungeservice.util import DateWithFuture as date
from typing import Dict, List, Tuple

from enum import Enum
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this import?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, thanks for the catch! removing now.

Copy link
Member

@KentShikama KentShikama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@KentShikama KentShikama merged commit 7bc1fbc into codeforpdx:master Sep 16, 2023
@KentShikama
Copy link
Member

You know about https://dev.recordsponge.com/ right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants