This is a test task project
October 27, 2023 ยท View on GitHub
How to start
- Clone the project.
- Extract
env.zipfile. There is an.envfile with secrets. - Run
docker-compose up - Visit http://localhost:8000/
- To run tests, run
docker-compose run --rm backend python manage.py test
Bonus features
- Hot module replacement.
- REST API.
- Fully typed API client is generated and front is compiled automatically once a change in backend code is saved.
- Working autocomplete for the API on front.
- Front does not compile when API calls are broken.
- React is served by backend to be as close as possible to production environment setup.
- Material UI.
Notes about the tasks
OAUTH
On the backend it's implemented using allauth. On the frontend, see
frontend/src/components/LoginButton/LoginButton.tsx file.
The button submits allauth login form, all the rest is done under the hood.
The form logic and button layout are encapsulated, for ease of adding more of them.
Parsing
See backend/core/parser.py The main method is Parser.parse.
spaCy is used for NLP where needed. The logic of parsing is next:
- Split the input into paragraphs.
- Find the paragraph which is most likely responsible for period by looking for the amount related keywords and dates.
- Within that paragraph, find all dates without year, as we are not interested in absolute dates.
- Make consecutive start-end periods from the dates found. If distance between 2 consecutive dates is more than 1 day it is considered a period.
- Find the paragraph which is most likely responsible for contribution amounts by looking for the amount related keywords and dates.
- Find all the % and $ amounts.
- If there is only one value in a group, it's considered maximum (there is no reason to provide only minimum contribution amount).
- If there are values in both groups, then the output is
x% or $y.
Request processing
- Browser sends request to the
backendservice. backendservice looks forwebpack-stats.jsonfile in thefrontend/builddirectory.backendservice reads the bundle file address fromwebpack-stats.json.backendservice renders the page with the bundle.
API client sync flow
- Developer changes its files of the
backendservice, which triggers its reload. backendservice generatesbackend/conf/openapi_schema.jsonfile withopenapischema.api-client-builderservice detects the change in the file and runs API client generation.- API client generation modifies files in
frontend/src/apidirectory, which triggers frontend recompile. - On recompile, web page reloads.