Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. def get_scatter(doc_type_name = "business"):
  2. answer = [[],[],[]]
  3. answer[0].append('Rating')
  4. answer[1].append('No. of Reviews')
  5. index_name = "content_engine_business"
  6. stars = [1.0,2.0,3.0,4.0,5.0]
  7. for k in range(len(stars)):
  8. temp =[]
  9. my_body={
  10. 'query' : {
  11. 'bool': {
  12. "must": [
  13. {"match" : {"stars":stars[k]}}
  14. ]
  15. }
  16. }
  17. }
  18. sample = es.search(index = index_name, body = my_body,size=5000)
  19. if sample['hits']['total'] > 5000:
  20. length = 5000
  21. else:
  22. length = sample['hits']['total']
  23. for el in sample['hits']['hits'][:1000]:
  24. random = el['_source']['review_count']
  25. name = el['_source']['name']
  26. answer[0].append(stars[k])
  27. answer[1].append(random)
  28. answer[2].append(name)
  29. return answer
  30.  
  31. def get_scatter_city(statename, doc_type_name = "business"):
  32. answer = [[],[],[]]
  33. answer[0].append('Rating')
  34. answer[1].append('No. of Reviews')
  35. index_name = "content_engine_business"
  36. stars = [1.0,2.0,3.0,4.0,5.0]
  37. for k in range(len(stars)):
  38. temp =[]
  39. my_body={
  40. 'query' : {
  41. 'bool': {
  42. "must": [
  43. {"match" : {"stars":stars[k]}},
  44. {"match" : {"state": statename}}
  45. ]
  46. }
  47. }
  48. }
  49. sample = es.search(index = index_name, body = my_body,size=10000)
  50. if sample['hits']['total'] > 10000:
  51. length = 10000
  52. else:
  53. length = sample['hits']['total']
  54. for el in sample['hits']['hits'][:1000]:
  55. random = el['_source']['review_count']
  56. name = el['_source']['name']
  57. answer[0].append(stars[k])
  58. answer[1].append(random)
  59. answer[2].append(name)
  60. return answer
  61.  
  62. def get_scatter_city_category(statename, category, doc_type_name = "business"):
  63. answer = [[],[],[]]
  64. answer[0].append('Rating')
  65. answer[1].append('No. of Reviews')
  66. index_name = "content_engine_business"
  67. stars = [1.0,2.0,3.0,4.0,5.0]
  68. if category == "misc":
  69. for k in range(len(stars)):
  70. temp =[]
  71. total_count = 0
  72. for l in range(len(misc)):
  73. my_body={
  74. 'query' : {
  75. 'bool': {
  76. "must": [
  77. {"match" : {"stars":stars[k]}},
  78. {"match" : {"state": statename}},
  79. {"match" : {"categories" : misc[l]}}
  80. ]
  81. }
  82. }
  83. }
  84. sample = es.search(index = index_name, body = my_body,size=10000)
  85. if sample['hits']['total'] > 10000:
  86. length = 10000
  87. else:
  88. length = sample['hits']['total']
  89. for el in sample['hits']['hits'][:1000]:
  90. random = el['_source']['review_count']
  91. name = el['_source']['name']
  92. answer[0].append(stars[k])
  93. answer[1].append(random)
  94. answer[2].append(name)
  95. else:
  96. for k in range(len(stars)):
  97. temp =[]
  98. my_body={
  99. 'query' : {
  100. 'bool': {
  101. "must": [
  102. {"match" : {"stars":stars[k]}},
  103. {"match" : {"state": statename}},
  104. {"match" : {"categories" : category}}
  105. ]
  106. }
  107. }
  108. }
  109. sample = es.search(index = index_name, body = my_body,size=10000)
  110. if sample['hits']['total'] > 10000:
  111. length = 10000
  112. else:
  113. length = sample['hits']['total']
  114. for el in sample['hits']['hits'][:1000]:
  115. random = el['_source']['review_count']
  116. name = el['_source']['name']
  117. answer[0].append(stars[k])
  118. answer[1].append(random)
  119. answer[2].append(name)
  120.  
  121. print len(answer)
  122. print "3"
  123. return answer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement