this looks an awful like https://github.com/dimagi/dimagi-utils/blob/master/dimagi/utils/data/generator.py