-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from MetaCell/feature/SCKAN-364
SCKAN-364 feat: Add statement preview row to the export + persist statement preview suffix and prefix
- Loading branch information
Showing
7 changed files
with
263 additions
and
62 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
backend/composer/migrations/0068_connectivitystatement_statement_prefix_and_more.py
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 4.1.4 on 2024-12-18 15:59 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("composer", "0067_auto_20241218_0928"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="connectivitystatement", | ||
name="statement_prefix", | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="connectivitystatement", | ||
name="statement_suffix", | ||
field=models.TextField(blank=True, null=True), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.1.4 on 2024-12-18 15:59 | ||
|
||
from .helpers.statement_preview import get_migration_prefix_for_statement_preview, get_migration_suffix_for_statement_preview | ||
from django.db import migrations | ||
|
||
|
||
def update_suffix_prefix_for_connectivity_statement_fields(apps, schema_editor): | ||
ConnectivityStatement = apps.get_model('composer', 'ConnectivityStatement') | ||
for cs in ConnectivityStatement.objects.all(): | ||
cs.statement_prefix = get_migration_prefix_for_statement_preview(cs) | ||
cs.statement_suffix = get_migration_suffix_for_statement_preview(cs) | ||
cs.save(update_fields=["statement_prefix", "statement_suffix"]) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("composer", "0068_connectivitystatement_statement_prefix_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
update_suffix_prefix_for_connectivity_statement_fields) | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from composer.utils import join_entities | ||
from django.apps import apps | ||
|
||
|
||
def get_migration_prefix_for_statement_preview(cs) -> str: | ||
sex = cs.sex.name if cs.sex else None | ||
|
||
species_list = [ | ||
specie.name for specie in cs.species.all()] | ||
species = join_entities(species_list) | ||
if not species: | ||
species = "" | ||
|
||
phenotype = cs.phenotype.name if cs.phenotype else '' | ||
if sex or species != "": | ||
statement = f"In {sex or ''} {species}, the {phenotype.lower()} connection goes" | ||
else: | ||
statement = f"A {phenotype.lower()} connection goes" | ||
return statement | ||
|
||
|
||
def get_migration_suffix_for_statement_preview(cs): | ||
ConnectivityStatement = apps.get_model( | ||
'composer', 'ConnectivityStatement') | ||
connectivity_statement = ConnectivityStatement.objects.get( | ||
id=cs.id) | ||
|
||
circuit_type = connectivity_statement.get_circuit_type_display( | ||
) if connectivity_statement.circuit_type else None | ||
projection = connectivity_statement.get_projection_display( | ||
) if connectivity_statement.projection else None | ||
projection_phenotype = str( | ||
connectivity_statement.projection_phenotype) if connectivity_statement.projection_phenotype else '' | ||
|
||
laterality_description = connectivity_statement.get_laterality_description() | ||
apinatomy = connectivity_statement.apinatomy_model if connectivity_statement.apinatomy_model else "" | ||
|
||
origin_names = [ | ||
origin.name for origin in connectivity_statement.origins.all()] | ||
origins = join_entities(origin_names) | ||
|
||
if not origins: | ||
origins = "" | ||
|
||
statement = f"This " | ||
if projection: | ||
statement += f"{projection.lower()} " | ||
if projection_phenotype: | ||
statement += f"{projection_phenotype.lower()} " | ||
if circuit_type: | ||
statement += f"{circuit_type.lower()} " | ||
|
||
statement += f"connection projects from the {origins}." | ||
if laterality_description: | ||
statement = statement[:-1] + \ | ||
f" and is found {laterality_description}.\n" | ||
|
||
if apinatomy: | ||
statement += f" It is described in {apinatomy} model." | ||
return statement |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from ..utils import join_entities | ||
|
||
|
||
def get_prefix_for_statement_preview(cs) -> str: | ||
sex = cs.sex.name if cs.sex else None | ||
|
||
species_list = [ | ||
specie.name for specie in cs.species.all()] | ||
species = join_entities(species_list) | ||
if not species: | ||
species = "" | ||
|
||
phenotype = cs.phenotype.name if cs.phenotype else '' | ||
if sex or species != "": | ||
statement = f"In {sex or ''} {species}, the {phenotype.lower()} connection goes" | ||
else: | ||
statement = f"A {phenotype.lower()} connection goes" | ||
return statement | ||
|
||
|
||
def get_suffix_for_statement_preview(cs): | ||
|
||
circuit_type = cs.get_circuit_type_display( | ||
) if cs.circuit_type else None | ||
projection = cs.get_projection_display( | ||
) if cs.projection else None | ||
projection_phenotype = str( | ||
cs.projection_phenotype) if cs.projection_phenotype else '' | ||
|
||
laterality_description = cs.get_laterality_description() | ||
apinatomy = cs.apinatomy_model if cs.apinatomy_model else "" | ||
|
||
origin_names = [ | ||
origin.name for origin in cs.origins.all()] | ||
origins = join_entities(origin_names) | ||
|
||
if not origins: | ||
origins = "" | ||
|
||
statement = f"This " | ||
if projection: | ||
statement += f"{projection.lower()} " | ||
if projection_phenotype: | ||
statement += f"{projection_phenotype.lower()} " | ||
if circuit_type: | ||
statement += f"{circuit_type.lower()} " | ||
|
||
statement += f"connection projects from the {origins}." | ||
if laterality_description: | ||
statement = statement[:-1] + \ | ||
f" and is found {laterality_description}.\n" | ||
|
||
if apinatomy: | ||
statement += f" It is described in {apinatomy} model." | ||
return statement | ||
|
||
|
||
def create_statement_preview(cs, journey): | ||
prefix = cs.statement_prefix | ||
journey_sentence = '; '.join(journey) | ||
suffix = cs.statement_suffix | ||
statement = f'{prefix} {journey_sentence}.\n{suffix}' | ||
return statement.strip().replace(" ", " ") |
Oops, something went wrong.