Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:NASA-IMPACT/COSMOS into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonDavis committed Dec 19, 2024
2 parents e51ce45 + 9ebdae5 commit 8df561a
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 14 deletions.
14 changes: 7 additions & 7 deletions sde_collections/models/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ def workflow_status_button_color(self) -> str:
@property
def reindexing_status_button_color(self) -> str:
color_choices = {
1: "btn-light", # NOT_NEEDED
2: "btn-warning", # NEEDED
3: "btn-secondary", # FINISHED
4: "btn-info", # READY_FOR_CURATION
5: "btn-warning", # CURATION_IN_PROGRESS
6: "btn-primary", # CURATED
7: "btn-success", # INDEXED_ON_PROD
1: "btn-light", # REINDEXING_NOT_NEEDED
2: "btn-danger", # REINDEXING_NEEDED_ON_DEV (matching Ready For Engineering)
3: "btn-info", # REINDEXING_FINISHED_ON_DEV (matching Indexing Finished on LRM Dev)
4: "btn-info", # REINDEXING_READY_FOR_CURATION (matching Ready for Curation)
5: "btn-success", # REINDEXING_CURATION_IN_PROGRESS (matching Curation in Progress)
6: "btn-primary", # REINDEXING_CURATED (matching Curated)
7: "btn-primary", # REINDEXING_INDEXED_ON_PROD (matching Prod: Perfect)
}
return color_choices[self.reindexing_status]

Expand Down
90 changes: 90 additions & 0 deletions sde_collections/utils/README_PAIRED_FIELD_DESCRIPTOR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Paired Field Descriptor System

## Overview

The Paired Field Descriptor is a Django model descriptor designed to manage fields with both manual and machine learning (ML) generated variants. This system provides a flexible approach to handling metadata fields, with a focus on tag management and priority handling.

## Core Concepts

### Field Pairing Mechanism
The descriptor automatically creates two associated fields for each defined descriptor:
- **Manual Field**: Manually entered or curated metadata
- **ML Field**: Machine learning generated metadata

### Key Characteristics
- Manual field takes precedence over ML field
- Flexible field type support
- Handles empty arrays and None values
- Requires explicit setting of ML fields

## Implementation

### Creating a Paired Field Descriptor

```python
tdamm_tag = PairedFieldDescriptor(
field_name="tdamm_tag",
field_type=ArrayField(models.CharField(max_length=255, choices=TDAMMTags.choices), blank=True, null=True),
verbose_name="TDAMM Tags",
)
```

#### Parameters
- `field_name`: Base name for the descriptor
- `field_type`: Django field type (supports various field types)
- `verbose_name`: Optional human-readable name

### Field Naming Convention
When you define a descriptor, two additional fields are automatically created:
- `{field_name}_manual`: For manually entered values
- `{field_name}_ml`: For machine learning generated values

## Characteristics

### Field Priority
1. Manual field always takes precedence
2. ML field serves as a fallback
3. Empty manual fields or None values defer to ML field

### Field Retrieval
```python
# Retrieval automatically prioritizes manual field
tags = url.tdamm_tag # Returns manual tags if exist, otherwise ML tags
```

### Field Setting
```python
# Sets only the manual field
url.tdamm_tag = ["MMA_M_EM", "MMA_M_G"]

# ML field must be set explicitly
url.tdamm_tag_ml = ["MMA_O_BH"]
```

### Field Deletion
```python
# Deletes both manual and ML fields
del url.tdamm_tag
```

### Data Preservation
- Paired fields maintain their state during:
- Dump to Delta migration
- Delta to Curated promotion
- Manual entries take precedence in all migration stages

## Serializer Integration

Here's the way to configure the serializer to retrieve the paired field, seamlessly extracting either manual or ML tags based on the descriptor's priority rules.
```python
class DeltaUrlSerializer(serializers.ModelSerializer):
tdamm_tag = serializers.SerializerMethodField()

class Meta:
model = DeltaUrl
fields = ("url", "tdamm_tag")

def get_tdamm_tag(self, obj):
tags = obj.tdamm_tag
return tags if tags is not None else []
```
14 changes: 7 additions & 7 deletions sde_indexing_helper/static/js/delta_url_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2221,13 +2221,13 @@ function handleReindexingStatusSelect() {
case "changeReindexingStatus":
var color_choices = {
1: "btn-light", // REINDEXING_NOT_NEEDED
2: "btn-warning", // REINDEXING_NEEDED_ON_DEV
3: "btn-secondary", // REINDEXING_FINISHED_ON_DEV
4: "btn-info", // REINDEXING_READY_FOR_CURATION
5: "btn-warning", // REINDEXING_CURATION_IN_PROGRESS
6: "btn-primary", // REINDEXING_CURATED
7: "btn-success" // REINDEXING_INDEXED_ON_PROD
};
2: "btn-danger", // REINDEXING_NEEDED_ON_DEV (matching Ready For Engineering)
3: "btn-info", // REINDEXING_FINISHED_ON_DEV (matching Indexing Finished on LRM Dev)
4: "btn-info", // REINDEXING_READY_FOR_CURATION (matching Ready for Curation)
5: "btn-success", // REINDEXING_CURATION_IN_PROGRESS (matching Curation in Progress)
6: "btn-primary", // REINDEXING_CURATED (matching Curated)
7: "btn-primary" // REINDEXING_INDEXED_ON_PROD (matching Prod: Perfect)
};

$button = $(`#reindexing-status-button-${collection_id}`);

Expand Down

0 comments on commit 8df561a

Please sign in to comment.