123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- # -*- coding: utf-8 -*-
- #!/usr/bin/env python
- import os
- import sys
- import datetime
- PROJECT_ROOT = os.path.join(os.path.abspath(os.path.split(os.path.realpath(__file__))[0] + "/.."), '..')
- sys.path.insert(0, PROJECT_ROOT)
- os.environ.update({"DJANGO_SETTINGS_MODULE": "configs.production"})
- import django
- django.setup()
- from apilib.utils_datetime import to_datetime
- from apps.web.constant import Const
- from apps.web.device.models import Device
- from apps.web.dealer.models import DealerRechargeRecord
- # 统计东郡的经销商数据,按照设备量的大小,从高统计
- import pymongo
- client=pymongo.MongoClient(host='211.159.224.10',port=27119,username = 'dba',password = 'dayuan@2020..') #连接本地的服务端
- db=client.spider #指定操作的数据库
- collection=db.dongjun_devices #指定操作的集合
- # 遍历设备,并登记到经销商
- dealerDict = {}
- devs = collection.find({'createDate':{'$gte':1596211200000}})
- devList = []
- for dev in devs:
- devList.append(dev)
- for dev in devList:
- tel = dev.get('contactMobilePhone','')
- if tel not in dealerDict:
- dealerDict[tel] = {'count':1,'cityName':dev.get('cityName',''),'typeName':dev.get('equipTypeName',''),'name':dev.get('name','')}
- else:
- dealerDict[tel]['count'] += 1
- dealerList = [(k,v['count'],v['cityName'],v['typeName'],v['name']) for k,v in dealerDict.items()]
- def cmp_xy(x,y):
- if x[1] < y[1]:
- return -1
- elif x[1] == y[1]:
- return 0
- return 1
- dealerList.sort(cmp=cmp_xy, reverse=True)
- for dealer in dealerList[0:100000]:
- print dealer[0],dealer[1],dealer[2],dealer[3],dealer[4]
-
|