Avaiga / taipy

Turns Data and AI algorithms into production-ready web applications in no time.
https://www.taipy.io
Apache License 2.0
10.94k stars 775 forks source link

Cycle based filtering for scenario getters #413

Open jrobinAV opened 11 months ago

jrobinAV commented 11 months ago

Propose a way to filter scenarios by providing a cycle description.

Objectives

We want to implement a filter mechanism, a query system, or Python API to describe and retrieve a meaningful subset of scenarios easily. This filtering should be based on the cycle. (thanks to @Forchapeatl Pull Request 😉, I realize that even if we want to expose an API to retrieve a subset of scenarios, the implementation is related to cycle description).

use cases:

In the following, I do not propose implementing a get_scenarios function exactly as written. It is the easiest way I found to describe what should be provided by the user and what should be returned by the filtering mechanism. These are some use cases I have in mind. We should have similar descriptions for weekly, monthly, quarterly, and yearly scenarios once we have listed all the relevant use cases. We can discuss an API for that.

Daily scenarios

Here are a few use cases I have in mind for daily scenarios.

Weekly scenarios

TODO

Forchapeatl commented 8 months ago

I am great at graph algorithims, I am very much interested in this issue. May I handle this issue ?

trgiangdo commented 8 months ago

Thank you @Forchapeatl. If you have any question regarding the implementation, feel free to ask us.

jrobinAV commented 8 months ago

Thank you very much @Forchapeatl. You rock!

Forchapeatl commented 8 months ago

Thank you very much @Forchapeatl. You rock!

Thank you :)

Forchapeatl commented 8 months ago

Case study : Get all wednesday Scenarioes

Screenshot from 2023-12-28 13-38-06

From the above illustration , if we intend to get all wednesday senarios , it sould be possible by getting all senarios who's start and end date contains wednesday ( by date ) . That is we get all scenarios whoes cycle comply to this function startDate <= query day <= end Date

i would like to get more information on this function . Please tell me more about this _build_filters_with_version("all") code.

https://github.com/Avaiga/taipy/blob/170a14b149544fdde085ba17ed19719cdf790370/taipy/core/scenario/_scenario_manager.py#L255-L262

trgiangdo commented 8 months ago

About the _build_filters_with_version(), because most Taipy entities have a version, this method create a filter dictionary to make sure getting the correct entities of the correct version. However, Cycle entities do not have a version (it can be shared across application versions), the filter will be empty to get all Cycle entities.

jrobinAV commented 7 months ago

This issue is not ready to be implemented for me. It requires a better description of the motivation, the expected output, a description of the expected API and a list of use cases.

jrobinAV commented 7 months ago

@Forchapeatl @toan-quach @trgiangdo @FlorianJacta I just updated the description of the issue to try to make it clearer.

Please provide any feedback, comments, or ideas so we can challenge, or append the use cases. Once we settle on representative use cases we can propose an API.

What do you think?

Forchapeatl commented 7 months ago

Thank you for elaborating on the usecases @jrobinAV . It 's very good. The way I see it , we could split the usecases into 2 functions.

  1. Get daily scenarios by date: This method can take datetime as parameter and bool if we want it by year or month.

get_scenarios(days_of_month=[1, 15, 21]) get_scenarios(days_of_year=["1/1", "12/5", "22/8"])

  1. Get daily scenarios by day : For these method the user passes an option and the function will have to compute the datetime.

get_scenarios(days_of_week="week_days") get_scenarios(days_of_week="week_end") get_scenarios(days_of_week=["Mondays", "Thursdays"]) get_scenarios(days_of_month="last") get_scenarios_by(days_of_year=["January", "March"])

@jrobinAV , please 🙏 at your convenience help draw up a few usecases for WEEKLY scenarions for me please. I am still struggling with building an organised logic together.

trgiangdo commented 1 month ago

We can provide multiple options for the user to filter with each type of frequency. The user can only use 1 param.

Daily scenarios

Weekly scenarios

Monthly scenarios

Quarterly scenarios

Yearly scenarios

FlorianJacta commented 1 month ago

I don't really see the relationship between cycles and this API. Does this mean that scenarios without a cycle couldn't be filtered this way?

trgiangdo commented 1 month ago

Yes, scenarios without cycle can be filtered using other properties (like creation_time)

FlorianJacta commented 1 month ago

To be honest, it is hard for me to see the motivation behind all of it. Would it be faster than if I did it myself?

What I needed in the past for cycles is a way to create a tree (as a dict) of cycles and scenarios:

This was needed to create a scenario selector.

And I also needed to get all scenarios from a cycle object.

trgiangdo commented 1 month ago

For "a way to create a tree (as a dict) of cycles and scenarios", the API already exists

import taipy as tp
tp.get_cycles_scenarios()

For "I also needed to get all scenarios from a cycle object", the API also already exists

import taipy as tp
tp.get_scenarios(cycle=CycleObject)

So there's actually no other motivation behind this issue?

FlorianJacta commented 1 month ago

I know that they already exist. Not back in my days 😄

Well, you tell me. Or @jrobinAV tells us.

jrobinAV commented 2 weeks ago

To be honest, it is hard for me to see the motivation behind all of it. Would it be faster than if I did it myself?

Without such an API, the implementation should be easy and straightforward, I agree. However, the easy solution will be to read all the scenarios and filter some of them out. In terms of performance, we could benefit from having a cycle description that can be used in the scenario query so we can only read the needed scenarios.

And I also needed to get all scenarios from a cycle object.

True.