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

Date column in Tasks section #689

Merged
merged 8 commits into from
Mar 17, 2023

Conversation

Angatupyry
Copy link
Collaborator

@Angatupyry Angatupyry commented Mar 13, 2023

What's new

Date column has been added in taskstate

This field is saved when the user creates a new task. It allows us to know when a task was created.
This field cannot be updated by the user.

Screenshot from 2023-03-13 16-38-07

Self-checks

  • I have prototyped this new feature (if necessary) on Figma
  • I'm familiar with and follow this Typescript guideline
  • I added unit-tests for new components
  • I tried testing edge cases
  • I tested the behavior of the components that interact with the backend, with an e2e test

Discussion

@codecov
Copy link

codecov bot commented Mar 13, 2023

Codecov Report

Merging #689 (2a0785a) into deploy/hammer (9b0d007) will decrease coverage by 0.75%.
The diff coverage is 28.40%.

@@                Coverage Diff                @@
##           deploy/hammer     #689      +/-   ##
=================================================
- Coverage          59.30%   58.55%   -0.75%     
=================================================
  Files                281      282       +1     
  Lines               5932     6093     +161     
  Branches             801      824      +23     
=================================================
+ Hits                3518     3568      +50     
- Misses              2260     2370     +110     
- Partials             154      155       +1     
Flag Coverage Δ
api-server 84.69% <94.11%> (+0.20%) ⬆️
dashboard 20.32% <0.00%> (-0.35%) ⬇️
react-components 58.33% <2.06%> (-2.40%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rver/api_server/models/tortoise_models/__init__.py 100.00% <ø> (ø)
...kages/dashboard/src/components/tasks/tasks-app.tsx 0.00% <0.00%> (ø)
...ackages/react-components/lib/tasks/create-task.tsx 1.31% <1.05%> (-0.04%) ⬇️
...react-components/lib/tasks/task-table-datagrid.tsx 60.97% <50.00%> (-0.57%) ⬇️
...i-server/api_server/routes/tasks/favorite_tasks.py 91.42% <91.42%> (ø)
...api-server/api_server/models/rmf_api/task_state.py 100.00% <100.00%> (ø)
...-server/api_server/models/tortoise_models/tasks.py 100.00% <100.00%> (ø)
...ckages/api-server/api_server/repositories/tasks.py 94.80% <100.00%> (+0.21%) ⬆️
...ges/api-server/api_server/routes/tasks/__init__.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@aaronchongth aaronchongth left a comment

Choose a reason for hiding this comment

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

Upon going through it in detail, I believe we might not need to update rmf_api_msgs, and the pydantic model as well, just an additional field to the tortoise model is sufficient.

It looks like we just need to modify https://github.com/open-rmf/rmf-web/blob/main/packages/api-server/api_server/repositories/tasks.py#L29-L46, where instead of ttm.TaskState.update_or_create, we can get_or_none, if it is not none, we copy the existing state's unix_millis_request_time, and update the model with that same request time.

Otherwise, we create a new one with the current time stamp for the request time. We can be sure that the first state we get to save is right after the request has been dispatched, since it is saved in this post call and this post call

This approach should be used for the upcoming column of task initiator too, using the dashboard's current user. Let me know what you think about this approach

@Angatupyry
Copy link
Collaborator Author

Upon going through it in detail, I believe we might not need to update rmf_api_msgs, and the pydantic model as well, just an additional field to the tortoise model is sufficient.

It looks like we just need to modify https://github.com/open-rmf/rmf-web/blob/main/packages/api-server/api_server/repositories/tasks.py#L29-L46, where instead of ttm.TaskState.update_or_create, we can get_or_none, if it is not none, we copy the existing state's unix_millis_request_time, and update the model with that same request time.

Otherwise, we create a new one with the current time stamp for the request time. We can be sure that the first state we get to save is right after the request has been dispatched, since it is saved in this post call and this post call

This approach should be used for the upcoming column of task initiator too, using the dashboard's current user. Let me know what you think about this approach

Hey, Aaron. I think your approach is ok and that's exactly what I'm trying to do here

async def save_task_state(self, task_state: TaskState) -> None:
        datetime_request_time = (
            datetime.fromtimestamp(task_state.unix_millis_request_time / 1000)
            if task_state.unix_millis_request_time
            else datetime.now()
        )
        task_state.unix_millis_request_time = (
            task_state.unix_millis_request_time
            if task_state.unix_millis_request_time
            else round(time.time() * 1000)
        )
        await ttm.TaskState.update_or_create(
            {
                "data": task_state.json(),
                "category": task_state.category.__root__
                if task_state.category
                else None,
                "assigned_to": task_state.assigned_to.name
                if task_state.assigned_to
                else None,
                "unix_millis_start_time": task_state.unix_millis_start_time
                and datetime.fromtimestamp(task_state.unix_millis_start_time / 1000),
                "unix_millis_finish_time": task_state.unix_millis_finish_time
                and datetime.fromtimestamp(task_state.unix_millis_finish_time / 1000),
                "status": task_state.status if task_state.status else None,
                "unix_millis_request_time": datetime_request_time,
            },
            id_=task_state.booking.id,
        )

But I also need to update the data field so that it can be displayed later in the dashboard.
And regarding displaying in the datagrid, how could we access the field without it existing here? The API client creates the interfaces depending on that class.
I consider that to save the data in the database the tortoise field is enough but to show it on the dashboard I consider that we also need the field in rmf_api (which does not necessarily have to depend on rmf_msgs_api and)

Copy link
Member

@aaronchongth aaronchongth left a comment

Choose a reason for hiding this comment

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

Doh! Thanks for explaining, I totally forgot that we are using the data JSON field, we should fix that at some point, I'll add a backburner task for that.

I've left some comments and suggestions, let me know what you think

packages/api-server/api_server/repositories/tasks.py Outdated Show resolved Hide resolved
packages/api-server/api_server/repositories/tasks.py Outdated Show resolved Hide resolved
Copy link
Member

@aaronchongth aaronchongth left a comment

Choose a reason for hiding this comment

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

Thanks for the quick rework! Tested and working great, LGTM

@aaronchongth aaronchongth merged commit 7ea986d into deploy/hammer Mar 17, 2023
@aaronchongth aaronchongth deleted the feature/add-unix-millis-request-time branch March 17, 2023 04:09
@aaronchongth aaronchongth mentioned this pull request Mar 17, 2023
5 tasks
aaronchongth pushed a commit that referenced this pull request Apr 16, 2023
* Add unix-millis-request-time field in taskstate

Signed-off-by: fierro <[email protected]>

* Generate taskstate model according to the rmf_api_msgs changes

Signed-off-by: fierro <[email protected]>

* Generate api client to get the new field

Signed-off-by: fierro <[email protected]>

* Save unix request time as now() and use previous value if the method is update

Signed-off-by: fierro <[email protected]>

* Show unix_millis_request_time in dashboard

Signed-off-by: fierro <[email protected]>

* Add Unix_millis_request_time into booking instead of taskstate directly

Signed-off-by: fierro <[email protected]>

* Access to unix_millis_request_time field through booking

Signed-off-by: fierro <[email protected]>

* Get previous task_state and if is not none use its request_time value

Signed-off-by: fierro <[email protected]>

---------

Signed-off-by: fierro <[email protected]>
(cherry picked from commit 7ea986d)
Signed-off-by: Aaron Chong <[email protected]>
@aaronchongth aaronchongth mentioned this pull request Apr 16, 2023
5 tasks
aaronchongth added a commit that referenced this pull request Jul 4, 2023
* Date column in Tasks section (#689)

* Add unix-millis-request-time field in taskstate

Signed-off-by: fierro <[email protected]>

* Generate taskstate model according to the rmf_api_msgs changes

Signed-off-by: fierro <[email protected]>

* Generate api client to get the new field

Signed-off-by: fierro <[email protected]>

* Save unix request time as now() and use previous value if the method is update

Signed-off-by: fierro <[email protected]>

* Show unix_millis_request_time in dashboard

Signed-off-by: fierro <[email protected]>

* Add Unix_millis_request_time into booking instead of taskstate directly

Signed-off-by: fierro <[email protected]>

* Access to unix_millis_request_time field through booking

Signed-off-by: fierro <[email protected]>

* Get previous task_state and if is not none use its request_time value

Signed-off-by: fierro <[email protected]>

---------

Signed-off-by: fierro <[email protected]>
(cherry picked from commit 7ea986d)
Signed-off-by: Aaron Chong <[email protected]>

* Fix/request date export (#690)

* Added date column to minimal export, only update fields of task state when it has not been created before

Signed-off-by: Aaron Chong <[email protected]>

* Use create and get_or_none, and save model if it exists

Signed-off-by: Aaron Chong <[email protected]>

---------

Signed-off-by: Aaron Chong <[email protected]>
(cherry picked from commit a1ea778)
Signed-off-by: Aaron Chong <[email protected]>

* Feature/task initiator (#692)

* Add initiator column in taskstate model

Signed-off-by: fierro <[email protected]>

* Initiator field has been added on client side

Signed-off-by: fierro <[email protected]>

* Set initiator field with the previous value if its is updated or use self.user.username if its is created

Signed-off-by: fierro <[email protected]>

* Add initiator as column in datagrid and show it in TaskSection

Signed-off-by: fierro <[email protected]>

* Populate initiator field with self.user.name when task is created

Signed-off-by: fierro <[email protected]>

* Add initiator column to minimal export

Signed-off-by: fierro <[email protected]>

* Set initiator column to minimal export

Signed-off-by: fierro <[email protected]>

* In update method, fill the initiator field with the previous db_task_state value

Signed-off-by: fierro <[email protected]>

---------

Signed-off-by: fierro <[email protected]>
(cherry picked from commit 86700da)
Signed-off-by: Aaron Chong <[email protected]>

* Adding user and request time to requests before submitting

Signed-off-by: Aaron Chong <[email protected]>

* api-server, use requester instead of initiator for task_request and task_state

Signed-off-by: Aaron Chong <[email protected]>

* Initiator to Requester

Signed-off-by: Aaron Chong <[email protected]>

* Update api-client

Signed-off-by: Aaron Chong <[email protected]>

* Using N/A instead of unknown for fields

Signed-off-by: Aaron Chong <[email protected]>

* pylint

Signed-off-by: Aaron Chong <[email protected]>

* Changing N/A to unknown

Signed-off-by: Aaron Chong <[email protected]>

* Adding try catch for username promise

Signed-off-by: Aaron Chong <[email protected]>

---------

Signed-off-by: fierro <[email protected]>
Signed-off-by: Aaron Chong <[email protected]>
Co-authored-by: César Rolón <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants