示例#1
0
def one_day_deal_area():
    pipeline = [{
        '$match': {
            '$and': [{
                'pub_date': {
                    '$gte': '2016.06.25',
                    '$lte': '2016.06.26'
                }
            }, {
                'saled': '1'
            }]
        }
    }, {
        '$group': {
            '_id': {
                '$slice': ['$area', 1, 1]
            },
            'counts': {
                '$sum': 1
            }
        }
    }, {
        '$sort': {
            'counts': 1
        }
    }, {
        '$limit': 7
    }]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {'name': i['_id'][0], 'y': i['counts']}
        yield data
示例#2
0
def total_post():
    # 条件
    pipeline = [
        {
            '$group': {
                '_id': {
                    '$slice': ['$cates', 0, 1]
                },
                'counts': {
                    '$sum': 1
                }
            }
        },
        {
            '$sort': {
                'counts': -1
            }
        },  # 倒序
        {
            '$limit': 6
        }
    ]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        print(i)
        data = {
            'name': i['_id'][0],  # 类名
            'y': i['counts']  # 数量
        }
        yield data
示例#3
0
def topx(date1, date2, area, limit):

    pipeline = [{
        '$match': {
            '$and': [{
                'publish_time': {
                    '$gte': date1,
                    '$lte': date2
                }
            }, {
                'area': area
            }]
        }
    }, {
        '$group': {
            '_id': "$type",
            'counts': {
                '$sum': 1
            }
        }
    }, {
        '$limit': limit
    }, {
        '$sort': {
            'counts': -1
        }
    }]
    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {'name': i['_id'], 'data': [i['counts']], 'type': 'column'}
        yield data
示例#4
0
def one_day_deal_cate():
    pipeline = [{
        '$match': {
            '$and': [{
                'pub_date': {
                    '$gte': '2015.12.25',
                    '$lte': '2016.01.11'
                }
            }, {
                'time': 1
            }]
        }
    }, {
        '$group': {
            '_id': {
                '$slice': ['$cates', 2, 1]
            },
            'counts': {
                '$sum': 1
            }
        }
    }, {
        '$sort': {
            'counts': 1
        }
    }]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {'name': i['_id'][0], 'y': i['counts']}
        yield data
示例#5
0
def total_post():
    pipeline = [
        {'$group':{'_id':{'$slice':['$cates',2,1]},'counts':{'$sum':1}}},
    ]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {
            'name':i['_id'][0],
            'y':i['counts']
        }
        yield data
示例#6
0
def total_post():
    pipeline = [
        {'$group': {'_id': {'$slice': ['$cates', 2, 1]}, 'counts': {'$sum': 1}}},
    ]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {
            'name': i['_id'][0],
            'y': i['counts']
        }
        yield data
示例#7
0
def total_post():
    pipeline = [
                {'$group':{'_id': "$type",'counts':{'$sum':1}}},
                {'$sort': {'counts': -1}},
                {'$limit': 15}
    ]
    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = [
            i['_id'], i['counts']
        ]
        yield data
示例#8
0
def one_day_deal_area():
    pipeline = [
        {'$match':{'$and':[{'pub_date':{'$gte':'2015.12.25','$lte':'2016.01.11'}},{'time':1}]}},
        {'$group':{'_id':{'$slice':['$area',1]},'counts':{'$sum':1}}},
        {'$sort':{'counts':1}}
    ]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {
            'name':i['_id'][0],
            'y':i['counts']
        }
        yield data
示例#9
0
def topx(date1, date2, area, limit):

    pipeline = [
        {'$match': {'$and':[{'publish_time':{'$gte': date1,'$lte': date2}},{'area': area}]}},
        {'$group':{'_id': "$type",'counts':{'$sum':1}}},
        {'$limit':limit},
        {'$sort':{'counts':-1}}
    ]
    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {
            'name': i['_id'],
            'data': [i['counts']],
            'type': 'column'
        }
        yield data
示例#10
0
def total_post():
    pipeline = [{
        '$group': {
            '_id': "$type",
            'counts': {
                '$sum': 1
            }
        }
    }, {
        '$sort': {
            'counts': -1
        }
    }, {
        '$limit': 15
    }]
    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = [i['_id'], i['counts']]
        yield data
示例#11
0
def topx(date1, date2, area, limit):

    pipeline = [
        {
            '$match': {
                '$and': [{
                    'pub_date': {
                        '$gte': date1,
                        '$lte': date2
                    }
                }, {
                    'area': {
                        '$all': area
                    }
                }]
            }
        },  # 发帖日期区间*地区
        {
            '$group': {
                '_id': {
                    '$slice': ['$cates', 0, 1]
                },
                'counts': {
                    '$sum': 1
                }
            }
        },  # 以商品的类名进行分组 并计总量
        {
            '$limit': limit
        },  # 前几名
        {
            '$sort': {
                'counts': -1
            }
        }  # 倒序排列
    ]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {
            'name': i['_id'][0],  # 类目名
            'data': [i['counts']],  # 发帖量
            'type': 'column'  # 柱状
        }
        yield data  # 迭代生成数据
示例#12
0
def topx(date1, date2, area, limit):
    options = {
        'chart': {'zoomType': 'xy'},
        'title': {'text': '发贴数量最大的类目'},
        'subtitle': {'text': '数据图表'},
        'yAxis': {'title': {'text': '数量'}}
    }
    pipeline = [
        {'$match': {'$and': [{'pub_date': {'$gte': date1, '$lte': date2}}, {'area': {'$all': area}}]}},
        {'$group': {'_id': {'$slice': ['$cates', 2, 1]}, 'counts': {'$sum': 1}}},
        {'$limit': limit},
        {'$sort': {'counts': -1}}
    ]

    for i in ItemInfo._get_collection().aggregate(pipeline):
        data = {
            'name': i['_id'][0],
            'data': [i['counts']],
            'type': 'column'
        }
        yield data