brandAndBrandNameTest.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding=utf-8
  2. '''
  3. Created on 2016年3月30日
  4. 因为有2个属性brand商标、brandName商标名,统计一下出现的规则
  5. @author: ChenHao
  6. '''
  7. '''
  8. 结果:
  9. 2696 2541 0 155 0
  10. 2696条有效测试数据中
  11. 每个器件都有brand属性
  12. 极少的器件带有brandName属性
  13. '''
  14. from util_common import Constant
  15. from pymongo.mongo_client import MongoClient
  16. # cli = MongoClient(Constant.MONGODB_URL)
  17. cli = MongoClient("mongodb://localhost:27017/")
  18. db = cli.spider
  19. count_ava = 0
  20. count_hasBrand = 0;
  21. count_hasBrandName = 0;
  22. count_hasBoth = 0;
  23. count_hasNone = 0;
  24. for i in range(1, 2697):
  25. rs = db.propertyvalue.find({"componentid": i})
  26. if rs.count() > 0:
  27. count_ava += 1
  28. hasBrand = False
  29. hasBrandName = False
  30. for r in rs:
  31. if r["propertyid"] == 40:
  32. hasBrand = True
  33. if r["propertyid"] == 25:
  34. hasBrandName = True
  35. if hasBrand:
  36. if hasBrandName:
  37. count_hasBoth += 1
  38. else:
  39. count_hasBrand += 1
  40. else:
  41. if hasBrandName:
  42. count_hasBrandName += 1
  43. else:
  44. count_hasNone += 1
  45. print (count_ava, count_hasBrand, count_hasBrandName, count_hasBoth, count_hasNone)
  46. cli.close()