예제 #1
0
 def get_update_frame_interval(self, tracking_fps):
     source_video_fps = self.get_source_video_fps()
                             
     interval = float(source_video_fps / tracking_fps)
     
     # round 
     interval = Context(prec=1, rounding=ROUND_HALF_UP).create_decimal(interval)
     self.pym.PY_LOG(False, 'D', self.__class__, 'update frame interval : %.2f' % interval)                                                                  
     return interval
예제 #2
0
 def get_pick_up_frame_interval(self, vott_video_fps):
     source_video_fps = self.get_source_video_fps()
     self.pym.PY_LOG(False, 'D', self.__class__, 'source_video_fps: %d' % source_video_fps)
                             
     interval = float(source_video_fps / vott_video_fps)
     
     # round 
     interval = Context(prec=1, rounding=ROUND_HALF_UP).create_decimal(interval)
     self.pym.PY_LOG(False, 'D', self.__class__, 'pick up frame interval : %.2f' % interval)                                                                  
     return interval
예제 #3
0
def Check_mouse_speed(messageL):
    global hit_flag
    global start
    global end
    global text
    if hit_flag == 0:
        start = time.perf_counter()
        hit_flag = 1
        var_username.set("开始")
        messageL["bg"] = "green"

    else:
        hit_flag = 0
        end = time.perf_counter()
        end = end - start
        #print(Context(prec=5, rounding=ROUND_HALF_UP).create_decimal('1.315097868'))
        text = str(
            Context(prec=5, rounding=ROUND_HALF_UP).create_decimal(
                str(end))) + "s"
        var_username.set(text)
        messageL["bg"] = "red"
예제 #4
0
①.当被修约的值为5时,如果他前面的数为偶数且被修约数的后面没有数时则舍弃;
②.当被修约的值为5时,如果他前面的数为偶数时且被修约数的后面还有数时,则进位。
③.当被修约的值为5时,如果他前面的数为奇数时则进位;

被修约的数字等于5时,要看5前面的数字,
    若是奇数则进位,
    若是偶数则将5舍掉,即修约后末尾数字都成为偶数;
    若5的后面还有不为“0”的任何数,则此时无论5的前面是奇数还是偶数,均应进位。
'''
print(round(22.5))
print(round(22.51))

print(round(23.5))
print(round(22.51))

#四舍五入方法
# 1.扩大100倍然后缩小100

# 2.用decmicial模块
from _pydecimal import Decimal, Context, ROUND_HALF_UP
print(Context(prec=4, rounding=ROUND_HALF_UP).create_decimal('0.3255'))

#利用’’%.af’’%b——其中 b 代表要限定的数字, a 代表要求限定小数点的位数,结果自动四舍五入。
c = 1.264871331241212
# for each in data:
#     print("%.3f"%each)

data = [[22.4999, 22.5551, 23.5555, 23.5551],
        [22.5555, 22.5551, 23.5555, 23.5551]]
print(np.round(data, decimals=3))
print(type(np.round(1.23456, decimals=3)))
예제 #5
0
 def roundValue(value, n=None):
     return (Context(prec=3, rounding=ROUND_HALF_UP).create_decimal(str(value)))
예제 #6
0
    def result(self, festival, product_id, source_id):
        self.result_data[str(product_id)] = {}
        if self.oneday:
            self.result_data[str(product_id)][str(self.special_day_year)] = []

            if source_id:
                #Pandas dataframe 模式
                df_product_id = self.table.query(
                    f'product_id in @product_id and (source_id in @source_id)')

                #Django ORM 模式
                # df_product_id = self.table.filter(product__in=product_id).filter(source__in=source_id)
            else:
                #Pandas dataframe 模式
                df_product_id = self.table.query(f'product_id in @product_id')

                #Django ORM 模式
                # df_product_id = self.table.filter(product__in=product_id)

            #Pandas dataframe 模式
            if df_product_id['avg_price'].any():
                has_volume = df_product_id['volume'].notna().sum(
                ) / df_product_id['avg_price'].count() > 0.8
                has_weight = df_product_id['avg_weight'].notna().sum(
                ) / df_product_id['avg_price'].count() > 0.8
            else:
                has_volume = False
                has_weight = False
            if has_volume and has_weight:
                avgprice = (df_product_id['avg_price'] *
                            df_product_id['avg_weight'] *
                            df_product_id['volume']).sum() / (
                                df_product_id['avg_weight'] *
                                df_product_id['volume']).sum()
            elif has_volume:
                avgprice = (df_product_id['avg_price'] *
                            df_product_id['volume']
                            ).sum() / df_product_id['volume'].sum()
            else:
                avgprice = df_product_id['avg_price'].mean()

            #Django ORM 模式
            # total_price = list()
            # total_volume = list()
            # if df_product_id.count():
            #     if df_product_id.filter(volume__isnull=False).count() / df_product_id.count() > 0.8:
            #         for q in df_product_id:
            #             total_price.append(q.avg_price * q.volume)
            #             total_volume.append(q.volume)
            #             avgprice = sum(total_price) / sum(total_volume) if len(total_volume) else 0
            #     else:
            #         for q in df_product_id:
            #             total_price.append(q.avg_price)
            #             avgprice = sum(total_price) / len(total_price) if len(total_price) else 0
            # else:
            #     avgprice = 'nan'

            self.result_data[str(product_id)][str(
                self.special_day_year)].append(
                    float(
                        Context(
                            prec=28,
                            rounding=ROUND_HALF_UP).create_decimal(avgprice)))

        else:
            for y in range(self.roc_before5years, self.roc_year + 1):
                self.result_data[str(product_id)][str(y)] = []

            for y in range(self.roc_before5years, self.roc_year + 1):
                if festival == 1:
                    date_range = self.Chinese_New_Year_dict[str(y)]
                if festival == 2:
                    date_range = self.Dragon_Boat_Festival_dict[str(y)]
                if festival == 3:
                    date_range = self.Mid_Autumn_Festival_dict[str(y)]

                for d in date_range:
                    start_date = datetime.strptime(
                        "{}".format(d.split('~')[0]), "%Y-%m-%d").date()
                    end_date = datetime.strptime("{}".format(d.split('~')[1]),
                                                 "%Y-%m-%d").date()

                    if source_id:
                        df_product_id = self.table.query(
                            f'product_id in @product_id and date >= "{start_date}" and date <= "{end_date}" and (source_id in @source_id)'
                        )
                        # df_product_id = self.table.filter(product__in=product_id).filter(source__in=source_id).filter(date >=start_date).filter(date <= end_date)

                    else:
                        df_product_id = self.table.query(
                            f'product_id in @product_id and date >= "{start_date}" and date <= "{end_date}"'
                        )
                        # df_product_id = self.table.filter(product__in=product_id).filter(date >=start_date).filter(date <= end_date)

                    if df_product_id.shape[0]:
                        has_volume = df_product_id['volume'].count(
                        ) / df_product_id.shape[0] > 0.8
                        has_weight = df_product_id['avg_weight'].count(
                        ) / df_product_id.shape[0] > 0.8
                    else:
                        has_volume = False
                        has_weight = False
                    if has_volume and has_weight:
                        avgprice = (df_product_id['avg_price'] *
                                    df_product_id['avg_weight'] *
                                    df_product_id['volume']).sum() / (
                                        df_product_id['avg_weight'] *
                                        df_product_id['volume']).sum()
                    elif has_volume:
                        avgprice = (df_product_id['avg_price'] *
                                    df_product_id['volume']
                                    ).sum() / df_product_id['volume'].sum()
                    else:
                        avgprice = df_product_id['avg_price'].mean()

                    # total_price = list()
                    # total_volume = list()
                    # if df_product_id.count():
                    #     if df_product_id.filter(volume__isnull=False).count() / df_product_id.count() > 0.8:
                    #         for q in df_product_id:
                    #             total_price.append(q.avg_price * q.volume)
                    #             total_volume.append(q.volume)
                    #             avgprice = sum(total_price) / sum(total_volume) if len(total_volume) else 0
                    #     else:
                    #         for q in df_product_id:
                    #             total_price.append(q.avg_price)
                    #             avgprice = sum(total_price) / len(total_price) if len(total_price) else 0
                    # else:
                    #     avgprice = 'nan'
                    self.result_data[str(product_id)][str(y)].append(
                        float(
                            Context(prec=28,
                                    rounding=ROUND_HALF_UP).create_decimal(
                                        avgprice)))

        return self.result_data
예제 #7
0
def area_proportion(convert_target, full_size):
    new_convert_target = convert_target*100
    result = Context(prec=3, rounding=ROUND_HALF_UP).create_decimal((new_convert_target*100)/full_size)
    return result