A few links that might be useful if you've not already seen them...
- Tracking progress docs: https://docs.moodle.org/38/en/Tracking_progress (I suspect the built-in reports described here should do what you want.)
- Custom report plugins:
- Report plugin dev docs: https://docs.moodle.org/dev/Reports
HTH,
Dave.