def main():
    logging.basicConfig(level=logging.INFO, format='%(message)s')

    parser = argparse.ArgumentParser(description='Inspect price distributions')
    parser.add_argument('prefix', help='Directory containing json files')
    parser.add_argument('facet', help='Facet', choices=['age', 'none'])
    args = parser.parse_args()

    logging.info('Loading products...')
    product_by_id = load_items(os.path.join(args.prefix, 'product.json'),
                               'product_id')
    logging.info('Loading users...')
    user_by_id = load_items(os.path.join(args.prefix, 'user.json'),
                            'user_id')

    print '"facet","price"'
    with open(os.path.join(args.prefix, 'review.json')) as f:
        for line in f:
            review = json.loads(line)
            product = product_by_id[review['product_id']]
            price = get_price(product)
            if not price:
                continue

            user = user_by_id[review['user_id']]
            fct = facet(review, product, user, args.facet)
            if not fct:
                continue

            print '"{0}","{1}"'.format(fct, price)
示例#2
0
    def calculate(self, start_td, end_td):
        cost_sum, unit_volum, start_td, end_td = self.start_passive_invest(
            start_td, end_td, 30.4)

        if cost_sum == 0 or start_td == end_td:
            return {'Gain ratio': 0, 'Ann ret': 0,
                    'Start time': start_td, 'Inv period': 0,
                    'Unit vol': 0}

        current_price = get_price(self.df, end_td.strftime('%Y-%m-%d'))
        time_delta = end_td-start_td
        period_y = time_delta.days/365
        current_total_value = unit_volum*current_price
        gain_ratio = (current_total_value-cost_sum)/cost_sum
        annualized_return = ((1+gain_ratio)**(1/period_y))-1

        return {'Gain ratio': gain_ratio, 'Ann ret': annualized_return,
                'Start time': start_td, 'Inv period': period_y,
                'Unit vol': unit_volum}
示例#3
0
def is_valid_product(product):
    if 'price' not in product or not product['price']:
        return False

    price = get_price(product)
    if not price:
        return False
    product['price'] = price

    if 'description' not in product or not product['description']:
        return False

    description = u' '.join(product['description'])
    if INVALID_DESCRIPTION_SNIPPET in description:
        return False

    if ('categories' in product and
            INVALID_CATEGORIES.intersection(product['categories'])):
        return False

    # TODO: remove food (e.g. 'サプリメント・フード')

    return True