brafdlog / caspion

Automated budget tracking from Israeli financial institutions
https://www.caspion.org
MIT License
202 stars 45 forks source link

Take category classification logic from a json instead of code and expose it in the configuration screen #31

Open brafdlog opened 4 years ago

brafdlog commented 4 years ago

Currently the logic for classifying a transaction relies on the categoryCalculationScript.js. Most of the logic there is matching patterns of descriptions to patterns or exact matches. In order to make this easily configurable by the user, we want to move this logic to a json configuration that will contain the list of patterns and exact matches. After this is taken from the json, expose a ui for managing this in the config screen.

Notes:

  1. We need to allow people to have their own setup - both control category names and control the mapping, because this is something that is not consistent across people and across budgeting tools. In the future we may consider having this configuration per output vendor.
  2. We want this to work both in development from the repository and for the released electron app.
  3. When running for the first time (either in dev or released electron app) should work with a default configuration without requiring an initial setup.
  4. In future consider supporting regex patterns, but not required for initial phase.
  5. Write unit tests for this logic.

Proposed solution:

The getCategoryNameByTransactionDescription will fetch this json and use it to get the transaction category according to the following logic:

Look for an exact match for the transaction description string in the exactMatches arrays.

If not found fall back to looking for substring matches in the patternMatches arrays.

JSON structure:

{
  "exactMatches": {
    "electricity": ["חברת חשמל", "חיוב חשמל חודשי"],
    "groceries": ["המכולת של יהונתן", "המכולת של ברוך"]
  },
  "patternMatches": {
    "car maintenance": ["מוסך", "טסט"],
    "groceries": ["מכולת"]
  }
}

This json should be saved in a place where it can be used both in development and in release. There are a few options to implement this, see open questions.

Have a defaultCategoryMapping.json file committed to git. If the user has no mapping logic defined yet, take the default and save it as the user's json for future customization.

Open questions:

  1. Should this be part of the config or separate json?
  2. Where should this be stored? Could be a json file or local storage etc. See: https://medium.com/cameron-nokes/how-to-store-user-data-in-electron-3ba6bf66bc1e
  3. Need to verify it works nicely with Hebrew category names and patterns.
brafdlog commented 4 years ago

@baruchiro I updated the description, please take a look and see what you think.

github-actions[bot] commented 2 weeks ago

Issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.