import time

import uiautomator2 as u2

from utils.utils import UiFactory

# 连接到设备，默认连接第一个设备，如果有多个设备可以指定序列号
ui = UiFactory('emulator-5554')
# 从配置中加载坐标
# 执行deepcoin_point.py 文件进行采集。
ui.load_point("deepcion_point.json")

is_start = ui.check_app_running("com.niocpeed.dna")
# tab 交易按钮
# btn_jy = ui.xpath("btn_jy")
#
# if is_start:
#     print("点击交易")
#     btn_jy.click()

# 设置委托
input_weituo = ui.xpath("input_weituo")
# 设置数量
input_num = ui.xpath('input_num')

# # 设置数量
# btn_ping = ui.xpath('btn_ping')

# start1 = time.time()
# input_num.clear()
# end1 = time.time()
# print("清空数量：操作耗时：", end1 - start1)
# start1 = time.time()
# input_num.text("41")
# end1 = time.time()
# print("设置数量：操作耗时：", end1 - start1)
#
btn_buy = ui.desc("btn_buy")
#
# start1 = time.time()
# input_weituo.click()
# end1 = time.time()
# print("点击：最优委托 操作耗时：", end1 - start1)

# start1 = time.time()
# btn_ping.click()
# end1 = time.time()
# print("点击：平仓 操作耗时：", end1 - start1)
#
for i in range(10):
    # 初始化点击按钮
    start = time.time()
    # start1 = time.time()
    # input_weituo.click()
    # end1 = time.time()
    # print("点击：最优委托 操作耗时：", end1 - start1)
    #
    # # start1 = time.time()
    # # input_weituo.set_text("0.114")
    # # end1 = time.time()
    # # print("设置：操作耗时：", end1 - start1)
    # start1 = time.time()
    # input_num.click()
    # end1 = time.time()
    # print("点击：操作耗时：", end1 - start1)
    # start1 = time.time()
    # input_num.set_text("40")
    # end1 = time.time()
    # print("设置：操作耗时：", end1 - start1)
    start1 = time.time()
    btn_buy.click()
    end1 = time.time()
    print("点击下单：操作耗时：", end1 - start1)
    end = time.time()
    # print("点击整体：操作耗时：", end - start)
    time.sleep(5)
