graphxplore.DataMapping.Conclusions package

Conclusions objects take a source line of data (as dictionary) and return a specific value based on the input. E.g. the CopyConclusion just copies/returns a specific input value. All classes of this subpackage have the same interface, inherit from the Conclusion class and can be parsed from/to strings. Code might look like

>>> from graphxplore.MetaDataHandling import DataType
>>> from graphxplore.DataMapping import SourceDataLine
>>> from graphxplore.DataMapping.Conclusions import CopyConclusion
>>> conclusion = CopyConclusion(target_data_type=DataType.Integer, origin_table='table', var_to_copy='var')
>>> print(str(conclusion))
'COPY VARIABLE var IN TABLE table IF TYPE IS Integer'
>>> source_line = SourceDataLine({'table' : {'var' : 42}})
>>> conclusion.get_return(source_line)
42
>>> source_line = SourceDataLine({'table' : {'var' : 'some_value'}})
>>> conclusion.get_return(source_line)
# 'some_value' is not an integer and thus will not get copied
None

Module contents

class graphxplore.DataMapping.Conclusions.AggregateConclusion(source_data_type: DataType, origin_table: str, var_to_aggregate: str, aggregator: AggregatorType)[source]

Bases: Conclusion

This conclusion returns the aggregation of all data of a specific table, variable and data type for a primary key value. It can e.g. be used to extract minimal, maximal or average values from time series or check if a patient was diagnosed with a certain condition at least once.

Parameters:
  • source_data_type (DataType) – Only values of this type will be aggregated

  • origin_table (str) – The table of origin for the variable

  • var_to_aggregate (str) – The name of the variable

  • aggregator (AggregatorType) – The type of data aggregation

static from_string(input_str: str) AggregateConclusion | None[source]

Generates a Conclusion object from an input string if it is valid

Parameters:

input_str (str) – The input string

Returns:

Returns the generated conclusion or None, if the string was invalid

Return type:

AggregateConclusion | None

get_required_data() Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]][source]

Returns the required source tables and variables for the conclusion to operate.

Returns:

Returns a dictionary of required source tables and variables of the table

Return type:

Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]]

get_return(source_data: SourceDataLine) str | int | float | None[source]

Triggers the conclusion on the source data and generates the return value for the target data based on source_data.

Parameters:

source_data (SourceDataLine) – The line of source data

Returns:

Returns the value of the target variable, or None

Return type:

str | int | float | None

class graphxplore.DataMapping.Conclusions.Conclusion(target_data_type: DataType)[source]

Bases: object

This is the abstract parent class of all conclusions of MappingCase objects.

Parameters:

target_data_type (DataType) – The data type of the target variable

static from_string(input_str: str) Conclusion | None[source]

Generates a Conclusion object from an input string if it is valid

Parameters:

input_str (str) – The input string

Returns:

Returns the generated conclusion or None, if the string was invalid

Return type:

Conclusion | None

get_required_data() Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]][source]

Returns the required source tables and variables for the conclusion to operate.

Returns:

Returns a dictionary of required source tables and variables of the table

Return type:

Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]]

get_return(source_data: SourceDataLine) str | int | float | None[source]

Triggers the conclusion on the source data and generates the return value for the target data based on source_data.

Parameters:

source_data (SourceDataLine) – The line of source data

Returns:

Returns the value of the target variable, or None

Return type:

str | int | float | None

class graphxplore.DataMapping.Conclusions.ConclusionParser[source]

Bases: object

static from_string(input_str: str) Conclusion[source]

Parse a conclusion from string

Parameters:

input_str (str) – The string to be parsed

Returns:

Returns the parsed conclusion or raises an exception

Return type:

Conclusion

class graphxplore.DataMapping.Conclusions.CopyConclusion(target_data_type: DataType, origin_table: str, var_to_copy: str)[source]

Bases: Conclusion

This conclusion copies the value of a source variable from a given line source data, if the value fits the data type of the target variable.

Parameters:
  • target_data_type (DataType) – The data type of the target variable

  • origin_table (str) – The source table of the variable to copy

  • var_to_copy (str) – the name of the source variable to copy

static from_string(input_str: str) CopyConclusion | None[source]

Generates a Conclusion object from an input string if it is valid

Parameters:

input_str (str) – The input string

Returns:

Returns the generated conclusion or None, if the string was invalid

Return type:

CopyConclusion | None

get_required_data() Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]][source]

Returns the required source tables and variables for the conclusion to operate.

Returns:

Returns a dictionary of required source tables and variables of the table

Return type:

Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]]

get_return(source_data: SourceDataLine) str | int | float | None[source]

Triggers the conclusion on the source data and generates the return value for the target data based on source_data.

Parameters:

source_data (SourceDataLine) – The line of source data

Returns:

Returns the value of the target variable, or None

Return type:

str | int | float | None

class graphxplore.DataMapping.Conclusions.FixedReturnConclusion(target_data_type: DataType, return_val: str | int | float | None)[source]

Bases: Conclusion

This conclusion returns a fixed value casted to the data type of the target variable

Parameters:
  • target_data_type (DataType) – The data type of the target variable

  • return_val (str | int | float | None) – The fixed return value

static from_string(input_str: str) FixedReturnConclusion | None[source]

Generates a Conclusion object from an input string if it is valid

Parameters:

input_str (str) – The input string

Returns:

Returns the generated conclusion or None, if the string was invalid

Return type:

FixedReturnConclusion | None

get_required_data() Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]][source]

Returns the required source tables and variables for the conclusion to operate.

Returns:

Returns a dictionary of required source tables and variables of the table

Return type:

Dict[str, List[Tuple[str, Tuple[AggregatorType, DataType] | None]]]

get_return(source_data: SourceDataLine) str | int | float | None[source]

Triggers the conclusion on the source data and generates the return value for the target data based on source_data.

Parameters:

source_data (SourceDataLine) – The line of source data

Returns:

Returns the value of the target variable, or None

Return type:

str | int | float | None