# Path: pyDEA/core/utils/dea_utils.py
# ZERO_TOLERANCE = 1e-10
# 
# Path: pyDEA/core/data_processing/targets_and_slacks.py
# def calculate_target(category, lambda_vars, coefficients):
#     ''' Returns a target value for a given category.
# 
#         Args:
#             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:
#             double: target value.
#     '''
#     target = 0
#     for dmu, value in lambda_vars.items():
#         target += value * coefficients[dmu, category]
#     return target
# 
# Path: pyDEA/core/data_processing/targets_and_slacks.py
# def calculate_radial_reduction(dmu_code, category, data, efficiency_score,
#                                orientation):
#     ''' Calculates radial reduction for a given DMU and category.
# 
#         Args:
#             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:
#             double: radial reduction value.
#     '''
#     # if input-oriented, then radial reduction is
#     # zero for all outputs
#     # if output-oriented, then radial reduction is
#     # zero for all inputs
#     if orientation == 'input':
#         if category in data.output_categories:
#             return 0
#         objective_value = efficiency_score
#     elif orientation == 'output':
#         if category in data.input_categories:
#             return 0
#         objective_value = 1/efficiency_score
# 
#     return (objective_value - 1) * data.coefficients[dmu_code, category]
# 
# Path: pyDEA/core/data_processing/targets_and_slacks.py
# def calculate_non_radial_reduction(target, radial_reduction, original):
#     ''' Calculates non-radial reduction value.
# 
#         Args:
#             target (double): DMU target value.
#             radial_reduction (double): radial reduction value.
#             original (double): coefficient corresponding to DMU and category
#                 of interest.
# 
#         Returns:
#             double: non-radial reduction value.
#     '''
#     return target - original - radial_reduction
# 
# Path: pyDEA/core/utils/progress_recorders.py
# class NullProgress(object):
#     ''' This class does not update solution progress. It is used in
#         terminal application.
#     '''
#     def set_position(self, position):
#         ''' Does nothing.
#         '''
#         pass
# 
#     def increment_step(self):
#         ''' Does nothing.
#         '''
#         pass


import pulp
from itertools import chain
from collections import defaultdict
from pyDEA.core.utils.dea_utils import ZERO_TOLERANCE
from pyDEA.core.data_processing.targets_and_slacks import calculate_target
from pyDEA.core.data_processing.targets_and_slacks import calculate_radial_reduction
from pyDEA.core.data_processing.targets_and_slacks import calculate_non_radial_reduction
from pyDEA.core.utils.progress_recorders import NullProgress

        work_sheet.write(start_row_index, 0, params_str)
        work_sheet.write(start_row_index + 1, 0, 'DMU')
        work_sheet.write(start_row_index + 1, 1, 'Category')
        work_sheet.write(start_row_index + 1, 2, 'Original')
        work_sheet.write(start_row_index + 1, 3, 'Target')
        work_sheet.write(start_row_index + 1, 4, 'Radial')
        work_sheet.write(start_row_index + 1, 5, 'Non-radial')
        if self.categorical is not None:
            work_sheet.write(
                start_row_index + 1, 6,
                'Categorical: {0}'.format(self.categorical))

        ordered_dmu_codes = solution._input_data.DMU_codes_in_added_order
        row_index = start_row_index + 2
        for dmu_code in ordered_dmu_codes:
            work_sheet.write(
                row_index, 0, solution._input_data.get_dmu_user_name(dmu_code))

            if solution.lp_status[dmu_code] == pulp.LpStatusOptimal:

                once = True
                all_lambda_vars = solution.get_lambda_variables(dmu_code)
                for category in chain(solution._input_data.input_categories,
                                      solution._input_data.output_categories):
                    work_sheet.write(row_index, 1, category)
                    original = solution._input_data.coefficients[
                        dmu_code, category]
                    work_sheet.write(row_index, 2, original)


# Path: pyDEA/core/utils/dea_utils.py
# ZERO_TOLERANCE = 1e-10
# 
# Path: pyDEA/core/data_processing/targets_and_slacks.py
# def calculate_target(category, lambda_vars, coefficients):
#     ''' Returns a target value for a given category.
# 
#         Args:
#             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:
#             double: target value.
#     '''
#     target = 0
#     for dmu, value in lambda_vars.items():
#         target += value * coefficients[dmu, category]
#     return target
# 
# Path: pyDEA/core/data_processing/targets_and_slacks.py
# def calculate_radial_reduction(dmu_code, category, data, efficiency_score,
#                                orientation):
#     ''' Calculates radial reduction for a given DMU and category.
# 
#         Args:
#             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:
#             double: radial reduction value.
#     '''
#     # if input-oriented, then radial reduction is
#     # zero for all outputs
#     # if output-oriented, then radial reduction is
#     # zero for all inputs
#     if orientation == 'input':
#         if category in data.output_categories:
#             return 0
#         objective_value = efficiency_score
#     elif orientation == 'output':
#         if category in data.input_categories:
#             return 0
#         objective_value = 1/efficiency_score
# 
#     return (objective_value - 1) * data.coefficients[dmu_code, category]
# 
# Path: pyDEA/core/data_processing/targets_and_slacks.py
# def calculate_non_radial_reduction(target, radial_reduction, original):
#     ''' Calculates non-radial reduction value.
# 
#         Args:
#             target (double): DMU target value.
#             radial_reduction (double): radial reduction value.
#             original (double): coefficient corresponding to DMU and category
#                 of interest.
# 
#         Returns:
#             double: non-radial reduction value.
#     '''
#     return target - original - radial_reduction
# 
# Path: pyDEA/core/utils/progress_recorders.py
# class NullProgress(object):
#     ''' This class does not update solution progress. It is used in
#         terminal application.
#     '''
#     def set_position(self, position):
#         ''' Does nothing.
#         '''
#         pass
# 
#     def increment_step(self):
#         ''' Does nothing.
#         '''
#         pass


# Path: pyDEA/core/data_processing/write_data.py
import pulp
from itertools import chain
from collections import defaultdict
from pyDEA.core.utils.dea_utils import ZERO_TOLERANCE
from pyDEA.core.data_processing.targets_and_slacks import calculate_target
from pyDEA.core.data_processing.targets_and_slacks import calculate_radial_reduction
from pyDEA.core.data_processing.targets_and_slacks import calculate_non_radial_reduction
from pyDEA.core.utils.progress_recorders import NullProgress


        work_sheet.write(start_row_index, 0, params_str)
        work_sheet.write(start_row_index + 1, 0, 'DMU')
        work_sheet.write(start_row_index + 1, 1, 'Category')
        work_sheet.write(start_row_index + 1, 2, 'Original')
        work_sheet.write(start_row_index + 1, 3, 'Target')
        work_sheet.write(start_row_index + 1, 4, 'Radial')
        work_sheet.write(start_row_index + 1, 5, 'Non-radial')
        if self.categorical is not None:
            work_sheet.write(
                start_row_index + 1, 6,
                'Categorical: {0}'.format(self.categorical))

        ordered_dmu_codes = solution._input_data.DMU_codes_in_added_order
        row_index = start_row_index + 2
        for dmu_code in ordered_dmu_codes:
            work_sheet.write(
                row_index, 0, solution._input_data.get_dmu_user_name(dmu_code))

            if solution.lp_status[dmu_code] == pulp.LpStatusOptimal:

                once = True
                all_lambda_vars = solution.get_lambda_variables(dmu_code)
                for category in chain(solution._input_data.input_categories,
                                      solution._input_data.output_categories):
                    work_sheet.write(row_index, 1, category)
                    original = solution._input_data.coefficients[
                        dmu_code, category]
                    work_sheet.write(row_index, 2, original)


                    target = calculate_target(category, all_lambda_vars,