Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events and Underway #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Events and Underway #2

wants to merge 3 commits into from

Conversation

joannekoch
Copy link
Contributor

@joannekoch joannekoch commented Jan 7, 2025

Add Events and Underway end points.

Installs amplify-storage-utils and uses FilesystemStore.

To test: http://localhost:8000/api/docs#/

Set up local vast mount dir in .env until we can access vast nfs mount on a vm.

@joannekoch joannekoch added the enhancement New feature or request label Jan 7, 2025
@joannekoch joannekoch self-assigned this Jan 7, 2025
@joefutrelle joefutrelle self-requested a review January 28, 2025 15:15

class Event(models.Model):
cruise = models.ForeignKey(Cruise, on_delete=models.CASCADE, related_name='events')
number = models.IntegerField()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the "message ID" from the e-log and so could be renamed to make more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed number to message_id


class Underway(models.Model):
cruise = models.ForeignKey(Cruise, on_delete=models.CASCADE, related_name='underway')
start_month = models.IntegerField()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use timestamps instead of integer year/month

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamps used instead of year/month

return EventService.get_events(cruise_name)


@router.post("filter/{cruise_name}", response=List[EventOutput])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could data serving endpoints be GETs instead of POSTs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't use GET here because there is data supplied to filter the events

if matching_files:
file_path = matching_files[0]
with open(file_path, 'r') as file:
reader = csv.DictReader(file)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Pandas for CSV data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used Pandas for CSV data.



@staticmethod
def delete_events(cruise_name: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to history when you delete an event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this deletes all the events for a cruise. when they are deleted, the history is deleted.

def get_underway_column_headers(request, cruise_name: str):
return UnderwayService.get_column_headers(cruise_name)

@router.get("find/{month}/{year}", response=List[UnderwayOutput]) #fix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accept time range? (see above comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change to accept start and end time

class UnderwayService:

UNDERWAY_DATA_DIR = '/data/underway'
object_store = FilesystemStore(UNDERWAY_DATA_DIR)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with object store client (not for this PR)

end_year = end_date.year
end_month = end_date.month

Underway.objects.create(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use update_or_create here? (or whatever it's called

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed code to use update_or_create instead of create

try:
cruise = Cruise.objects.get(name__iexact=cruise_name)
object_key = f"{cruise_name}{cls.FILE_SUFFIX}"
data = cls.object_store.get(object_key)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at BufferStore from amplify-storage-utils as a possible simplification of parsing the CSV from the bytes object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BufferStore only does this which this code already does: b = BytesIO(data)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine not to use it.

@classmethod
def find_underway_files(cls, month: int, year: int) -> list[UnderwayOutput]:
responses = []
underway_objects = Underway.objects.all()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this query via the ORM?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g., Underway.objects.filter( ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

underway.objects.filter used instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants