123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- # coding=utf-8
- import os
- from base import init_env
- os.environ.update({"DJANGO_SETTINGS_MODULE": "configs.dev_zjl"})
- init_env(False)
- from random import randint, choice
- from faker import Faker
- from apps.web.common.proxy import ClientRechargeModelProxy, ClientConsumeModelProxy, ClientDealerIncomeModelProxy, \
- DealerDailyStatsModelProxy
- from concurrent.futures import ThreadPoolExecutor, as_completed
- def task1(name, startTime, endTime):
- try:
- record = ClientConsumeModelProxy.get_one(startTime, endTime)
- up = True
- if record:
- pass
- # up = record.update(nickname=name)
- except Exception as e:
- print e
- up = False
- return bool(up)
- def task2(name, startTime, endTime):
- try:
- record = ClientDealerIncomeModelProxy.get_one(startTime, endTime)
- up = True
- if record:
- pass
- # up = record.update(title=name)
- except Exception as e:
- print e
- up = False
- return bool(up)
- def task3(name, startTime, endTime):
- try:
- record = DealerDailyStatsModelProxy.get_one(startTime, endTime)
- up = True
- if record:
- pass
- except Exception as e:
- print e
- up = False
- return bool(up)
- def task4(name, startTime, endTime):
- try:
- record = ClientRechargeModelProxy.get_one(startTime, endTime)
- up = True
- if record:
- pass
- # up = record.update(nickname=name)
- except Exception as e:
- print e
- up = False
- return bool(up)
- def call_back(future):
- pass
- def get_st_and_et():
- year = randint(2017, 2020)
- month = randint(1, 12)
- day = randint(1, 28)
- # 当 time 是str的时候好像由 datetime 的作用域乱掉了
- timeStr = "{}-{:02}-{:02}".format(year, month, day)
- return timeStr, timeStr
- def main():
- TEST_DATA_NUMBER = 10000 # 测试的数据条目
- TEST_WORKER = 20 # 测试数据的worker
- nameList = [Faker(locale='zh_CN').name() for i in range(100)]
- timeList = [get_st_and_et() for i in range(1000)]
- executor = ThreadPoolExecutor(max_workers=TEST_WORKER)
- futures = [executor.submit(choice([task1, task2, task3, task4]), choice(nameList), *choice(timeList)).add_done_callback(call_back) for i in range(TEST_DATA_NUMBER)]
- as_completed(futures)
- executor.shutdown(wait=True)
- if __name__ == '__main__':
- main()
|