taipy icon indicating copy to clipboard operation
taipy copied to clipboard

Sort mechanism for get_all_scenarios and get_masters functions

Open jrobinAV opened this issue 3 years ago • 2 comments

Description

When calling a tp.get_scenarios or tp.get_masters, the user should be able to provide an optional field for sorting the scenarios. The sort should be increasing or decreasing. The sort could be on the name (default), id, creation_date, or tag.

jrobinAV avatar Apr 10 '22 13:04 jrobinAV

I would like to contribute to this issue. Could you please assign it to me?

Luke-0162 avatar Mar 05 '24 14:03 Luke-0162

Hello @Luke-0162, thank you for joining our project. I assigned the issue to you.

Please let me know if you need more information about the issue.

trgiangdo avatar Mar 05 '24 14:03 trgiangdo

Hello @trgiangdo, thank you for your response. I am looking forward to solve this issue.

Could you please help clarify which functions or methods I will need to edit exactly in order to resolve this issue? I have been examining the fetch_config method within the scenario.py file, but I want to make sure I am on the right track.

Luke-0162 avatar Mar 13 '24 18:03 Luke-0162

In https://github.com/Avaiga/taipy/blob/develop/taipy/core/taipy.py, you can find the get_scenarios() and get_primary_scenarios() functions. These 2 functions return a list of scenarios.

You should add 2 new parameters to this 2 functions, first is sorted: bool which indicates if the returned lists of scenarios is sorted or not, and second is the sort_key: str which indicates which key or attribute is used to sort the scenario.

The default value of the sort_key can be discuss latter.

For example, it should be something like:

def get_scenarios(
    cycle: Optional[Cycle] = None,
    tag: Optional[str] = None,
    sorted: bool = False,
    sort_key: str = "creation_date",
) -> List[Scenario]:
    ...
    # Get the list of scenarios (already implemented)
    ...
    # Sort the scenario list and return the list

Similarly for the get_primary_scenarios() method

trgiangdo avatar Mar 14 '24 01:03 trgiangdo

Hello @trgiangdo,

Once again, thanks a lot for helping me out. I have completed the implementation of the functions as discussed. Additionally, I have made a local test project which uses Taipy. This setup aims to allow me to test the new implementation of the get_scenarios() and get_primary_scenarios() functions. However, when I now install my edited version of Taipy by using the command "pip install -e ." inside the directory in which I put the Taipy GitHub project and try to use my version of Taipy in the test project, the modules "Config, Scope, Gui" (which are the only ones I am using) are not recognised. Meanwhile, I noticed that the Taipy import itself is recognised. So, I was wondering if you know how this problem is fixed and more specifically what is common practice for testing quickly whether a function works.

Additionally, I'm curious about any further steps required to address this issue. Should I be considering creating unit tests?

Thank you for your time and assistance. Looking forward to your insights!

Luke-0162 avatar Mar 21 '24 18:03 Luke-0162

  1. You should not install your version of Taipy using pip install -e. You can either create a separate environment for running the test and install Taipy from your edited folder, or you can run the test from the taipy folder itself.
  2. Yes, there should be unittests that cover what you've done. Then you can push a PR for us to review.

trgiangdo avatar Mar 22 '24 02:03 trgiangdo

Hello @trgiangdo ,

I have finished implementing the sorting mechanism into the tp.get_scenarios() or tp.get_primary_scenarios() functions. Additionally, I have added unit tests that cover my implementations. However, when I try to commit my code in my fork repository and the mypy check is triggered, all checks pass except from some checks concerning overloaded function signature. I cannot commit my code despite not being the initiator of these errors, as I have only edited existing functions and have not added any additional functions (apart from the unit tests). Can you inform me on how to continue?

Once again, thanks a lot for your help!

Luke-0162 avatar Mar 24 '24 23:03 Luke-0162

You can try to ignore the mypy error by adding the option -n to the commit command. Something like

git commit -m "message" -n

trgiangdo avatar Mar 25 '24 06:03 trgiangdo

I successfully committed, however, now I am trying to submit a pull-request. As this is the first time for me to do this for an open-source project, I am not sure whether I have done it correctly. Can you help me out? @trgiangdo

Luke-0162 avatar Mar 25 '24 10:03 Luke-0162

We can see your PR now. Let's start working from there

trgiangdo avatar Mar 25 '24 10:03 trgiangdo