예제 #1
0
파일: eir032.py 프로젝트: travishen/aprp
    def hook(self, dic):

        for key, value in dic.items():
            if isinstance(value, str):
                dic[key] = value.strip()

        product_code = dic.get('品種代碼')
        product = self.PRODUCT_QS.filter(code=product_code).first()
        source_name = dic.get('市場名稱')
        source = self.SOURCE_QS.filter_by_name(source_name).first()
        if product and source:
            tran = DailyTran(
                product=product,
                source=source,
                up_price=dic.get('上價'),
                mid_price=dic.get('中價'),
                low_price=dic.get('下價'),
                avg_price=dic.get('平均價'),
                volume=dic.get('交易量'),
                date=date_transfer(sep=self.SEP, string=dic.get('交易日期'), roc_format=self.ROC_FORMAT)
            )
            return tran
        else:
            if not product:
                self.LOGGER.warning('Cannot Match Product: "%s" In Dictionary %s'
                                    % (product_code, dic), extra=self.LOGGER_EXTRA)
            if not source:
                self.LOGGER.warning('Cannot Match Source: "%s" In Dictionary %s'
                                    % (source_name, dic), extra=self.LOGGER_EXTRA)
            return dic
예제 #2
0
    def hook(self, dic):

        for key, value in dic.items():
            if isinstance(value, str):
                dic[key] = value.strip()

        product_code = dic.get('item')
        product = self.PRODUCT_QS.filter(code=product_code).first()

        if product:
            tran = DailyTran(product=product,
                             avg_price=dic.get('price'),
                             avg_weight=dic.get('weight'),
                             volume=dic.get('volume'),
                             date=date_transfer(sep=self.SEP,
                                                string=dic.get('date'),
                                                roc_format=self.ROC_FORMAT))
            return tran
        else:
            if not product:
                self.LOGGER.warning(
                    'Cannot Match Product: "%s" In Dictionary %s' %
                    (product_code, dic),
                    extra=self.LOGGER_EXTRA)
            return dic
예제 #3
0
파일: rice_avg.py 프로젝트: travishen/aprp
        def create_tran(obj):
            tran = DailyTran(product=obj,
                             avg_price=dic.get(obj.code),
                             date=date_transfer(sep=self.SEP,
                                                string=dic.get('pt_date'),
                                                roc_format=self.ROC_FORMAT))

            # NOTE: wholesale obj price need to division by 100
            if obj.code in [
                    'pt_2japt', 'pt_2tsait', 'pt_2sangt', 'pt_2glutrt',
                    'pt_2glutlt', 'pt_4japt', 'pt_4tsait', 'pt_4sangt',
                    'pt_4glutrt', 'pt_4glutlt'
            ]:
                tran.avg_price = tran.avg_price / 100

            return tran
예제 #4
0
    def hook2(self, dic):
        for key, value in dic.items():
            if isinstance(value, str):
                dic[key] = value.strip()

        product_name = "青香蕉下品(內銷)"
        source_name = dic.get('ORGNAME')
        product = self.PRODUCT_QS.filter(code=product_name).first()
        source = self.SOURCE_QS.filter(name=source_name).first()
        if product and source:
            tran = DailyTran(product=product,
                             source=source,
                             avg_price=float(dic.get('AVGPRICE')),
                             date=date_transfer(sep=self.SEP,
                                                string=dic.get('PERIOD'),
                                                roc_format=self.ROC_FORMAT))
            return tran
        else:
            if product_name and not product:
                self.LOGGER.warning('Cannot Match Product: %s' %
                                    (product_name),
                                    extra=self.LOGGER_EXTRA)
            if source_name and source_name != '當日平均價' and not source:
                self.LOGGER.warning('Cannot Match Source: %s' % (source_name),
                                    extra=self.LOGGER_EXTRA)
            return dic
예제 #5
0
    def hook(self, dic):

        for key, value in dic.items():
            if isinstance(value, str):
                dic[key] = value.strip()

        product_code = dic.get('productID')
        product = self.PRODUCT_QS.filter(code=product_code).first()
        source_name = dic.get('shortName')
        source = self.SOURCE_QS.filter_by_name(source_name).first()
        if product and source:
            tran = DailyTran(product=product,
                             source=source,
                             avg_price=dic.get('avgPrice'),
                             avg_weight=dic.get('avgWeight'),
                             volume=dic.get('quantity'),
                             date=date_transfer(sep=self.SEP,
                                                string=dic.get('transDate'),
                                                roc_format=self.ROC_FORMAT))
            return tran
        else:
            if not product:
                self.LOGGER.warning(
                    'Cannot Match Product: "%s" In Dictionary %s' %
                    (product_code, dic),
                    extra=self.LOGGER_EXTRA)
            if not source:
                self.LOGGER.warning(
                    'Cannot Match Source: "%s" In Dictionary %s' %
                    (source_name, dic),
                    extra=self.LOGGER_EXTRA)
            return dic
예제 #6
0
파일: eir049.py 프로젝트: MatsuiLin101/aprp
 def create_tran(obj):
     tran = DailyTran(
         product=obj,
         avg_price=float(dic.get(obj.code)) / 0.6,
         date=date_transfer(sep=self.SEP, string=dic.get('日期'), roc_format=self.ROC_FORMAT)
     )
     return tran
예제 #7
0
파일: efish.py 프로젝트: MatsuiLin101/aprp
 def create_tran(obj):
     code = obj.code
     tran = DailyTran(
         product=obj,
         avg_price=float(dic.get(code).replace(',', '')),
         date=date_transfer(sep=self.SEP, string=dic.get('date'), roc_format=self.ROC_FORMAT)
     )
     return tran
예제 #8
0
        def create_tran(obj, source):
            code = obj.code
            volume_column = self.COLUMN_SEP.join((code, self.VOLUME_COLUMN))
            avg_weight_column = self.COLUMN_SEP.join(
                (code, self.AVG_WEIGHT_COLUMN))
            avg_price_column = self.COLUMN_SEP.join(
                (code, self.AVG_PRICE_COLUMN))
            tran = DailyTran(product=obj,
                             source=source,
                             volume=dic.get(volume_column),
                             avg_weight=dic.get(avg_weight_column),
                             avg_price=float(dic.get(avg_price_column)),
                             date=date_transfer(sep=self.SEP,
                                                string=dic.get('交易日期'),
                                                roc_format=True))

            return tran
예제 #9
0
파일: apis.py 프로젝트: COAStatistics/aprp
    def hook3(self, dic):
        for key, value in dic.items():
            if isinstance(value, str):
                dic[key] = value.strip()

        product_name = "蒜頭(蒜球)(旬價)"
        source_name = dic.get('ORGNAME')
        YEAR = dic.get('YEAR')
        MONTH = dic.get('MONTH')
        PERIOD = dic.get('PERIOD')
        if PERIOD == None:
            pass
        elif '上旬' in PERIOD:
            PERIOD = '05'
        elif '中旬' in PERIOD:
            PERIOD = '15'
        elif '下旬' in PERIOD:
            PERIOD = '25'

        if PERIOD == None:
            pass
        else:
            date = f'{YEAR}/{MONTH}/{PERIOD}'

        product = self.PRODUCT_QS.filter(code=product_name).first()
        source = self.SOURCE_QS.filter(name=source_name).first()
        if product and source:
            tran = DailyTran(product=product,
                             source=source,
                             avg_price=float(dic.get('AVGPRICE')),
                             date=date_transfer(sep=self.SEP,
                                                string=date,
                                                roc_format=self.ROC_FORMAT))
            return tran
        else:
            if product_name and not product:
                self.LOGGER.warning('Cannot Match Product: %s' %
                                    (product_name),
                                    extra=self.LOGGER_EXTRA)
            if source_name and not source:
                self.LOGGER.warning('Cannot Match Source: %s' % (source_name),
                                    extra=self.LOGGER_EXTRA)
            return dic
예제 #10
0
파일: amis.py 프로젝트: taiwang1209/aprp
    def hook(self, dic):
        for key, value in dic.items():
            if isinstance(value, str):
                dic[key] = value.strip()

        source_code = dic.get('MarketNo')
        source = self.SOURCE_QS.filter(code=source_code).first()
        date = date_transfer(sep=self.SEP,
                             string=dic.get('TransDate'),
                             roc_format=self.ROC_FORMAT)
        products = dic.get('Detail')
        if source and products:
            trans = []
            # sum detail object and translate to "one" DailyTran
            if self.sum_to_product:

                def sum_details(lst):
                    sum_avg_price = 0
                    sum_volume = 0
                    for dic in lst:
                        avg_price = float(dic.get('AvgPrice'))
                        volume = float(dic.get('TransVolume'))
                        sum_avg_price += avg_price * volume
                        sum_volume += volume
                    return sum_avg_price / sum_volume, sum_volume

                product_code = self.sum_to_product
                product = self.PRODUCT_QS.filter(code=product_code).first()
                if product:
                    avg_price, sum_volume = sum_details(products)
                    tran = DailyTran(
                        product=product,
                        source=source,
                        avg_price=avg_price,
                        volume=sum_volume,
                        date=date,
                    )
                    trans.append(tran)
                else:
                    self.LOGGER.warning(
                        'Cannot Match Product: "%s" In Dictionary %s' %
                        (product_code, dic),
                        extra=self.LOGGER_EXTRA)

            else:
                # translate detail objects to "multi" DailyTran
                for dic in products:
                    product_code = dic.get('ProductNo')
                    product = self.PRODUCT_QS.filter(code=product_code).first()
                    if product:
                        tran = DailyTran(
                            product=product,
                            source=source,
                            avg_price=float(dic.get('AvgPrice')),
                            volume=float(dic.get('TransVolume')),
                            date=date,
                        )
                        trans.append(tran)
                    else:
                        self.LOGGER.warning(
                            'Cannot Match Product: "%s" In Dictionary %s' %
                            (product_code, dic),
                            extra=self.LOGGER_EXTRA)

            return trans

        if products and not source:
            self.LOGGER.warning('Cannot Match Source: "%s" In Dictionary %s' %
                                (source_code, dic),
                                extra=self.LOGGER_EXTRA)
            return dic

        else:
            return dic