Esempio n. 1
0
    def tick(self):
        self.lock.acquire()
        # append the sales record to the history
        self.sales_history.append(self.item_sold)
        # reset the sales counter
        self.item_sold = 0

        self.lock.release()

        # Calculate the metrics for previous tick and add to tracker
        self.revenue_history.append(self.sales_history[-1] * self.product.price)
        self.profit_history.append(self.revenue_history[-1] - self.expense_history[-1])
        self.sentiment_history.append(self.user_sentiment())

        # add the profit to seller's wallet
        self.wallet += self.my_profit(True)

        # choose what to do for next timestep
        advert_type, scale = self.CEO()

        # ANSWER a. print data to show progress
        #test=', '.join(for x in self.sentiment_history)
        
        logging.info ('[Seller]: (%s,%d) Revenue in previous quarter:%d', self.name,self.tickcount,self.my_revenue(True))
        logging.info ('[Seller]: (%s,%d) Expenses in previous quarter:%d', self.name,self.tickcount,self.my_expenses(True))
        logging.info ('[Seller]: (%s,%d) Profit in previous quarter:%d', self.name,self.tickcount,self.my_profit(True))
        logging.info ('[Seller]: (%s,%d) Sentiment in previous quarter:%d', self.name,self.tickcount,self.user_sentiment())
        #logging.info ('[Seller]: (%s,%d) Sales in previous quarter:%d', self.name,self.tickcount,self.sales_history(True))
        #logging.info ('[Seller]: (%s,%d)Strategy for next quarter \nAdvert Type: {}, scale: {}\n\n'.format(advert_type, scale))
        
        # perform the actions and view the expense
        self.expense_history.append(GoogleAds.post_advertisement(self, self.product, advert_type, scale))
Esempio n. 2
0
    def CEO(self):
        """
        Choose advertisement types and scales for each product based on revenue and user_coverage.
        If user_coverage is less than target, choose basic ads, otherwise choose targeted ads.
        
        Set total advertisement budget less than a percentage of revenue or wallet money, to avoid bankrupt
        Scale (number of ads to put) equals to budget divided by advert price.
        
        :return: none
        """
        # initilize empty variable
        advert_type = {}
        expense = {}
        ads_type = GoogleAds.ADVERT_BASIC
        
        # set advertising budget as a percentage of total revenue or total money in wallet
        ads_percent = 0.5
        max_budget = self.wallet * 0.2
        
        # decide individual advertising strategy for each product
        for product in self.products_list:
            
            # get the latest revenue to decide ads budget
            revenue = self.revenue_history[-1][product]
            
            #avoid bankrupt by setting advertisment budget
            ads_budget = max(ads_percent * revenue, max_budget)
            coverage = GoogleAds.user_coverage(product)
            
            # check if user_coverage is more than half of GoogleAds users
            if coverage > 0.5:
                ads_type = GoogleAds.ADVERT_TARGETED

            scale = min(int(ads_budget / GoogleAds.advert_price[ads_type]), 500)
                        
            # perform the actions and view the expense
            advert_type.update({product: (ads_type, scale)})
            
            # obtain expense from GoogleAds
            expense.update({product: GoogleAds.post_advertisement(self, product, ads_type, scale)})
        
        # store advertisement types and scales, and expense history
        self.advert_history.append(advert_type)
        self.expense_history.append(expense)
               
        return
Esempio n. 3
0
    def tick(self):
        """ in each tick, each product will be considered iteratively 
        while in CEO decsion function, all products will be considered in each decsion"""
        self.dataCenter.seller_info_update(self.count)
        """ decide whether to buy cheating data sheets in each tick count > 20 """
        self.data_cheating = False
        if self.count > 20 and random.random() > 0.7:
            self.data_cheating = True
            """obtain cheating data sheet """
            self.dataCenter.send_data(self)
            # the price of a cheating package is related to package size
            self.wallet -= 20 * self.count
            self.cheating_package = self.dataCenter.send_data(self)

        for product in self.product_list:
            self.lock.acquire()

            # append the sales record to the history
            self.dataCenter.data_ranking(obj_data=[product, self],
                                         data_type='seller')
            self.sales_history[product].append(self.item_sold[product])
            self.product_storage[product] -= self.item_sold[product]

            # reset the sales counter
            self.item_sold[product] = 0

            # Calculate the metrics for previous tick and add to tracker
            self.revenue_history[product].append(
                self.sales_history[product][-1] *
                self.price_history[product][-1])
            self.profit_history[product].append(
                self.revenue_history[product][-1] -
                self.expense_history[product][-1])
            self.wallet += self.profit_history[product][-1]
            self.sentiment_history[product].append(
                self.user_sentiment(product))
            self.price_history[product].append(
                self.price_history[product][-1] + self.CEO_price(product))

            # add the profit to seller's wallet
            self.wallet += self.my_profit(product, True)
            self.lock.release()

            # choose what to do for next timestep

            advert_type, user_list, scale = self.CEO_advertisement(product)

            # ANSWER a. print data to show progress
            print('\nProduct in previous quarter: ' + product.name)
            print('Revenue in previous quarter:',
                  self.my_revenue(product, True))
            print('Expenses in previous quarter:',
                  self.my_expenses(product, True))
            print('Profit in previous quarter:', self.my_profit(product, True))
            print(
                '\nStrategy for next quarter \nAdvert Type: {}, scale: {}\n\n'.
                format(advert_type, scale))
            print('\n', self.count)

            # avoid bankrupt
            if self.count > 0 and self.revenue_history[product][-1] > 0:
                budget = ad_budget_ration * self.revenue_history[product][-1]
            elif self.count == 0:
                budget = ad_budget_ration * self.wallet / len(
                    self.product_list)
                # perform the actions and view the expense
            else:
                budget = 0
            if self.product_storage[product] > 0:
                self.expense_history[product].append(
                    GoogleAds.post_advertisement(self, product, advert_type,
                                                 user_list, scale, budget))
            else:
                self.expense_history[product].append(0)
        print(self.name + ' wallet: ' + str(self.wallet))
Esempio n. 4
0
    def tick(self):
        self.lock.acquire()

        # append the sales record to the history
        self.sales_history.append(self.item_sold)

        # reset the sales counter
        self.item_sold = 0

        self.lock.release()

        # Calculate the metrics for previous tick and add to tracker
        for product in self.products:
            # logging.info("[Seller]: (%s,%d) sold  %d units of %s",self.name,self.tick_count,self.item_sold, product.product_name)
            self.revenue_history.append(self.sales_history[-1] *
                                        product.stock_price)
            self.profit_history.append(self.revenue_history[-1] -
                                       self.expense_history[-1])
            self.sentiment_history.append(self.user_sentiment())

        # add the profit to seller's wallet
        # self.wallet += self.my_profit(True)

        # choose what to do for next timestep
        ceo = CEO(self)
        # advert_type, scale = ceo.analyze()
        ceo.check_any_products_out_of_stock()
        ceo.purchase_stock()

        if self.wallet < 200:
            ceo.apply_discount_for_all_products()
        else:
            ceo.adjust_price()

        # ANSWER a. print data to show progress
        # print('Revenue in previous quarter:', self.my_revenue(True))
        # print('Expenses in previous quarter:', self.my_expenses(True))
        # print('Profit in previous quarter:', self.my_profit(True))
        # print('\nStrategy for next quarter \nAdvert Type: {}, scale: {}\n\n'.format(advert_type, scale))

        # logging.info('[Seller]: (%s,%d) Revenue in previous quarter:%d', self.name, self.tick_count, self.my_revenue(True))
        # logging.info('[Seller]: (%s,%d) Expenses in previous quarter:%d', self.name, self.tick_count, self.my_expenses(True))
        # logging.info('[Seller]: (%s,%d) Profit in previous quarter:%d', self.name, self.tick_count, self.my_profit(True))
        # logging.info('[Seller]: (%s,%d) Sales in previous quarter:%s', self.name, self.tick_count, self.sales_history)

        # perform the actions and view the expense
        for product in self.products:
            # choose between ad type and scale
            advert_type, scale = ceo.analyze(product)
            # decide how much to spend on ads
            budget = ceo.decide_how_much_to_spend_on_ads()
            if GoogleAds.post_advertisement(self, product, advert_type,
                                            scale) > budget:
                logging.info(
                    '[Seller,(%s,%d)]: The cost of product %s on ads exceeds the budget, do not spend.',
                    self.name, self.tick_count, product.product_name)
            else:
                logging.info(
                    '[Seller,(%s,%d)]: The cost of product %s on ads is less than the budget, then buy ads.',
                    self.name, self.tick_count, product.product_name)
                self.expense_history.append(
                    GoogleAds.post_advertisement(self, product, advert_type,
                                                 scale))