-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: Cenários de BDD usando o modulo behave
- Loading branch information
1 parent
c3b9972
commit 11fcc9c
Showing
13 changed files
with
184 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
Feature: Convert a multivariate Timeseries to list of univariate Timeseries and vice versa | ||
|
||
Value Statement: | ||
As a data analyst | ||
I want the ability to convert between Timeseries types ['univariate', 'multivariate'] for use in different situations | ||
So I can start analyzing the data right away and come up with solutions for the business. | ||
|
||
Background: | ||
Given that I have a T8S_WORKSPACE_DIR and a long format time series persisted to a Parquet file | ||
|
||
Scenario: Conversion of Timeseries types ['univariate', 'multivariate'] for use in different situations | ||
Given that I create a Timeseries using the selected parquet file in the T8S_WORKSPACE/data/parquet directory | ||
When I convert Timeseries from long format to wide format | ||
Then I convert the Timeseries from multivariate to a list of univariate Timeseries | ||
And I convert the list of univariate Timeseries into a single multivariate Timeseries | ||
And I check the result. | ||
# Constraint: The Timeseries has no invalid values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import os | ||
from pathlib import Path | ||
from datetime import datetime | ||
import numpy as np | ||
import pandas as pd | ||
from t8s import get_sample_df | ||
from t8s.log_config import LogConfig | ||
from t8s.util import Util | ||
from t8s.io import IO | ||
from t8s.ts import TimeSerie | ||
from t8s.ts_writer import TSWriter, WriteParquetFile | ||
from t8s.ts_builder import TSBuilder | ||
from t8s.ts_builder import ReadParquetFile | ||
from behave import given, when, then, use_step_matcher, step | ||
from behave.model import Table | ||
from behave_pandas import table_to_dataframe, dataframe_to_table | ||
from logging import INFO, DEBUG, WARNING, ERROR, CRITICAL | ||
|
||
LogConfig().initialize_logger(DEBUG) | ||
logger = LogConfig().getLogger() | ||
|
||
""" | ||
Feature: Convert a multivariate Timeseries to list of univariate Timeseries and vice versa | ||
Value Statement: | ||
As a data analyst | ||
I want the ability to convert between Timeseries types ['univariate', 'multivariate'] for use in different situations | ||
So I can start analyzing the data right away and come up with solutions for the business. | ||
Background: | ||
Given that I have a T8S_WORKSPACE_DIR and a long format time series persisted to a Parquet file | ||
""" | ||
|
||
@given(u'that I have a T8S_WORKSPACE_DIR and a long format time series persisted to a Parquet file') | ||
def background(context): | ||
logger.info(u'STEP: Given that I have a T8S_WORKSPACE_DIR and a long format time series persisted to a Parquet file') | ||
|
||
if context.status == 'data directory empty': | ||
context.create_sample_ts_and_save_as_parquet(context) | ||
context.status = 'data directory with parquet file' | ||
|
||
# O método before_feature() em features/environment.py atualiza o contexto | ||
logger.info(f'-------------------------------------------------') | ||
logger.info(f'Background @given: T8S_WORKSPACE_DIR = {context.T8S_WORKSPACE_DIR}') | ||
logger.info(f'Background@given: CSV_PATH = {context.CSV_PATH}') | ||
logger.info(f'Background@given: PARQUET_PATH = {context.PARQUET_PATH}') | ||
context.list_files(f'Background@given: ', context) | ||
# logger.info(f'\background : context.ts1 -> \n{str(context.ts1)}') | ||
logger.info(f'-------------------------------------------------') | ||
# A forma de passar estes dados para os steps seguintes é usando o objeto context | ||
|
||
""" | ||
Scenario: Conversion of Timeseries types ['univariate', 'multivariate'] for use in different situations | ||
Given that I create a Timeseries using the selected parquet file in the T8S_WORKSPACE/data/parquet directory | ||
When I convert Timeseries from long format to wide format | ||
Then I convert the Timeseries from multivariate to a list of univariate Timeseries | ||
And I convert the list of univariate Timeseries into a single multivariate Timeseries | ||
And I check the result. | ||
# Constraint: The Timeseries has no invalid values | ||
""" | ||
|
||
@given(u'that I create a Timeseries using the selected parquet file in the T8S_WORKSPACE/data/parquet directory') | ||
def create_time_serie(context): | ||
filename = 'ts_long_01.parquet' | ||
path_str: str = str(context.PARQUET_PATH) + '/' + filename | ||
path = Path(path_str) | ||
logger.debug('path: ' + str(path)) | ||
ctx = TSBuilder(ReadParquetFile()) | ||
logger.debug("Client: Strategy is set to read Parquet file.") | ||
ts1: TimeSerie = ctx.build_from_file(Path(path_str)) | ||
assert int(ts1.features) == 3 | ||
assert ts1.format == 'long' | ||
assert ts1.df.__len__() == 8 | ||
context.ts1 = ts1 | ||
|
||
@when(u'I convert Timeseries from long format to wide format') | ||
def convert_time_serie_from_long_to_wide_format(context): | ||
logger.info(f'context.ts1 BEFORE -> \n{str(context.ts1)}') | ||
|
||
@then(u'I convert the Timeseries from multivariate to a list of univariate Timeseries') | ||
def convert_time_serie_from_multivariate_to_list_of_univariate(context): | ||
logger.info(f'context.ts1 BEFORE -> \n{str(context.ts1)}') | ||
|
||
@then(u'I convert the list of univariate Timeseries into a single multivariate Timeseries') | ||
def convert_list_of_univariate_to_multivariate(context): | ||
logger.info(f'context.ts1 BEFORE -> \n{str(context.ts1)}') | ||
|
||
@then(u'I check the result.') | ||
def check_result(context): | ||
logger.info(f'context.ts1 BEFORE -> \n{str(context.ts1)}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters