Subversion Repositories SmartDukaan

Rev

Rev 19362 | Rev 19390 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19362 Rev 19389
Line 2690... Line 2690...
2690
            specialOffer = promo.__dict__
2690
            specialOffer = promo.__dict__
2691
    except:
2691
    except:
2692
        pass
2692
        pass
2693
    return specialOffer
2693
    return specialOffer
2694
 
2694
 
-
 
2695
def getBrandSubCategoryInfo(category_id, id_list, type):
-
 
2696
    if mc.get("brandSubCategoryInfo") is None:
-
 
2697
        collection =  get_mongo_connection().Catalog.Deals
-
 
2698
        result = collection.aggregate( 
-
 
2699
                [
-
 
2700
                    {'$match':{'category_id':category_id,'showDeal':1}},
-
 
2701
                    {"$group": { "_id": { "subCategoryId": "$subCategoryId", "brand_id": "$brand_id", "brand":"$brand","subCategory":"$subCategory" }, "count": {"$sum": 1} } }
-
 
2702
                ]
-
 
2703
            );
-
 
2704
        from pprint import pprint
-
 
2705
        pprint(result)
-
 
2706
        
-
 
2707
        subCategoryMap = {}
-
 
2708
        brandMap = {}
-
 
2709
        
-
 
2710
        for data in result['result']:
-
 
2711
            result_set = data['_id']
-
 
2712
            count = data['count']
-
 
2713
            subCategoryId = result_set['subCategoryId']
-
 
2714
            brand_id = result_set['brand_id']
-
 
2715
            subCategory = result_set['subCategory']
-
 
2716
            brand = result_set['brand']
-
 
2717
             
-
 
2718
            if subCategoryMap.has_key(subCategoryId):
-
 
2719
                subCategoryMap.get(subCategoryId).append({'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand})
-
 
2720
            else:
-
 
2721
                subCategoryMap[subCategoryId] = [{'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand}]
-
 
2722
                
-
 
2723
            if brandMap.has_key(brand_id):
-
 
2724
                brandMap.get(brand_id).append({'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand})
-
 
2725
            else:
-
 
2726
                brandMap[brand_id] = [{'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand}]
-
 
2727
        
-
 
2728
        mc.set("brandSubCategoryInfo",{'subCategoryMap':subCategoryMap, 'brandMap': brandMap}, 600)
-
 
2729
    
-
 
2730
    
-
 
2731
    returnMap = {}    
-
 
2732
    brandSubCategoryInfo = mc.get("brandSubCategoryInfo")
-
 
2733
    if brandSubCategoryInfo is None:
-
 
2734
        return []
-
 
2735
    
-
 
2736
    if type == "subCategoryInfo":
-
 
2737
        if brandSubCategoryInfo.get('subCategoryMap') is None:
-
 
2738
            return []
-
 
2739
        subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
-
 
2740
        subCategoryMap = brandSubCategoryInfo.get('subCategoryMap')
-
 
2741
        for subCategory in subCategories:
-
 
2742
            tempList = subCategoryMap.get(subCategory)
-
 
2743
            print tempList
-
 
2744
            if tempList is None:
-
 
2745
                continue
-
 
2746
            for v in tempList:
-
 
2747
                if returnMap.has_key(v['brand_id']):
-
 
2748
                    existing = returnMap.get(v['brand_id'])
-
 
2749
                    existing['count'] = existing['count'] + v['count'] 
-
 
2750
                else:
-
 
2751
                    returnMap[v['brand_id']] = {'brand_id':v['brand_id'],'brand':v['brand'],'count':v['count']}
-
 
2752
            
-
 
2753
            
-
 
2754
    elif type == "brandInfo":
-
 
2755
        if brandSubCategoryInfo.get('brandMap') is None:
-
 
2756
            return []
-
 
2757
        brands = [int(brand_id) for brand_id in id_list.split('^')]
-
 
2758
        brandMap = brandSubCategoryInfo.get('brandMap')
-
 
2759
        for brand_id in brands:
-
 
2760
            tempList = brandMap.get(brand_id)
-
 
2761
            print tempList
-
 
2762
            if tempList is None:
-
 
2763
                continue
-
 
2764
            for v in tempList:
-
 
2765
                if returnMap.has_key(v['subCategoryId']):
-
 
2766
                    existing = returnMap.get(v['subCategoryId'])
-
 
2767
                    existing['count'] = existing['count'] + v['count'] 
-
 
2768
                else:
-
 
2769
                    returnMap[v['brand_id']] = {'subCategoryId':v['subCategoryId'],'subCategory':v['subCategory'],'count':v['count']}
-
 
2770
    
-
 
2771
    return returnMap.values()
-
 
2772
 
2695
            
2773
            
2696
def main():
2774
def main():
2697
    getDealsForSearchText("20", 'Samsung', 0, 10)
2775
    #getDealsForSearchText("20", 'Samsung', 0, 10)
-
 
2776
   
-
 
2777
    x = getBrandSubCategoryInfo(6,"15^17","subCategoryInfo")
-
 
2778
    print "==============="
-
 
2779
    print x
2698
    
2780
    
2699
if __name__=='__main__':
2781
if __name__=='__main__':
2700
    main()
2782
    main()
2701
 
2783
 
2702
 
2784