taipy
taipy copied to clipboard
Added Filter Scenarios by time on CycleManager Class
This PR continues https://github.com/Avaiga/taipy/pull/646
Hello @trgiangdo , I have been guided by this comment it helped me a lot, thank you. What worries me is :
-
If I use the
_CycleManager._get_all()
, I will get a list of cycles but I have n't found a means to extract scenarios form a cycle. Even this get_cycles_scenarios method is fromget_scenarios
calls thescenarioManager
Class. I think it would be hard to avoid the local import of the scenario Manager. ( I may be wrong ) -
I am not really sure of my logic. If there is a way to get the scenarios of a cycle, please help me with hints .
You can get the scenarios by cycle using _ScenarioManager._get_all_by_cycle()
method. But this should not be called inside the _CycleManager, it should be called at the API
Example Usage
from taipy.config import Config, Frequency, Scope
import taipy as tp
import datetime as dt
from datetime import date
import pandas as pd
def filter_by_month(df, month):
df['Date'] = pd.to_datetime(df['Date'])
df = df[df['Date'].dt.month == month]
return df
historical_data_cfg = Config.configure_csv_data_node(id="historical_data",
default_path="time_series.csv",
scope=Scope.GLOBAL)
month_cfg = Config.configure_data_node(id="month",
scope=Scope.CYCLE)
month_values_cfg = Config.configure_data_node(id="month_data",
scope=Scope.CYCLE)
task_filter_cfg = Config.configure_task(id="filter_by_month",
function=filter_by_month,
input=[historical_data_cfg, month_cfg],
output=month_values_cfg)
scenario_cfg = Config.configure_scenario(id="my_scenario",
task_configs=[task_filter_cfg],
frequency=Frequency.MONTHLY)
if __name__ == '__main__':
tp.Core().run()
scenario_1 = tp.create_scenario(scenario_cfg,
creation_date=dt.datetime(2022,10,7),
name="Scenario 2022/10/7")
scenario_2 = tp.create_scenario(scenario_cfg,
creation_date=dt.datetime(2022,10,5),
name="Scenario 2022/10/5")
scenario_1.month.write(10)
scenario_1.submit()
cycle = scenario_1.cycle
b = dt.datetime(2022,10,12,0,0)
print('<<<<<<<<<Scenarios>>>>>>>>>',tp.get_scenarios_by_time(b))
Hello @Forchapeatl, the get_scenarios_by_time()
method here is not what discussed in issue https://github.com/Avaiga/taipy/issues/413.
I believe you are on the right track and to ensure alignment with our objectives, I recommend revisiting the specifics of the issue and refining the get_scenarios()
method accordingly
@trgiangdo , you are right . This PR no-longer addresses issue #413. I am just holding on to this comment .
Yes, I believe that comment is obsolete since we were in the discussion phase. Can you help us implement the API as discussed in the issue? I believe we can use a lot of the code you already implemented
Closed due to inactivity