Last active
January 17, 2017 15:34
-
-
Save kyle-eshares/287a305583259159a2081513c3134f2a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# computations.py | |
def add_shareholder_name(shareholder_ix): | |
def inner(flat, mdl): | |
flat.shareholder_name = shareholder_ix[mdl.shareholder_id] | |
return inner | |
def add_transfered_to_labels(transfered_to_ix): | |
def inner(flat, mdl): | |
flat.exercised_from_labels = [ | |
sec.label for sec in transfered_to_ix[mdl.id] | |
] | |
return inner | |
... | |
# data.py | |
all_securities = list(Security.objects.filter(company=company).all()) | |
all_shareholders = list(ShareHolders.objects.filter(company=company).all()) | |
# Many to One | |
shareholder_ix = {sh.pk: sh for shareholder in all_shareholders} | |
# Reverse foreign key | |
transfered_to_ix = defaultdict(list) | |
for security in all_securities: | |
if security.transformed_from_id: | |
transfered_to_ix[security.transformed_from_id].append(security) | |
flat_securities = ( | |
conduit(all_securities) | |
... | |
.filter(should_show_security) # Filter securities since now we grab all of them | |
.map( | |
flatten( | |
... | |
add_shareholder_name(shareholder_ix), | |
add_transfered_to_labels(transfered_to_ix) | |
) | |
) | |
... | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment