sbu.dataframe¶
A module which handles data parsing and DataFrame construction.
Index¶
|
Acquire the SBU usage for each account in the |
|
Gather SBU usage of a specific user account. |
|
Return a starting and ending date as two strings. |
|
Construct a filename containing the current date. |
|
Create a Pandas DatetimeIndex from a start and end date. |
|
Parse any dates supplied to |
Return the total number of requested SBUs. |
API¶
- sbu.dataframe.get_sbu(df, project, start=None, end=None)[source]¶
Acquire the SBU usage for each account in the
pandas.DataFrame.index
.The start and end of the reported interval can, optionally, be altered with start and end. Performs an inplace update of df, adding new columns to hold the SBU usage per month under the
"Month'
super-column. In addition, a single row and column is added ("sum"
) with SBU usage summed over the entire interval and over all users, respectively.- Parameters
df (
pandas.DataFrame
) – A Pandas DataFrame with usernames and information, constructed byyaml_to_pandas()
.pandas.DataFrame.columns
andpandas.DataFrame.index
should be instances ofpandas.MultiIndex
andpandas.Index
, respectively. User accounts are expected to be stored inpandas.DataFrame.index
. SBU usage (including the sum) is stored in the"Month"
super-column.start (
int
orstr
, optional) – Optional: The starting year of the interval. Defaults to the current year ifNone
.end (
str
orint
, optional) – Optional: The final year of the interval. Defaults to current year + 1 ifNone
.project (
str
, optional) – Optional: The project code of the project of interest. If notNone
, only SBUs expended under this project are considered.
- Return type
- sbu.dataframe.parse_accuse(project, start=None, end=None)[source]¶
Gather SBU usage of a specific user account.
The bash command
accuse
is used for gathering SBU usage along an interval defined by start and end. Results are collected and returned in a Pandas DataFrame.- Parameters
- Returns
The SBU usage of user over a specified period.
- Return type
- sbu.dataframe.get_date_range(start=None, end=None)[source]¶
Return a starting and ending date as two strings.
- Parameters
start (
int
orstr
, optional) – The starting year of the interval. Accepts dates formatted as YYYY, MM-YYYY or DD-MM-YYYY. Defaults to the current year ifNone
.end (
str
orint
, optional) – The final year of the interval. Accepts dates formatted as YYYY, MM-YYYY or DD-MM-YYYY. Defaults to the current year + 1 ifNone
.
- Returns
A tuple with the start and end data, formatted as strings. Dates are formatted as DD-MM-YYYY.
- Return type
- sbu.dataframe.construct_filename(prefix, suffix='.csv')[source]¶
Construct a filename containing the current date.
Examples
>>> filename = construct_filename('my_file', '.txt') >>> print(filename) 'my_file_31_May_2019.txt'
- Parameters
- Returns
A filename consisting of prefix, the current date and suffix.
- Return type
- sbu.dataframe._get_datetimeindex(start, end)[source]¶
Create a Pandas DatetimeIndex from a start and end date.
- Parameters
- Returns
A DatetimeIndex starting from sy and ending on ey.
- Return type
- sbu.dataframe._parse_date(input_date, default_day='01', default_month='01', default_year=None)[source]¶
Parse any dates supplied to
get_date_range()
.- Parameters
input_date (
str
,int
orNone
) –The to-be parsed date. Allowed types and values are:
default_month (
str
) – The default month if a month is not provided in input_date. Expects a month in MM format.default_year (
str
, optional) – Optional: The default year if a year is not provided in input_date. Expects a year in YYYY format. Defaults to the current year ifNone
.
- Returns
A string, constructed from input_date, representing a date in DD-MM-YYYY format.
- Return type
- Raises
ValueError – Raised if input_date is provided as string and contains more than 2 dashes.
TypeError – Raised if input_date is neither
None
, a string nor an integer.