-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
api/core/models.py
Outdated
|
||
class Event(models.Model): | ||
cruise = models.ForeignKey(Cruise, on_delete=models.CASCADE, related_name='events') | ||
number = models.IntegerField() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
api/core/models.py
Outdated
|
||
class Underway(models.Model): | ||
cruise = models.ForeignKey(Cruise, on_delete=models.CASCADE, related_name='underway') | ||
start_month = models.IntegerField() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
api/events/services.py
Outdated
if matching_files: | ||
file_path = matching_files[0] | ||
with open(file_path, 'r') as file: | ||
reader = csv.DictReader(file) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
api/underway/api.py
Outdated
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
api/underway/services.py
Outdated
class UnderwayService: | ||
|
||
UNDERWAY_DATA_DIR = '/data/underway' | ||
object_store = FilesystemStore(UNDERWAY_DATA_DIR) |
There was a problem hiding this comment.
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)
api/underway/services.py
Outdated
end_year = end_date.year | ||
end_month = end_date.month | ||
|
||
Underway.objects.create( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
api/underway/services.py
Outdated
try: | ||
cruise = Cruise.objects.get(name__iexact=cruise_name) | ||
object_key = f"{cruise_name}{cls.FILE_SUFFIX}" | ||
data = cls.object_store.get(object_key) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
api/underway/services.py
Outdated
@classmethod | ||
def find_underway_files(cls, month: int, year: int) -> list[UnderwayOutput]: | ||
responses = [] | ||
underway_objects = Underway.objects.all() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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( ...
There was a problem hiding this comment.
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.
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.