change master.quarter format #12

Closed
opened 2020-10-16 13:46:54 +00:00 by banillie · 2 comments
banillie commented 2020-10-16 13:46:54 +00:00 (Migrated from github.com)

@yulqen Is it possible to change the master.quarter structure so that str(master.quarter) returns [quarter]_[year_one]_[year_two] i.e. Q2_20_21, rather than Q2 20/21? It would be helpful for automatically including the quarter stamp in the saving of output files e.g. data_analysis_Q2_20_21 .
Just an idea. Sure it wont be difficult to develop a function to do this in analysis_engine also.

@yulqen Is it possible to change the `master.quarter` structure so that `str(master.quarter)` returns `[quarter]_[year_one]_[year_two]` i.e. `Q2_20_21`, rather than `Q2 20/21`? It would be helpful for automatically including the quarter stamp in the saving of output files e.g. `data_analysis_Q2_20_21` . Just an idea. Sure it wont be difficult to develop a function to do this in analysis_engine also.
yulqen commented 2020-10-16 16:03:13 +00:00 (Migrated from github.com)

@banillie - in case you haven't seen

Here you go. Using pythons regular expressions library - regular expressions.

Makes more sense for you to convert the text to whatever you want rather than changing the API.

import re

def make_file_friendly(quarter_str: str) -> str:

    # regular expressions start with an "r" in python. This is the crucial bit - a pattern that states what string you want to match.
    regex = r"Q(\d) (\d+)\/(\d+)"  

   # this returns the string we want, keeping the bits in brackets from `regex` and writing them out separated by underscores instead of the forward slash.
    return re.sub(regex, r"Q\1_\2_\3", quarter_str)

# just testing it works
test_str = "Q2 10/23"
print(make_file_friendly(test_str))
@banillie - in case you haven't seen Here you go. Using pythons regular expressions library - [regular expressions](https://en.wikipedia.org/wiki/Regular_expression). Makes more sense for you to convert the text to whatever you want rather than changing the API. ```python import re def make_file_friendly(quarter_str: str) -> str: # regular expressions start with an "r" in python. This is the crucial bit - a pattern that states what string you want to match. regex = r"Q(\d) (\d+)\/(\d+)" # this returns the string we want, keeping the bits in brackets from `regex` and writing them out separated by underscores instead of the forward slash. return re.sub(regex, r"Q\1_\2_\3", quarter_str) # just testing it works test_str = "Q2 10/23" print(make_file_friendly(test_str)) ```
banillie commented 2020-10-19 14:46:33 +00:00 (Migrated from github.com)

Excellent. Thanks for providing this.

Excellent. Thanks for providing this.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
yulqen/datamaps#12
No description provided.