示例#1
0
    def set_accuracy_data(self):
        """
    Set up accuracy data for one hotel
    """
        if self.department_accuracy_data is None:
            dep_have_revenue_data = self.get_list_dept(
                has_revenue=True, no_include_hotel_id=False)
            l_df = []
            for dep_id in dep_have_revenue_data:
                try:
                    dep_acc_data = self.db.get_department_forecast_accuracy_data(
                        self.client_id, dep_id, ACCURACY_LEADTIME)
                except:
                    log.warning('%s:%s %s:%s Cannot_get_accuracy_data:1' %
                                (col_name.CLIENT, self.client_id,
                                 col_name.DEPT_ID, dep_id))
                    continue

                if not dep_acc_data:
                    log.warning('%s:%s %s:%s Cannot_get_accuracy_data:1' %
                                (col_name.CLIENT, self.client_id,
                                 col_name.DEPT_ID, dep_id))


#        dep_acc_data = pd.DataFrame(dep_acc_data, index=[0])
#        dep_acc_data['H_Id'] = dep_id
#mm
                dep_acc_data = pd.DataFrame(dep_acc_data)
                dep_acc_data = dep_acc_data[dep_acc_data['H_Id'] == dep_id]

                l_df.append(dep_acc_data)

            self.department_accuracy_data = pd.concat(l_df, ignore_index=True)
 def create_season_df(self, json_data):
     """
 Using d2o api to get season data.
 Returns:
   pd.DataFrame: season data in dataframe format
   |Id|From|To|Names|Color
 """
     try:
         l_df = []
         for period in json_data['Periods']:
             if period['Dates'] == []:
                 continue
             else:
                 df = pd.DataFrame(period['Dates'])
                 df['Color'] = period['Color']
                 df['Names'] = period['Name']
                 df['From'] = pd.to_datetime(df['From'])
                 df['To'] = pd.to_datetime(df['To'])
                 df = df[['Id', 'From', 'To', 'Names', 'Color']]
                 l_df.append(df)
         from_to_ss_df = pd.concat(l_df, ignore_index=True)
         from_to_ss_df = from_to_ss_df[from_to_ss_df.Color != '#000000']
         return from_to_ss_df
     except Exception, e:
         log.warning('No_season_data')
         return None
示例#3
0
 def set_hotel_total_data(self):
     """
 if hotel total data (total is a special kind of department data) set up hotel_total_data as
 dataframe follows structure bellow:
 Date | DepId | Guest | Unit | Revenue | FoodRevenue | TotalFoodRevenue
 """
     if self.hotel_total_data is None:
         data_in_json = self.db.get_hotel_food_revenue_in_a_specific_time_period(
             self.client_id, self.hotel_id, self.from_date, self.to_date)
         if len(data_in_json) > 0:
             total_rev_food_df = pd.DataFrame(data_in_json)
             total_rev_food_df['Date'] = pd.to_datetime(
                 total_rev_food_df['Date'])
             total_rev_food_df.set_index('Date', inplace=True)
             self.hotel_total_data = total_rev_food_df
         else:
             warning_mess = '%s:%s %s:%s %s' % (
                 col_name.CLIENT, self.client_id, col_name.H_ID,
                 self.hotel_id, 'Total_data_empty:1')
             log.warning(warning_mess)