pyDEA.core.data_processing package

Submodules

pyDEA.core.data_processing.input_data module

This module contains a class for storing input data.

class pyDEA.core.data_processing.input_data.InputData[source]

Bases: object

This class stores input data and provides some useful methods to add input data and to access it.

DMU_codes

set of str

set of internal codes of DMUs. All codes are assigned automatically when DMUs are added.

DMU_code_to_user_name

dict of str to str

dictionary that maps internal DMU codes to DMU names provided by the user.

_DMU_user_name_to_code

dict of str to str

dictionary that maps DMU names to internal DMU codes. It is useful for adding new DMUs and for unit tests.

DMU_codes_in_added_order

list of str

list of DMU codes in the order they were added.

categories

set of str

set of all categories (input and output).

coefficients

dict of tuple of str, str to double}

dictionary that maps internal DMU code and category to the corresponding coefficient, e.g. {(DMU, category) : value}.

output_categories

set of str

set of output categories.

input_categories

set of str

set of input categories.

_count

int

internal variable used to generate DMU codes.

add_coefficient(dmu_user_name, category_name, value)[source]

Adds coefficient value corresponding to DMU and category to the internal data structure. Updates other containers that store DMUs and categories. If given pair of DMU and category already exist, KeyError is raised.

Parameters:
  • dmu_user_name (str) – DMU name.
  • category_name (str) – category (input or output).
  • value (double) – coefficient value.
Raises:

KeyError – if a pair of dmu_user_name and category_name has already been added before

add_input_category(category_name)[source]

Adds given category to the set of input categories.

Parameters:category_name (str) – name of the input category.
Raises:KeyError – if category_name is not present among existing categories.
add_output_category(category_name)[source]

Adds given category to the set of output categories.

Parameters:category_name (str) – name of the output category.
Raises:KeyError – if category_name is not present among existing categories.
get_dmu_user_name(dmu_code)[source]

Returns DMU user name given DMU code.

Parameters:dmu_code (str) – DMU code.
Returns:DMU name.
Return type:str
Raises:KeyError – if dmu_code does not exist.
print_coefficients()[source]

Prints all coefficients on the screen.

pyDEA.core.data_processing.parameters module

This module contains methods and Parameters class responsible for parsing, storing and updating parameters from a file.

pyDEA.core.data_processing.parameters.VALID_PARAM_NAME

str

string for regular expressions that describes valid parameter names (must start with a word character, might contain word characters and spaces).

pyDEA.core.data_processing.parameters.VALID_PARAM_VALUE

str

string for regular expressions that describes valid parameter values (must start with any non-space character).

pyDEA.core.data_processing.parameters.VALID_PARAM_NAMES

list of str

list of allowed parameter names.

pyDEA.core.data_processing.parameters.CATEGORICAL_AND_DATA_FIELDS

list of str

list of parameter names that contain data or categorical information.

class pyDEA.core.data_processing.parameters.Parameters[source]

Bases: object

This class stores and manipulates all parameters needed to run DEA models. After object creation all parameter values are set to empty string.

params

dict of str to str

dictionary of parameter names and values.

Example

>> params = {‘DEAform’: ‘env’, ‘ReturnsToScale’: ‘VRS’}

change_category_name(old_name, new_name)[source]

Changes a given category name to a new name in all parameter values that contain this category.

Parameters:
  • old_name (str) – previous category name.
  • new_name (str) – new category name.
clear_all_categorical_and_data_fields()[source]

Sets values of parameters from CATEGORICAL_AND_DATA_FIELDS to empty strings.

copy_all_params(params_from)[source]

Copies all parameter values from a given parameter object.

Parameters:params_from (Parameters) – parameter object from which parameter values will be copied.
get_all_params_as_string()[source]

Returns all parameters with values as a string.

Returns:all paremeters with values.
Return type:str
get_parameter_value(param_name)[source]

Returns a value that corresponds to a given parameter name. If there is no such parameter name, throws KeyError exception.

Example

>>> allParams = Parameters()
>>> allParams.update_parameter('DEA_FORM', 'value1')
>>> allParams.get_parameter_value('DEA_FORM')
value1
>>> allParams.get_parameter_value('Param2')
KeyError
Parameters:param_name (str) – parameter name.
Returns:parameter value.
Return type:str
get_set_of_parameters(param_name, delimiter=';')[source]

Some of the parameters contain a set of values. Returns a set of strings with these values instead of one string.

Parameters:
  • param_name (str) – parameter name.
  • delimiter (str, optional) – delimiter. Defaults to semicolon.
Returns:

set of parsed parameter values.

Return type:

set of str

print_all_parameters()[source]

Prints all parameters on screen.

remove_category_from_params(category_type, category_name)[source]

Removes a given parameter value from parameters.

Parameters:
  • category_type (str) – parameter name.
  • category_name (str) – value that should be removed.
update_parameter(param_name, param_value)[source]

Updates existing parameter in the dictionary. If parameter does not exist in the dictionary, throws exception. Parameter name and value must satisfy conditions specified by regular expressions VALID_PARAM_NAME and VALID_PARAM_VALUE.

Example

>>> p = Parameters()
>>> p.get_parameter_value('DEA_FORM')
''
>>> p.update_parameter('DEA_FORM', 'new value')
>>> p.get_parameter_value('DEA_FORM')
'new value'
>>> p.update_parameter('param2', 'value2')
KeyError
>>> p.update_parameter('DEA_FORM', '   ')
ValueError
Parameters:
  • param_name (str) – parameter name.
  • param_value (str) – parameter value.
Raises:
  • KeyError – if a given parameter name does not belong to VALID_PARAM_NAMES.
  • ValueError – if a given parameter value does not satisfy regular expression given in VALID_PARAM_VALUE.
pyDEA.core.data_processing.parameters.extract_comment(line)[source]

Removes comments from a given line. Symbol # is treated as one line comment separator.

Example

>>> extract_comment("some line")
some line
>>> extract_comment("line with comment # here comes comment")
line with comment
>>> extract_comment("# only comment is present")
>>>
Parameters:line (str) – line with text.
Returns:line without comment.
Return type:str
pyDEA.core.data_processing.parameters.parse_parameters_from_file(filename)[source]

Reads parameters from a given file. If file does not exist, the exception will be thrown. Returns Parameters object with all parameters. Does not validate parameters. Throws an exception if there are repeating parameters (all parameters must be unique). All parameters must follow convention: <param_name> {param_value}. Supports one line comments: <param_name> {param_value} # this parameter is important. If some parameters are missing, their value will be set to empty string.

Parameters:

filename (str) – path to file with parameters. Only text files are accepted, but actual file extension does not matter.

Returns:

parameter object with parsed parameters.

Return type:

Parameters

Raises:
  • FileNotFound – if given file does not exist.
  • ValueError – if file does not contain any valid parameters.
pyDEA.core.data_processing.parameters.validate_string(string, expression)[source]

Checks if a given string matched a given regular expression.

Example

>>> validate_string('', VALID_PARAM_NAME)
False
>>> validate_string('abc', VALID_PARAM_NAME)
True
>>> validate_string('abc something', VALID_PARAM_NAME)
True
>>> validate_string(' space', VALID_PARAM_NAME)
False
>>> validate_string('     ', VALID_PARAM_NAME)
False
>>> validate_string(r'\home\path\file.txt  ', VALID_PARAM_VALUE)
True
>>> validate_string(r' \home\path\file.txt  ', VALID_PARAM_VALUE)
False
Parameters:
  • string (str) – string to check.
  • expression (str) – regular expression string.
Returns:

True if string meets conditions specified by a regular expression, False otherwise.

Return type:

bool

pyDEA.core.data_processing.parameters.write_parameters_to_file(params, filename)[source]

Writes all parameters stored in a given Parameters object to a given file in the following format format: <param_name> {param_value}. If the file already exists, all parameters will be over-written with the new ones.

Parameters:
  • params (Parameters) – parameters object.
  • filename (str) – file name where parameters must be written.

pyDEA.core.data_processing.read_data_from_xls module

This module contains functions and classes responsible for reading input data from xls, xlsx and csv files.

Note

In xlrd when text is read from xlsx, leading white spaces are automatically removed. But when text is read from xls, they are kept.

class pyDEA.core.data_processing.read_data_from_xls.CSVReader[source]

Bases: object

This class implements parsing of input data from csv files.

rows

list of list of str

list of rows with input data.

file_ref

file

file reference.

cell_is_not_blank(cell)[source]

Checks if a given cell has blank value.

Parameters:cell (str) – cell.
Returns:True if cell has blank value, False otherwise.
Return type:bool
cell_is_not_empty(cell)[source]

Checks if a given cell has non-empty value.

Parameters:cell (str) – cell.
Returns:True if cell has non-empty value, False otherwise.
Return type:bool
cell_is_text(cell)[source]

All cells are stored as strings, always returns True.

Returns:always returns True.
Return type:bool
close_file()[source]

Closes file if necessary.

get_cell_content(cell)[source]

Returns cell content.

Parameters:cell (str) – cell.
Returns:cell content.
Return type:str
get_cell_value(row_index, column)[source]

Returns value of the cell with given row and column index.

Parameters:
  • row (int) – row index.
  • column (int) – column index.
Returns:

cell value.

Return type:

str

get_rows()[source]

Returns a list of rows.

Returns:list of rows.
Return type:list of list of str
get_sheet_name()[source]

Since csv files do not support sheets, always returns empty string.

Returns:empty string.
Return type:str
is_valid_text(cell)[source]

Checks if a given cell contain valid text.

Parameters:cell (str) – cell.
Returns:True if cell contain valid text, False otherwise.
Return type:bool
open_file(file_name, sheet_name)[source]

Opens a given file and prepares to read data from a given sheet.

Parameters:
  • file_name (str) – path to file with input data.
  • sheet_name (str) – sheet name.
class pyDEA.core.data_processing.read_data_from_xls.XLSReader[source]

Bases: object

This class implements parsing of input data from xls and xlsx files.

open_sheet

xlrd.Sheet

open sheet where data is stored.

cell_is_not_blank(cell)[source]

Checks if a given cell has blank value.

Parameters:cell (xlrd.Cell) – cell.
Returns:True if cell has blank value, False otherwise.
Return type:bool
cell_is_not_empty(cell)[source]

Checks if a given cell has non-empty value.

Parameters:cell (xlrd.Cell) – cell.
Returns:True if cell has non-empty value, False otherwise.
Return type:bool
cell_is_text(cell)[source]

Checks if a given cell contain text.

Parameters:cell (xlrd.Cell) – cell.
Returns:True if cell contain text, False otherwise.
Return type:bool
close_file()[source]

Closes file if necessary.

get_cell_content(cell)[source]

Returns cell content.

Parameters:cell (xlrd.Cell) – cell.
Returns:cell content (type depends on what is stored in the cell).
get_cell_value(row, column)[source]

Returns value of the cell with given row and column index.

Parameters:
  • row (int) – row index.
  • column (int) – column index.
Returns:

cell value.

Return type:

str

get_rows()[source]

Returns a list of rows.

Returns:list of rows.
Return type:list of list of xlrd.Cell
get_sheet_name()[source]

Returns opened sheet name.

Returns:sheet name.
Return type:str
is_valid_text(cell)[source]

Checks if a given cell contain valid text.

Parameters:cell (xlrd.Cell) – cell.
Returns:True if cell contain valid text, False otherwise.
Return type:bool
open_file(file_name, sheet_name)[source]

Opens a given file and prepares to read data from a given sheet.

Parameters:
  • file_name (str) – path to file with input data.
  • sheet_name (str) – sheet name.
pyDEA.core.data_processing.read_data_from_xls.construct_input_data_instance(categories, coefficients)[source]

Constructs proper instance of InputData from categories and coefficients.

Parameters:
  • categories (list of str) – list of categories.
  • coefficients (dict of str to list of double) – dictionary that maps DMU name to a list with coefficients.
Returns:

constructed instance.

Return type:

InputData

pyDEA.core.data_processing.read_data_from_xls.convert_to_dictionary(data, check_value=<function fake_fnc at 0x0000023975E05510>)[source]

Converts given list of data to a dictionary.

Parameters:
  • data (list of str or double) – list where the first element is DMU name, all other elements are coefficients.
  • check_value (func, optional) – function that is called on each element of the data list (except the first one) before adding the coefficient to a dictionary. Defaults to fake_fnc.
Returns:

tuple with the following values:

  • dictionary that maps DMU name to a list with coefficients.
  • true if there are the same DMU names, False otherwise.

Return type:

tuple of dict of str to list of double, bool

pyDEA.core.data_processing.read_data_from_xls.extract_categories(reader, row)[source]

Constructs list of categories out of data in row.

Parameters:
  • reader (CSVReader or XLSReader) – object that implements interface for reading input data.
  • row (list of values) – list of values stored in a row.
Returns:

tuple with list of parsed categories and list fo column indexes where parsed categories were found.

Return type:

tuple of list of str, list of int

pyDEA.core.data_processing.read_data_from_xls.extract_coefficients(reader, row, col_indexes)[source]

Parses row with coefficients.

Parameters:
  • reader (CSVReader or XLSReader) – object that implements interface for reading input data.
  • row (list of values) – list of values stored in a row.
  • col_indexes (list of int) – list of column indexes where categories were found.
Returns:

a tuple with DMU name, list of corresponding coefficients and column index of the first non-empty value.

Return type:

tuple of str, list of double, int

pyDEA.core.data_processing.read_data_from_xls.fake_fnc(count)[source]

Helper function that always returns True.

pyDEA.core.data_processing.read_data_from_xls.find_first_non_empty_col(reader, row)[source]

Finds index of the first non-empty column.

Parameters:
  • reader (CSVReader or XLSReader) – object that implements interface for reading input data.
  • row (list of values) – list of values stored in a row.
Returns:

index of the first non-empty column.

Return type:

int

pyDEA.core.data_processing.read_data_from_xls.has_non_empty_cells(reader, row)[source]

Checks if at least one of the values in array contains non-empty data.

Parameters:
  • reader (CSVReader or XLSReader) – object that implements interface for reading input data.
  • row (list of values) – list of values stored in a row.
Returns:

true if at least one of the values in array contains non-empty data, false otherwise.

Return type:

bool

pyDEA.core.data_processing.read_data_from_xls.read_data(file_name, sheet_name='')[source]

Reads data from a given file.

Parameters:
  • file_name (str) – path to file with input data.
  • sheet_name (str, optional) – name of the excel sheet where data is stored. Defaults to empty string. If it is not given, data is read from the first sheet.
Returns:

tuple with the following components:

  • list of categories (first non-empty row is considered to be a list of categories);
  • list where the first element is DMU name, all other elements are coefficients;
  • name of all DMUs if specified;
  • name of sheet where data was read from.

Return type:

tuple of list of str, list of str, str, str

Note

DMUs and categories can be strings or numbers, so returned types depend on these types.

pyDEA.core.data_processing.read_data_from_xls.validate_data(categories, coefficients)[source]

Checks if given data is valid.

Parameters:
  • categories (list of str) – list of categories.
  • coefficients (dict of str to list of double) – dictionary that maps DMU name to a list with coefficients.
Returns:

True if data in categories and coefficients is valid, False otherwise.

Return type:

bool

pyDEA.core.data_processing.save_data_to_file module

This module implements function to write data to xls file.

pyDEA.core.data_processing.save_data_to_file.create_workbook(output_file)[source]

Creates a proper instance of data file writer depending on file extension. Supported formats are: xls, xslx and csv.

Parameters:output_file (str) – file name.
Returns:created data file writer instance.
Return type:(xlwt.Workbook, XlsxWorkbook or OneCsvWriter)
Raises:ValueError – if a file with not supported extension was provided.
pyDEA.core.data_processing.save_data_to_file.save_data_to_xls(data_file, categories, data, sheet_name='Data')[source]

Writes input data to xls-file.

Parameters:
  • data_file (str) – name of new or existing file where data will be written.
  • categories (list of str) – the first line that will be written to file, it must contain category names and might also contain name of DMUs as the first element.
  • data (list of list of int, float or str) –

    list with data, for example

    >> data = [[‘A’, 1, 2, 3], [‘B’, 2, “a”, 5], [‘C’, 0]]

  • sheet_name (str, optional) – name of the sheet where the data will be written, if the existing sheet name is specified, data will be overwritten on this sheet, defaults to “Data”.
Raises:

ValueError – if sheet_name is empty string or None, or any empty value for xls and xlsx files.

pyDEA.core.data_processing.solution module

This module contains classes that implement various objects for storing solutions.

pyDEA.core.data_processing.solution._solution_id

int

global variable used for generating solution IDs.

class pyDEA.core.data_processing.solution.Solution(input_data)[source]

Bases: object

This class implements basic solution.

_solution_id

int

solution ID.

orientation

str

problem orientation, can take values input or output.

_input_data

InputData

object that stores input data.

efficiency_scores

dict of str to double

dictionary that maps DMU code to efficiency spyDEA.core.

lp_status

dict of str to pulp.LpStatus

dictionary that maps DMU code to LP status (optimal, unbounded, etc).

input_duals

dict of str to dict of str to double

dictionary that maps DMU code to another dictionary that maps input category name to value of dual variable.

output_duals

dict of str to dict of str to double

dictionary that maps DMU code to another dictionary that maps output category name to value of dual variable.

return_to_scale

dict of str to str

dictionary that maps DMU code to the return-to-scale of the DMU

Parameters:input_data (InputData) – object that stores input data.
add_efficiency_score(dmu_code, efficiency_score)[source]

Adds efficiency score of a given DMU to internal data structure.

Parameters:
  • dmu_code (str) – DMU code.
  • efficiency_score (double) – efficiency spyDEA.core.
Raises:

ValueError – if dmu_code does not exist or has invalid value.

add_input_dual(dmu_code, input_category, dual_value)[source]

Adds value of a dual variable associated with a given input category and DMU code to internal data structure.

Parameters:
  • dmu_code (str) – DMU code.
  • input_category (str) – input category name.
  • dual_value (double) – value of a dual variable.
Raises:

ValueError – if a given category is not a valid input category.

add_lambda_variables(dmu_code, variables)[source]

Adds lambda variables corresponding to a given DMU to pickled file.

Parameters:
  • dmu_code (str) – DMU code.
  • variables (dict of str to double) – dictionary that maps DMU codes to the corresponding value of lambda variables.
Raises:

ValueError – if DMU code does not exist or if number of lambda variables is not equal to total number of DMU codes, or if variables contain keys that are not existing DMU codes.

add_lp_status(dmu_code, lp_status)[source]

Adds LP status corresponding to a given DMU to internal data structure.

Parameters:
  • dmu_code (str) – DMU code.
  • lp_status (pulp.LpStatus) – LP status.
add_output_dual(dmu_code, output_category, dual_value)[source]

Adds value of a dual variable associated with a given output category and DMU code to internal data structure.

Parameters:
  • dmu_code (str) – DMU code.
  • output_category (str) – output category name.
  • dual_value (double) – value of a dual variable.
Raises:

ValueError – if a given category is not a valid output category.

get_efficiency_score(dmu_code)[source]

Returns efficiency score of a given DMU.

Parameters:dmu_code (str) – DMU code.
Returns:efficiency spyDEA.core.
Return type:double
get_input_dual(dmu_code, input_category)[source]

Returns dual variable value corresponding to a given DMU and input category.

Parameters:
  • dmu_code (str) – DMU code.
  • input_category (str) – input category name.
Returns:

dual variable value.

Return type:

double

get_lambda_variables(dmu_code)[source]

Returns lambda variables corresponding to a given DMU.

Parameters:dmu_code (str) – DMU code.
Returns:lambda variables.
Return type:dict of str to double
get_output_dual(dmu_code, output_category)[source]

Returns dual variable value corresponding to a given DMU and output category.

Parameters:
  • dmu_code (str) – DMU code.
  • output_category (str) – output category name.
Returns:

dual variable value.

Return type:

double

is_efficient(dmu_code, lambda_variables=None)[source]

Checks if a given DMU is efficient.

Parameters:
  • dmu_code (str) – DMU code.
  • lambda_variables (dict of str to double, optional) – dictionary that maps DMU codes to the corresponding value of lambda variables. If it is not given, it will be loaded from a pickled file.
Returns:

True if a given DMU is efficient, False otherwise.

Return type:

bool

print_solution()[source]

Prints all data on the screen.

class pyDEA.core.data_processing.solution.SolutionWithSuperEfficiency(input_data)[source]

Bases: pyDEA.core.data_processing.solution.Solution

This class redefines one method of Solution to accept efficiency scores greater than 1.

is_efficient(dmu_code, lambda_variables=None)[source]

Returns True if a given DMU is efficient, False otherwise.

We have to redefine this method in the case of super efficiency, because now any DMU with efficiency score >= 1 is considered efficient.

Parameters:
  • dmu_code (str) – internal code of DMU.
  • lambda_variables (dict of str to double, optional) – dictionary that maps DMU codes to the corresponding value of lambda variables. It is ignored in this class.
Returns:

True if a given DMU is efficient, False otherwise.

Return type:

bool

Example

>>> s = SolutionWithSuperEfficiency()
>>> s.add_efficiency_score('dmu_1', 1.2)
>>> s.is_efficient('dmu_1')
True
>>> s.add_efficiency_score('dmu_2', 0.5)
>>> s.is_efficient('dmu_2')
False
>>> s.add_efficiency_score('dmu_3', 0.9999999)
>>> s.is_efficient('dmu_3')
False
class pyDEA.core.data_processing.solution.SolutionWithVRS(model_solution)[source]

Bases: object

This class decorate Solution with VRS variables to store their values for VRS DEA models.

_model_solution

Solution

solution that should be decorated with VRS variables.

vrs_duals

dict of str to double

dictionary that maps DMU code to VRS variable value.

Parameters:model_solution (Solution) – solution that should be decorated with VRS variables.
add_VRS_dual(dmu_code, value)[source]

Adds VRS variable value corresponding to a given DMU to internal data structure.

Parameters:
  • dmu_code (str) – DMU code.
  • value (double) – value of the VRS variable.
get_VRS_dual(dmu_code)[source]

Returns value of a VRS variable corresponding to a given DMU.

Parameters:dmu_code (str) – DMU code.
Returns:value of the VRS variable.
Return type:double
print_solution()[source]

Prints all data on the screen.

pyDEA.core.data_processing.solution_text_writer module

This model contains classes used for writing one page of a solution to a file.

class pyDEA.core.data_processing.solution_text_writer.OneCsvWriter(file_name)[source]

Bases: object

This class is used for writing data to a csv file.

file_name

str

name of the file to create.

tab_writer

TxtOneFileWriter

TxtOneFileWriter object which is responsible to filling csv file with data.

Parameters:file_name (str) – name of the file to create.
add_sheet(name)[source]

Creates a csv file.

Parameters:name (str) –

this parameter is ignored.

Note

This argument is ignored, the file name given in class consructor is used.

Returns:SolutionTextWriter object that is responsible for filling this file with data.
Return type:SolutionTextWriter
save(file_name)[source]

Closes opened csv file.

Parameters:file_name (str) – this parameter is ignored.
class pyDEA.core.data_processing.solution_text_writer.SolutionTextWriter(delimiter, write_fnc)[source]

Bases: object

This class implements generic utility to write formatted data to a given output (usually file, but could be anything that implements a particular interface). Data is written row by row and column by column, as a table.

current_row

int

index of current row.

current_col

int

index of current column.

delimiter

str

delimiter used to separate columns.

Note

Rows are separated by end of line symbol.

write_fnc

callable

function that takes one string argument which should be written to a given output, and writes this argument to that output.

name

str

name of the solution page (i.e. EfficiencyScores, Parameters,...). Name is usually changed by the user or another function manually, for example see module write_data_to_xls.

Parameters:
  • delimiter (str) – delimiter used to separate columns.
  • write_fnc (callable) – function that takes one string argument which should be written to a given output, and writes this argument to that output.
write(row_index, column_index, data)[source]

Writes given data to an output (usually file).

Warning

When using this function, rows and columns must be specified in order, i.e. you can call write(0, 0, ‘data’), then write(1, 0, ‘data’). But you cannot call write(2, 0, ‘data’), and then write(0, 0, ‘data’). Data should be written row by row and column by column.

Parameters:
  • row_index (int) – index of the row where data must be written.
  • column_index (int) – index of the column where data must be written.
  • data (str or float) –

    data that will be written.

    Note

    data will be formatted before writing, see function format_data.

Example

>>> writer = SolutionTextWriter(';', write_fnc)
>>> write(0, 0, 'a')
>>> write(0, 1, 'b')
>>> write(1, 0, 'c')
"\na;b\nc"
class pyDEA.core.data_processing.solution_text_writer.TxtOneFileWriter(file_ref)[source]

Bases: object

This class is a helper class for TxtWriter. It implements function write_text that writes data to a file, and it keeps reference to file.

file_ref

file reference

reference to file where all data is written.

Parameters:file_ref (file reference) – reference to file where all data is written.
write_text(data)[source]

Writes given data to file.

Parameters:data (str) – data to write to file.
class pyDEA.core.data_processing.solution_text_writer.TxtWriter(folder_name)[source]

Bases: object

This class is used for writing solution to csv. It creates a given folder where all csv files will be written and creates solution files in this folder.

folder_name

str

folder for csv files.

tabs

list of file references

list of references to files where solution will be written.

tab_writers

list of SolutionTextWriter

list of SolutionTextWriter objects each of which is responsible to filling one csv file with data.

Parameters:folder_name (str) – folder for csv files.
add_sheet(name)[source]

Creates a csv file that represents one page of the solution.

Parameters:name (str) –

name of the file.

Note

This is a temporary name. After solution is written and save is called, file will be renamed according to a solution page name (i.e. EfficiencyScores).

Returns:SolutionTextWriter object that is responsible for filling this file with data.
Return type:SolutionTextWriter
save(file_name)[source]

Closes all created csv files and renames them according to solution page names.

Parameters:file_name (str) – this parameter is ignored.

pyDEA.core.data_processing.targets_and_slacks module

This module contains functions responsible for calculating various targets for output.

pyDEA.core.data_processing.targets_and_slacks.calculate_non_radial_reduction(target, radial_reduction, original)[source]

Calculates non-radial reduction value.

Parameters:
  • target (double) – DMU target value.
  • radial_reduction (double) – radial reduction value.
  • original (double) – coefficient corresponding to DMU and category of interest.
Returns:

non-radial reduction value.

Return type:

double

pyDEA.core.data_processing.targets_and_slacks.calculate_radial_reduction(dmu_code, category, data, efficiency_score, orientation)[source]

Calculates radial reduction for a given DMU and category.

Parameters:
  • dmu_code (str) – DMU code.
  • category (str) – category name.
  • data (InputData) – object that stores input data.
  • efficiency_score (double) – efficiency spyDEA.core.
  • orientation (str) – problem orientation, can take values input or output.
Returns:

radial reduction value.

Return type:

double

pyDEA.core.data_processing.targets_and_slacks.calculate_target(category, lambda_vars, coefficients)[source]

Returns a target value for a given category.

Parameters:
  • category (str) – category name.
  • lambda_vars (dict of str to double) – dictionary that maps DMU codes to the corresponding value of lambda variables.
  • coefficients (dict of tuple of str, str to double}) – dictionary that maps internal DMU code and category to the corresponding coefficient, e.g. {(DMU, category) : value}.
Returns:

target value.

Return type:

double

pyDEA.core.data_processing.write_data_to_xls module

This module contains functions and classes responsible for writing solutions into different outputs (files, screen, GUI, etc). All names start with XLS because originally only xls-files were supported.

Warning

if new methods for writing output are added, they MUST follow the rule: data must be added sequentially, row after row, column after column.

class pyDEA.core.data_processing.write_data_to_xls.XLSSheetOnionRank(ranks)[source]

Bases: object

Writes information about peel the onion solution to a given output.

ranks

list of dict of str to double

list that contains dictionaries that map DMU code to peel the onion rank.

Parameters:ranks (list of dict of str to double) – list that contains dictionaries that map DMU code to peel the onion rank.
create_sheet_onion_rank(work_sheet, solution, start_row_index, params_str)[source]

Writes information about peel the onion solution to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

class pyDEA.core.data_processing.write_data_to_xls.XLSSheetWithCategoricalVar(categorical=None)[source]

Bases: object

Writes various solution information to a given output, and adds categorical information if necessary.

categorical

str

name of categorical category.

Parameters:categorical (str) – name of categorical category.
create_sheet_efficiency_scores(work_sheet, solution, start_row_index, params_str)[source]

Writes efficiency scores to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

create_sheet_input_output_data(work_sheet, solution, start_row_index, params_str)[source]

Writes input and output weights to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

create_sheet_input_output_data_base(work_sheet, solution, get_multiplier, sheet_name, start_row_index, params_str)[source]

Writes input and output weights or weighted data to a given output depending on input parameters.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • get_multiplier (func) – function that scales weights.
  • sheet_name (str) – name that will be written into the name attribute of work_sheet.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

create_sheet_targets(work_sheet, solution, start_row_index, params_str)[source]

Writes targets to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

create_sheet_weighted_data(work_sheet, solution, start_row_index, params_str)[source]

Writes weighted data to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

class pyDEA.core.data_processing.write_data_to_xls.XLSSheetWithParameters(params, run_date, total_seconds)[source]

Bases: object

Writes parameters to a given output.

params

Parameters

parameters.

run_date

datetime

date and time when the problem was solved.

total_seconds

float

time (in seconds) needed to solve the problem.

Parameters:
  • params (Parameters) – parameters.
  • run_date (datetime) – date and time when the problem was solved.
  • total_seconds (float) – time (in seconds) needed to solve the problem.
create_sheet_parameters(work_sheet, solution, start_row_index, params_str)[source]

Writes parameters to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

class pyDEA.core.data_processing.write_data_to_xls.XLSWriter(params, writer, run_date, total_seconds, worksheets=None, ranks=None, categorical=None)[source]

Bases: object

This class is responsible for writing solution information into a given output.

params

Parameters

parameters.

writer

object that contains several objects that have name attribute and implement write method, it actually writes data to some output (like file, screen, etc.).

ranks

list of dict of str to double

list that contains dictionaries that map DMU code to peel the onion rank.

categorical

str

name of categorical category.

run_date

datetime

date and time when the problem was solved.

total_seconds

float

time (in seconds) needed to solve the problem.

params_sheet

XLSSheetWithParameters

object that writes parameters to a given output.

worksheets

list of func

list of functions that will be called to write solution information to a given output.

start_rows

list of int

list of start row indexes for each element in worksheets.

existing_sheets

list of func

contains None references in the beginning, but after at least one call to write_data method contains a copy of worksheets. It is necessary for appending data to the same output.

print_params

bool

if set to true parameters are written to a given output. It ensures that we don’t write parameters more than once if we should append information to the same output.

Parameters:
  • params (Parameters) – parameters.
  • writer – object that contains several objects that have name attribute and implement write method, it actually writes data to some output (like file, screen, etc.).
  • run_date (datetime) – date and time when the problem was solved.
  • total_seconds (float) – time (in seconds) needed to solve the problem.
  • worksheets (list of func, optional) – list of functions that will be called to write solution information to a given output. Defaults to None.
  • ranks (list of dict of str to double, optional) – list that contains dictionaries that map DMU code to peel the onion rank. Defaults to None.
  • categorical (str, optional) – name of categorical category. Defaults to None.
get_default_worksheets()[source]

Returns a default list of functions that will be called to write solution information to a given output.

Returns:list of functions.
Return type:list of func
write_data(solution, params_str='', progress_recorder=<pyDEA.core.utils.progress_recorders.NullProgress object at 0x000002397784AF98>)[source]

Writes given solution to a given output.

Parameters:
  • solution (Solution) – solution.
  • params_str (str, optional) – string that is usually written in the first row. Defaults to empty string.
  • progress_recorder (NullProgress, optional) – object that shows progress with writing solution to a given output. Defaults to NullProgress.
pyDEA.core.data_processing.write_data_to_xls.create_sheet_peer_count(work_sheet, solution, start_row_index, params_str)[source]

Writes peer counts to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

pyDEA.core.data_processing.write_data_to_xls.create_sheet_peers(work_sheet, solution, start_row_index, params_str)[source]

Writes peers to a given output.

Parameters:
  • work_sheet – object that has name attribute and implements write method, it actually writes data to some output (like file, screen, etc.).
  • solution (Solution) – solution.
  • start_row_index (int) – initial row index (usually used to append data to existing output).
  • params_str (str) – string that is usually written in the first row.
Returns:

index of the last row where data were written plus 1.

Return type:

int

pyDEA.core.data_processing.xlsx_workbook module

This module contains classes responsible for wrapping openpyxl functionality for creating xlsx files.

class pyDEA.core.data_processing.xlsx_workbook.XlsxSheet(worksheet)[source]

Bases: object

This class wraps openpyxl work sheet so that it can be used by xls writer class.

name

str

work sheet name.

worksheet

openpyxl work sheet

worksheet to wrap.

Parameters:worksheet (openpyxl work sheet) – worksheet to wrap.
name
write(row, col, value)[source]

Writes given value to a cell with specified row and column.

Parameters:
  • row (int) – row index.
  • col (int) – column index.
  • value (object) – value to write.
class pyDEA.core.data_processing.xlsx_workbook.XlsxWorkbook[source]

Bases: object

This class wraps openpyxl workbook so it can be used by xls writer class.

workbook

openpyxl workbook

workbook.

nb_sheets

int

number of added work sheets.

add_sheet(sheet_name)[source]

Adds one sheet to the workbook.

Parameters:sheet_name (str) – name of the work sheet.
Returns:created work sheet.
Return type:XlsxSheet
save(file_name)[source]

Saves workbook to a given file.

Parameters:file_name (str) – name of the file where workbook should be saved.

Module contents