def main_case_count_calculations(self):
     """This method calculates the entire Case Count KPIs set."""
     if self.filtered_mdis.empty or self.filtered_scif.empty:
         return
     try:
         self._prepare_data_for_calculation()
         total_facings_per_brand_res = self._calculate_total_bottler_and_carton_facings(
         )
         self._save_results_to_db(total_facings_per_brand_res,
                                  Ccc.TOTAL_FACINGS_KPI)
         cases_per_brand_res = self._count_number_of_cases()
         self._save_results_to_db(cases_per_brand_res, Ccc.CASE_COUNT_KPI)
         unshoppable_brands_lst = self._non_shoppable_case_kpi()
         self._save_results_to_db(unshoppable_brands_lst,
                                  Ccc.NON_SHOPPABLE_CASES_KPI)
         implied_shoppable_cases_kpi_res = self._implied_shoppable_cases_kpi(
         )
         self._save_results_to_db(implied_shoppable_cases_kpi_res,
                                  Ccc.IMPLIED_SHOPPABLE_CASES_KPI)
         total_cases_res = self._calculate_and_total_cases(
             cases_per_brand_res + implied_shoppable_cases_kpi_res)
         self._save_results_to_db(total_cases_res,
                                  Ccc.TOTAL_CASES_KPI,
                                  should_enter=False)
     except Exception as err:
         Log.error(
             "DiageoUS Case Count calculation failed due to the following error: {}"
             .format(err))
 def main_case_count_calculations(self):
     """This method calculates the entire Case Count KPIs set."""
     if not (self.filtered_scif.empty or self.matches.empty):
         try:
             if not self.filtered_mdis.empty:
                 self._prepare_data_for_calculation()
                 self._generate_adj_graphs()
                 facings_res = self._calculate_display_size_facings()
                 sku_cases_res = self._count_number_of_cases()
                 unshoppable_cases_res = self._non_shoppable_case_kpi()
                 implied_cases_res = self._implied_shoppable_cases_kpi()
             else:
                 facings_res = self._calculate_display_size_facings()
                 sku_cases_res = self._count_number_of_cases()
                 unshoppable_cases_res = []
                 implied_cases_res = []
             sku_cases_res = self._remove_nonshoppable_cases_from_shoppable_cases(
                 sku_cases_res, unshoppable_cases_res)
             total_res = self._calculate_total_cases(sku_cases_res +
                                                     implied_cases_res +
                                                     unshoppable_cases_res)
             placeholder_res = self._generate_placeholder_results(
                 facings_res, sku_cases_res, unshoppable_cases_res,
                 implied_cases_res)
             self._save_results_to_db(facings_res + sku_cases_res +
                                      unshoppable_cases_res +
                                      implied_cases_res + total_res +
                                      placeholder_res)
             self._calculate_total_score_level_res(total_res)
         except Exception as err:
             Log.error(
                 "DiageoUS Case Count calculation failed due to the following error: {}"
                 .format(err))
 def get_closest_point(origin_point, other_points_df):
     """This method gets a point (x & y coordinates) and checks what is the closet point the could be
     found in the DataFrame that is being received.
     @param: origin_point (tuple): coordinates of x and y
     @param: other_points_df (DataFrame): A DF that has rect_x' and 'rect_y' columns
     @return: A DataFrame with the closest points and the rest of the data
     """
     other_points = other_points_df[['rect_x', 'rect_y']].values
     # Euclidean geometry magic
     distances = np.sum((other_points - origin_point) ** 2, axis=1)
     # get the shortest hypotenuse
     try:
         closest_point = other_points[np.argmin(distances)]
     except ValueError:
         Log.error('Unable to find a matching opposite point for supplied anchor!')
         return other_points_df
     return other_points_df[
         (other_points_df['rect_x'] == closest_point[0]) & (other_points_df['rect_y'] == closest_point[1])]