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

OpenBB Script Routines major improvement #5005

Merged
merged 43 commits into from
May 30, 2023
Merged

Conversation

DidierRLopes
Copy link
Collaborator

@DidierRLopes DidierRLopes commented May 11, 2023

See current state here: https://twitter.com/didier_lopes/status/1656788265293459457?s=20

New features:

  • Allows to create variables
  • Allows to do for loops
  • Allows to slice ARGV or other vars
  • Documentation added
  • Decisions regarding some framework decisions I took- $ for args, $$ for var iterating in loops, 0-index, slicing like python
  • Several tests added here on tests/openbb_terminal/routines/test_routines.py - to be run with pytest tests/openbb_terminal/routines/test_routines.py

It doesn't has the capability of taking output from a command, thus the if/else is not a priority as the user controls the inputs. Taking output from command will likely require a big rewrite since that's not something our current infra supports.

@DidierRLopes DidierRLopes added the feat L Large T-Shirt size Feature label May 11, 2023
@reviewpad reviewpad bot added feat S Small T-Shirt size Feature and removed feat L Large T-Shirt size Feature labels May 11, 2023
@DidierRLopes
Copy link
Collaborator Author

CC: @the-praxs

@ronstone2000
Copy link

I like this. Your example hints at an extension that would make it even more flexible. Simple date manipulation:

END=today # A keyword that grabs the system date
START=$END-30 # (Some syntax that offsets a date)
DATES=$START,$END
...

@DidierRLopes
Copy link
Collaborator Author

I like this. Your example hints at an extension that would make it even more flexible. Simple date manipulation:

END=today # A keyword that grabs the system date START=$END-30 # (Some syntax that offsets a date) DATES=$START,$END ...

That's a great idea.

we can have some reserved keywords like LASTYEAR, LASTMONTH, LASTWEEK for dates. I'm wondering if there's any other type of keywords that we could use.

The offset is interesting but is hard to know what are we offsetting. Days? Months? Years?

@ronstone2000
Copy link

I was thinking days. I would not know exactly what LASTMONTH etc mean. Beginning of last month, end, April 11? Prebaked keywords would be helpful, but I may find them limiting if I want to work with arbitrary offsets from arbitrary dates. Say I'm an academic doing historical research and the baseline from which I want to look at stats is 10-10-2008, going back 3yrs ...

END=10-10-2008
BEGIN=$END-1095 # 10-10-2005

@the-praxs
Copy link
Contributor

the-praxs commented May 11, 2023

Rather than ARGV we can assign input argument values to a keyword called INPUT. This will prevent the user from overriding ARGV. Extending this, it means whatever arguments other than input is used can be used as a keyword for the script.

I am thinking about 0 vs 1-based indexing. If our user base is less technical, they will find it easier to use 1-based indexing. Programmers are comfortable with 0 already.

One cool feature I thought about is to provide the location of the output window for charts/tables i.e. top, center, bottom, or simply a row-column index like (1,2) (depending on the type of indexing) or to simplify more, 1,2,3 where everything goes top to bottom, left to right.

@the-praxs
Copy link
Contributor

For

I like this. Your example hints at an extension that would make it even more flexible. Simple date manipulation:
END=today # A keyword that grabs the system date START=$END-30 # (Some syntax that offsets a date) DATES=$START,$END ...

That's a great idea.

we can have some reserved keywords like LASTYEAR, LASTMONTH, LASTWEEK for dates. I'm wondering if there's any other type of keywords that we could use.

The offset is interesting but is hard to know what are we offsetting. Days? Months? Years?

CURRENT_DATE, QUARTER_1/Q1, QUARTER_2/Q2, Q2.DATE, Q2.MONTH etc?

@deeleeramone
Copy link
Contributor

deeleeramone commented May 11, 2023

I like this. Your example hints at an extension that would make it even more flexible. Simple date manipulation:
END=today # A keyword that grabs the system date START=$END-30 # (Some syntax that offsets a date) DATES=$START,$END ...

That's a great idea.

we can have some reserved keywords like LASTYEAR, LASTMONTH, LASTWEEK for dates. I'm wondering if there's any other type of keywords that we could use.

The offset is interesting but is hard to know what are we offsetting. Days? Months? Years?

As a usage example, I would like to have a routine that can query the economic and earnings calendars for the current or upcoming week without the need to explicitly state values for [start_date,end_date]. Keywords might be something like NEXTMONDAY, NEXTFRIDAY, LASTFRIDAY, THISMONDAY.

@DidierRLopes
Copy link
Collaborator Author

I was thinking days. I would not know exactly what LASTMONTH etc mean. Beginning of last month, end, April 11? Prebaked keywords would be helpful, but I may find them limiting if I want to work with arbitrary offsets from arbitrary dates. Say I'm an academic doing historical research and the baseline from which I want to look at stats is 10-10-2008, going back 3yrs ...

END=10-10-2008 BEGIN=$END-1095 # 10-10-2005

I think I'd rather for us to create our own convention, e,g. having valid 1YEARAGO, 2YEARSAGO, 3YEARSAGO, ... being valid

@DidierRLopes
Copy link
Collaborator Author

Rather than ARGV we can assign input argument values to a keyword called INPUT. This will prevent the user from overriding ARGV. Extending this, it means whatever arguments other than input is used can be used as a keyword for the script.

I am thinking about 0 vs 1-based indexing. If our user base is less technical, they will find it easier to use 1-based indexing. Programmers are comfortable with 0 already.

One cool feature I thought about is to provide the location of the output window for charts/tables i.e. top, center, bottom, or simply a row-column index like (1,2) (depending on the type of indexing) or to simplify more, 1,2,3 where everything goes top to bottom, left to right.

I like ARGV because it's Perl convention, but I understand that INPUT is more straightforward probably for 90% of users.

The programmer in my wants do die with 1-based indexing, but for less technical users it may be the right thing to do.

The screen position could potentially work. @tehcoderer would it be possible to have optional args for all commands that select where output lands on? Not sure if ROI for that one is worth, but would be good to know if at least possible!

QUARTER1, QUARTER2 convention sounds good.

Will work on a few improvements over weekend

@DidierRLopes
Copy link
Collaborator Author

I like this. Your example hints at an extension that would make it even more flexible. Simple date manipulation:
END=today # A keyword that grabs the system date START=$END-30 # (Some syntax that offsets a date) DATES=$START,$END ...

That's a great idea.
we can have some reserved keywords like LASTYEAR, LASTMONTH, LASTWEEK for dates. I'm wondering if there's any other type of keywords that we could use.
The offset is interesting but is hard to know what are we offsetting. Days? Months? Years?

As a usage example, I would like to have a routine that can query the economic and earnings calendars for the current or upcoming week without the need to explicitly state values for [start_date,end_date]. Keywords might be something like NEXTMONDAY, NEXTFRIDAY, LASTFRIDAY, THISMONDAY.

Good idea. I'll create a dictionary for us for these 🙏🏽

@deeleeramone
Copy link
Contributor

deeleeramone commented May 12, 2023

Good idea. I'll create a dictionary for us for these 🙏🏽

Maybe a smarter way to accomplish all of these, but if it gets the ball rolling, no harm in sharing. :)

def date_today() -> datetime:
    return (datetime.today())

def date_today_shift(ndays:int = 0) -> datetime:
    return (datetime.today() + timedelta(days=ndays))

def last_monday() -> datetime:
    if datetime.today().weekday() != 0:
        return (datetime.today() + timedelta(datetime.weekday(datetime.today())*(-1)))
    else:
        return (datetime.today() + timedelta(days = -7))

def next_monday() -> datetime:
    if datetime.today().weekday() == 0:
        return (datetime.today() + timedelta(days = 7))
    else:
        return (last_monday()+timedelta(days = 7))

@the-praxs
Copy link
Contributor

Rather than ARGV we can assign input argument values to a keyword called INPUT. This will prevent the user from overriding ARGV. Extending this, it means whatever arguments other than input is used can be used as a keyword for the script.
I am thinking about 0 vs 1-based indexing. If our user base is less technical, they will find it easier to use 1-based indexing. Programmers are comfortable with 0 already.
One cool feature I thought about is to provide the location of the output window for charts/tables i.e. top, center, bottom, or simply a row-column index like (1,2) (depending on the type of indexing) or to simplify more, 1,2,3 where everything goes top to bottom, left to right.

I like ARGV because it's Perl convention, but I understand that INPUT is more straightforward probably for 90% of users.

The programmer in my wants do die with 1-based indexing, but for less technical users it may be the right thing to do.

The screen position could potentially work. @tehcoderer would it be possible to have optional args for all commands that select where output lands on? Not sure if ROI for that one is worth, but would be good to know if at least possible!

QUARTER1, QUARTER2 convention sounds good.

Will work on a few improvements over weekend

Perfect! I will review the code in the mean time and think about some features/keywords.

@ronstone2000
Copy link

I think I'd rather for us to create our own convention, e,g. having valid 1YEARAGO, 2YEARSAGO, 3YEARSAGO, ... being valid

Works for me. I'd like to see 1WEEKAGO, 2WEEKSAGO, 1MONTHAGO etc intervals (I,e, near past offsets)

@DidierRLopes
Copy link
Collaborator Author

This should do.

Screen.Recording.2023-05-14.at.1.46.35.AM.mov

CC: @ronstone2000 @deeleeramone @the-praxs

@reviewpad reviewpad bot removed the feat S Small T-Shirt size Feature label May 14, 2023
@DidierRLopes DidierRLopes marked this pull request as ready for review May 29, 2023 10:18
Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

Copy link
Collaborator

@jmaslek jmaslek left a comment

Choose a reason for hiding this comment

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

rocket ship emojiiiii

reviewpad[bot]
reviewpad bot previously requested changes May 30, 2023
Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

reviewpad[bot]
reviewpad bot previously requested changes May 30, 2023
Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

@jmaslek jmaslek added this pull request to the merge queue May 30, 2023
Copy link

@reviewpad reviewpad bot left a comment

Choose a reason for hiding this comment

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

The poetry.lock file has been changed. Please update both requirements.txt and requirements-full.txt files

Merged via the queue into develop with commit 72a46fb May 30, 2023
@jmaslek jmaslek deleted the feature/openbb_script_loop branch May 30, 2023 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat L Large T-Shirt size Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants