123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import requests
- import random
- import json
- import time
- import threading
- class MyThread(threading.Thread):
- def __init__(self, func, args, name=''):
- threading.Thread.__init__(self)
- self.name = name
- self.func = func
- self.args = args
- def run(self):
- self.result = self.func(self.args)
- def get_result(self):
- try:
- return self.result
- except Exception:
- return None
- url = 'http://106.14.187.241:5555/elab-marketing-user//zhidi/activity/concurrent/turntableActivity'
- headers_2 = {'content-type': "application/json", 'Authorization': 'APP appid = 4abf1a,token = 9480295ab2e2eddb8',
- 'dsNo': 'source2'}
- def loop(nloop):
- response = requests.post(url, json=nloop, headers=headers_2)
- return response.text
- def main():
- result_list = []
- threads = []
- people = 200
- times = range(people)
- for i in times:
- params = {
- "actionType": 1,
- "activityId": 8939,
- "brandId": 1,
- "customerId": 223222 + random.randint(5000, 9000),
- "houseId": 10110,
- "mobile": "15622363" + str(random.randint(1000, 9999)),
- "shareActivityId": 0,
- "uuid": ""
- }
- t = MyThread(loop, params, ' 第' + str(i + range(i + 1)[0]) + '线程')
- threads.append(t)
- for i in range(people):
- threads[i].start()
- for i in range(people):
- threads[i].join()
- result = threads[i].get_result()
- result_list.append(json.loads(result))
- return result_list
- def analysis_result(result_list):
-
- dict_data = {}
-
- prize_count = 0
-
- think_prize = 0
-
- failed_prize = 0
- for x in result_list:
- success = x['success']
- if success is True:
-
- single = x['single']
- name = single['name']
- if name in dict_data.keys():
- count = dict_data[name]
- dict_data[name] = count + 1
- else:
- dict_data[name] = 1
- thinks = single['thinks']
- if str(thinks) == str(1):
- think_prize += 1
- else:
- prize_count += 1
- else:
-
- failed_prize += 1
- all = prize_count + think_prize
- for key in dict_data.keys():
- count = dict_data[key]
- if all > 0:
- print(key + ': ' + str(count), ",占比: " + str(count/all))
- else:
- print(key + ': ' + str(count))
- print('------------,参与抽奖人数:' + str(all))
- print("中奖:" + str(prize_count), ",中奖率:" + str(prize_count / all))
- print("谢谢参与; " + str(think_prize), ",谢谢参与率: " + str(think_prize / all))
-
- if __name__ == '__main__':
- result = main()
- analysis_result(result)
|