Exemple #1
0
    def videoToPhoto(self, dirname, index):
        curPath = os.getcwd()

        if self.machineName == "PACM00":
            print str(curPath) + "-------------"

            srcPath = os.path.join(os.path.dirname(curPath), "Screenshots")
            print srcPath + "1111111111"
            count = 0
            # for filename in os.listdir(srcPath):
            os.chdir(srcPath)

            for root, dirs, files in os.walk(srcPath):  # 遍历统计
                for file in files:
                    print os.path.abspath(file)
                    shutil.copyfile(file, curPath + "/" + str(count) + ".mp4")
                    count += 1
            os.chdir(curPath)

        MLog.info(u"video_operation videoToPhoto:" + '+++++++++++++' + curPath)
        if os.path.isdir(dirname):
            shutil.rmtree(dirname)
        os.makedirs(dirname)
        chagePath = curPath + '/' + dirname
        print '+++++++++++++' + chagePath
        os.chdir(chagePath)
        strcmd = 'ffmpeg -i ' + curPath + '/' + index + '.mp4' + ' -r ' + str(
            50) + ' -f ' + 'image2 %05d.jpg'
        subprocess.call(strcmd, shell=True)
        os.chdir(curPath)
Exemple #2
0
    def screenmain(self):

        MLog.info(u"screen_record_main screenmain: sernum = " + str(self.serNum))
        MLog.info(u"screen_record_main screenmain: "
                  + " firstLaunchTimes = " + str(self.getFirstStartTime())
                  + " notFirstLaunchTimes = " + str(self.getNormalStartTime())
                  + " apkName = " + self.getApkName())
        settings._init()
        try:
            d = u2.connect(self.serNum)
            doInThread(self.registerEvent.runwatch, d, 0)
            time.sleep(10)
            doInThread(self.registerEvent.inputListener, d, 0, self.serNum)
            time.sleep(20)

            if self.getFirstStartTime() > 0:
                if self.method == Constants.autoInstall:  # 自动安装
                    self.firstLaunch()
                elif self.method == Constants.manuelInstall:  # 手动安装
                    self.firstLaunch2()

            self.notFirstLaunch()
            self.enterLiveRoom()
        except BaseException, e:
            MLog.error("BaseException = " + repr(e))
Exemple #3
0
    def notFirstLaunch(self):
        if self.getNormalStartTime() > 0:
            if self.machineName == "PACM00":
                self.fileOperation.removeDirs("/sdcard/DCIM/Screenshots")
                MLog.info(u"删除 screenshot")
                path = os.path.dirname(__file__) + "\\"
                print path
                os.chdir(path)
                if os.path.exists("Screenshots"):
                    shutil.rmtree("Screenshots")

            notfirst_dir = self.tempDir + "_notfirst"
            self.fileOperation.mkdir(notfirst_dir)
            for index in range(int(self.getNormalStartTime())):

                self.appOperation.killProcess()
                self.startApp.startAPP(self.d, 15, notfirst_dir + '/' + str(index) + ".mp4")
                time.sleep(15)
                if self.machineName == "PACM00":
                    os.system('adb -s ' + self.serNum + ' shell service call statusbar 1')
                    self.d(text="停止录屏").click()
            time.sleep(10)
            if self.machineName == "PACM00":
                self.videoOperation.pullRecord("/sdcard/DCIM/Screenshots")
            else:
                self.videoOperation.pullRecord(notfirst_dir)
            path = os.path.abspath('.')
            folder = path + '/' + notfirst_dir
            MLog.debug(u"screen_record_main notFirstLaunch: path = " + path)
            os.chdir(folder)
            self.appOperation.killProcess()
            for index in range(int(self.getNormalStartTime())):
                self.videoOperation.videoToPhoto(str(notfirst_dir + "_" + str(index)), str(index))
            os.chdir(path)
Exemple #4
0
    def enterLiveRoom(self):
        # 启动APP
        self.start()
        time.sleep(15)
        if self.getEnterLiveRoom() > 0:
            if self.machineName == "PACM00":
                self.fileOperation.removeDirs("/sdcard/DCIM/Screenshots")
                MLog.info(u"删除 screenshot")
                path = os.path.dirname(__file__) + "\\"
                MLog.debug(u"screen_record_main enterLiveRoom: path = " + path)
                os.chdir(path)
                if os.path.exists("Screenshots"):
                    shutil.rmtree("Screenshots")

            enter_dir = self.tempDir + "_enterliveroom"
            self.fileOperation.mkdir(enter_dir)
            for index in range(int(self.getEnterLiveRoom())):
                self.startApp.enter(self.d, 10, enter_dir + '/' + str(index) + ".mp4", self.serNum)
                time.sleep(5)
                if self.machineName == "PACM00":
                    os.system('adb -s ' + self.serNum + ' shell service call statusbar 1')
                    self.d(text="停止录屏").click()
            time.sleep(5)
            if self.machineName == "PACM00":
                self.videoOperation.pullRecord("/sdcard/DCIM/Screenshots")
            else:
                self.videoOperation.pullRecord(enter_dir)
            path = os.path.abspath('.')
            folder = path + '/' + enter_dir
            MLog.debug(u"screen_record_main enterLiveRoom: path2 = " + path)
            os.chdir(folder)
            self.appOperation.killProcess()
            for index in range(int(self.getEnterLiveRoom())):
                self.videoOperation.videoToPhoto(str(enter_dir + "_" + str(index)), str(index))
            os.chdir(path)
Exemple #5
0
def create_lines(devices, apk_name):
    MLog.info(
        u"--------------------------开始准备生成折线图---------------------------")
    types = [u"非首次启动总耗时", u"首次启动总耗时", u"进直播间耗时", u"非首次启动闪屏页耗时", u"首次启动闪屏页耗时"]
    apks = [utf8(apk_name)]
    json_file_to_type(types, devices, apks)
    MLog.info(u"--------------------------生成折线图结束---------------------------")
def get_start_params():
    frame = 50
    firstLaunchTimes = 0
    notFirstLaunchTimes = 0
    enterLiveTimes = 1
    apkName = u"yy.apk"
    package = u"com.duowan.mobile"

    try:
        MLog.info(u"sys_config get_start_params: 读取配置文件参数...")
        conf = Config("default.ini")
        frame = conf.getconf("default").frame
        firstLaunchTimes = conf.getconf("default").first_start
        notFirstLaunchTimes = conf.getconf("default").normal_start
        enterLiveTimes = conf.getconf("default").enter_liveroom
        apkName = conf.getconf("default").apk_name
        package = conf.getconf("default").package

    except Exception:
        MLog.error(u"获取参数错误,使用默认值")
        frame = 50
        firstLaunchTimes = 1
        notFirstLaunchTimes = 1
        enterLiveTimes = 1
        apkName = u"yy.apk"
        package = u"com.duowan.mobile"
    finally:
        # start_python 需要运行在init_ffmpeg后面,否则拿不到帧数的值
        MLog.info("apkName = " + str(apkName) + " ,first_start = " \
                  + str(firstLaunchTimes) + " ,normal_start = " + str(notFirstLaunchTimes) + " ,frame = " + str(frame))

    return int(firstLaunchTimes), int(notFirstLaunchTimes), int(
        enterLiveTimes), str(apkName), str(package)
Exemple #7
0
def last_and_launching_frame_find_rgb(length, from_index, real_path, real_launching_feature_path,
                                      real_last_feature_path, rgb_folder):
    launching_homepage_flag = True
    launching_index = -1
    homepage_index = -1
    for i in range(from_index+2, length+1):
        src_file_path = real_path + base_utils.adapter_num(i) + ".jpg"
        feature_name = base_utils.adapter_num(i) + "_feature.jpg"

        if launching_homepage_flag:
            # 进入启动页匹配
            flag = isLaunchingPage(src_file_path, real_launching_feature_path)
            if flag:
                MLog.debug("find_lanching_end_frame: " + src_file_path + " is launching frame")
                continue
            else:
                # 没匹配到,则先记录为启动结束帧,记得往前取一帧
                launching_index = i - 1
                clip_generate_flag(real_path + base_utils.adapter_num(i - 1) + ".jpg",
                                   real_path + base_utils.adapter_num(i - 1) + "_feature.jpg")
                MLog.debug("find_lanching_end_frame: " + src_file_path + " is not launching frame!!!!")
                launching_homepage_flag = False
        else:
            # 首页匹配
            # 取巧操作,取右下角的点,看他是不是纯白,来过滤掉还有蒙层的帧
            if not isHomepageFinish(src_file_path):
                MLog.info("index = {} is not at homepage".format(i))
                continue
            match_img(src_file_path, real_last_feature_path, threshold, real_path + feature_name)
            if base_utils.os.path.exists(real_path + feature_name):
                # 如果识别到了,拿来图片和图库对比,如果当前图片rgb值远大于图库的平均rgb
                # 认为这一帧还在加载中;反之,则认为当前为加载完成帧

                degree = calculate_by_hists(real_last_feature_path, real_path + feature_name)
                print "degree = {}    -----------------------------".format(degree)
                # 这个值是否还可以再调一下?这个值太难取了,有些手机的帧很模糊,有些手机又特别清楚
                if degree < 0.65:
                    continue

                dst_path = real_path + base_utils.adapter_num(i) + "_clip.jpg"
                clip_specific_pic(src_file_path, dst_path)
                if compare_rgb(dst_path, rgb_folder):
                    MLog.debug("the rgb test is passed")
                    if isHomePageLoadFinish(src_file_path, src_file_path[0: len(src_file_path) - 4] + "_loaded.jpg"):
                        MLog.debug("the loading test is passed")
                        homepage_index = i
                        return launching_index, homepage_index
            else:
                # 没找到首页特征图时,去找启动页的特征图
                tmp_flag = isLaunchingPage(src_file_path, real_launching_feature_path)
                if tmp_flag:
                    launching_homepage_flag = True
                    MLog.info("we find launching  pic agagin, the index = {}".format(i))
                    continue
        MLog.debug("last_frame_find_rgb: " + src_file_path + " is not last frame")
    return launching_index, homepage_index
Exemple #8
0
 def get(self, section, option, default=""):
     """
     用法:
     conf = Config()
     info = conf.get("main","url)
     """
     if section in self.config.sections():
         pass
     else:
         MLog.info(u"configs2 get: " + u"配置文件中找不到该 section :" + str(section) + u"直接返回空字符串")
         return default
     return self.config.get(section, option)
Exemple #9
0
def test_main(serial_num, method, params):
    deviceInfo = DeviceInfo(serial_num)
    settings._init()
    firstLaunchTimes, notFirstLaunchTimes, enterLiveTimes, apkName, package = get_start_params(
    )
    MLog.info("current Device = {}".format(serial_num))
    start_time = datetime.datetime.now()
    if params.install_method == Constants.autoInstall:  # 自动安装
        MLog.info(u"main test_main: 自动安装!")
        start_python(serial_num, params)
    else:  # 手动安装,判断有么有安装,没有安装提示,return,安装之后走
        if apkIsInstall(package):
            start_python(serial_num, params)
        else:
            print u"应用没有安装,请先安装应用"
            sys.exit()

    end_video_2_frame_time = datetime.datetime.now()
    MLog.info(u"录屏及切帧时间 time = {}".format(end_video_2_frame_time - start_time))

    path = os.path.dirname(__file__) + "\\"
    os.chdir(path)
    print path
    device_name = deviceInfo.getDeviceInfo()
    first_launch_result, normal_launch_result, enter_ent = start_calculate(
        device_name)
    MLog.debug("first_launch_result ==========")
    MLog.debug(first_launch_result)
    MLog.debug("normal_launch_result ==========")
    MLog.debug(normal_launch_result)
    MLog.debug("enter ent ==========")
    MLog.debug(enter_ent)

    first_launch_all_datas, normal_launch_all_datas, detail_data, avg_detail_data, first_lunch_splash_datas, normal_launch_splash_datas, enter_liveroom_datas = format_data(
        first_launch_result, normal_launch_result, enter_ent, apkName)
    end_calculate_time = datetime.datetime.now()
    MLog.info(u"计算时间 time ={}".format(end_calculate_time -
                                      end_video_2_frame_time))

    # ---------------------------- UI Part ------------------------------#
    # 创建表格
    create_sheet(detail_data, avg_detail_data, device_name)
    # 写入json数据到本地
    write_data_local(device_name, enter_liveroom_datas, first_launch_all_datas,
                     first_lunch_splash_datas, normal_launch_all_datas,
                     normal_launch_splash_datas)

    end_time = datetime.datetime.now()
    MLog.info(
        "all time = {}, video_frame time = {}, calculate time = {}, datacharts time = {}"
        .format(end_time - start_time, end_video_2_frame_time - start_time,
                end_calculate_time - end_video_2_frame_time,
                end_time - end_calculate_time))
Exemple #10
0
 def installAPK(self, name):
     feature_path = self.getFeaturePath()
     path = os.path.dirname(__file__) + "\\"
     os.chdir(path)
     print path
     apk_path = feature_path + os.sep + "apk" + os.sep + name
     if not fileExist(apk_path):
         MLog.error(u"installAPK:" + u"请检查下你的apk安装包 " + name + u" 是否放置在:" +
                    feature_path + u"中的apk分类的路径下!")
         sysExit(u"应用退出,原因:安装失败!")
     MLog.debug(u"installAPK: 执行安装操作,包路径apk_path = " + apk_path)
     os.system("adb -s " + self.serNum + " install " + apk_path)
     MLog.info(u"app_operation installAPK: 安装成功! sermun = " + self.serNum)
Exemple #11
0
def startAppWithConfig(params):
    MLog.debug(u"程序启动...")
    os.system("python -m uiautomator2 init")
    time.sleep(10)
    # 取序列号
    start_time = datetime.datetime.now()
    serial = getDevices()
    MLog.info(u"读取到的序列号 = " + str(serial))
    devices = []
    pool = Pool(len(serial) + 1)  # 取电脑核数
    for index in range(len(serial)):
        serial_number = serial[index]
        MLog.info(u"启动一个新进程 : index = " + str(index) + u" serial_number = " +
                  serial_number)
        deviceInfo = DeviceInfo(serial_number)
        devices.append(deviceInfo.getDeviceInfo())
        # pool.apply_async(test_main, args=(serial_number,))
        # 下面方法注释开会导致进程阻塞,debug时可以打开,运行时注释掉!!!
        result = pool.apply_async(test_main, args=(
            serial_number,
            1,
            params,
        ))
        result.get()
    pool.close()
    pool.join()
    # 生成图表
    create_lines(devices, getApkName())

    # sendEmailWithDefaultConfig()  # 发邮件
    end_time = datetime.datetime.now()
    MLog.info("all time = {}".format(end_time - start_time))
    MLog.info(u"end main...")
Exemple #12
0
    def firstLaunch(self):
        if self.getFirstStartTime() > 0:
            if self.machineName == "PACM00":
                self.fileOperation.removeDirs("/sdcard/DCIM/Screenshots")
                MLog.info(u"删除 screenshot")
                path = os.path.dirname(__file__) + "\\"
                MLog.debug(u"screen_record_main firstLaunch: path = " + path)
                os.chdir(path)
                if os.path.exists("Screenshots"):
                    shutil.rmtree("Screenshots")
            self.appOperation.uninstallAPK()

            # firstTimes = firstLaunchTimes * 20
            first_dir = self.tempDir + "_first"
            self.fileOperation.mkdir(first_dir)
            if self.machineName != "PACM00":
                self.appOperation.installAPK(self.getApkName())
                time.sleep(20)  # 后续改成轮询是否有安装包的包名,有再录屏
            # screenRecord(firstTimes, first_dir + '/' + 'first.mp4')
            # startTime = time.time()
            for index in range(int(self.getFirstStartTime())):
                if self.machineName == "PACM00":
                    self.appOperation.uninstallAPK()
                    time.sleep(2)
                    self.appOperation.installAPK(self.getApkName())
                    time.sleep(15)
                    doInThread(self.registerEvent.inputListener, self.d, 0, self.serNum)
                else:
                    self.appOperation.clearData()
                    time.sleep(3)
                self.startApp.startAPP(self.d, 15, first_dir + '/' + str(index) + '.mp4')
                time.sleep(15)
                MLog.info(u"等待清除缓存...")
                if self.machineName == "PACM00":
                    os.system('adb -s ' + self.serNum + ' shell service call statusbar 1')
                    self.d(text="停止录屏").click()
            time.sleep(10)
            if self.machineName == "PACM00":
                self.videoOperation.pullRecord("/sdcard/DCIM/Screenshots")
            else:
                self.videoOperation.pullRecord(first_dir)
            path = os.path.abspath('.')
            folder = path + '/' + first_dir
            MLog.debug(u"screen_record_main firstLaunch: folder = " + folder)
            os.chdir(folder)
            self.appOperation.killProcess()
            for index in range(int(self.getFirstStartTime())):
                self.videoOperation.videoToPhoto(str(first_dir + "_" + str(index)), str(index))
            os.chdir(path)
def json_file_to_charts(type, device, apks):
    MLog.info(u"json_file_to_charts: type = " + type + u", device = " +
              device + u", apks =" + str(apks))
    # MLog.debug(u"json_file_to_charts: 开始生成折线图...")
    lines = []
    for apk in apks:
        file = get_json_file(type, device, apk)
        try:
            MLog.debug(u"尝试打开文件生成折线图,file = " + file)
            if not fileExist(file):
                continue
            lines.append(read_json(file))
        except Exception, e:
            MLog.error(u"打开文件失败" + file)
            MLog.error(u"e = " + repr(e))
            print lines
Exemple #14
0
 def pullRecord(self, name):
     curPath = os.getcwd()
     if self.machineName == "PACM00":
         os.system("adb -s " + self.serNum + "  pull " + name)
     else:
         os.system("adb -s " + self.serNum + "  pull " + self.saveDir +
                   name)
         MLog.info(u"video_operation pullRecord: 数据上传成功")
         path = os.path.dirname(__file__) + "\\"
         srcPath = os.path.join(os.path.dirname(path), name)
         print srcPath + "pull record----"
         os.chdir(srcPath)
         for root, dirs, files in os.walk(srcPath):  # 遍历统计
             for file in files:
                 if file.__contains__('_'):
                     os.rename(file, file.split('_')[0] + ".mp4")
         os.chdir(curPath)
Exemple #15
0
def huya_first_find_frame(length, from_index, real_path, real_launching_feature_path,
                          real_last_feature_path, rgb_folder):
    launching_homepage_flag = True
    launching_index = -1
    homepage_index = -1
    for i in range(from_index+2, length+1):
        src_file_path = real_path + base_utils.adapter_num(i) + ".jpg"
        feature_name = base_utils.adapter_num(i) + "_feature.jpg"

        if launching_homepage_flag:
            # 进入启动页匹配
            flag = isLaunchingPage(src_file_path, real_launching_feature_path)
            if flag:
                MLog.debug("find_lanching_end_frame: " + src_file_path + " is launching frame")
                continue
            else:
                # 没匹配到,则先记录为启动结束帧,记得往前取一帧
                launching_index = i - 1
                clip_generate_flag(real_path + base_utils.adapter_num(i - 1) + ".jpg",
                                   real_path + base_utils.adapter_num(i - 1) + "_feature.jpg")
                MLog.debug("find_lanching_end_frame: " + src_file_path + " is not launching frame!!!!")
                launching_homepage_flag = False
        else:
            match_img(src_file_path, real_last_feature_path, threshold, real_path + feature_name)
            if base_utils.os.path.exists(real_path + feature_name):
                # 如果识别到了,拿来图片和图库对比,如果当前图片rgb值远大于图库的平均rgb
                # 认为这一帧还在加载中;反之,则认为当前为加载完成帧

                degree = calculate_by_hists(real_last_feature_path, real_path + feature_name)
                print "degree = {}    -----------------------------".format(degree)
                # 这个值是否还可以再调一下?这个值太难取了,有些手机的帧很模糊,有些手机又特别清楚
                if degree < 0.735:
                    continue

                # 识别到才裁剪
                homepage_index = i
                return launching_index, homepage_index
            else:
                # 没找到首页特征图时,去找启动页的特征图
                tmp_flag = isLaunchingPage(src_file_path, real_launching_feature_path)
                if tmp_flag:
                    launching_homepage_flag = True
                    MLog.info("we find launching  pic agagin, the index = {}".format(i))
                    continue
        MLog.debug("last_frame_find_rgb: " + src_file_path + " is not last frame")
    return launching_index, homepage_index
Exemple #16
0
 def screenRecord(self, d, times, name):
     if self.machineName == "PACM00":
         os.system('adb -s ' + self.serNum +
                   ' shell service call statusbar 1')
         d(text="开始录屏").click()
         print "start"
         time.sleep(5)
     else:
         print(
             name +
             "         ----------------------------------                ---------------------------"
         )
         subprocess.Popen(
             "adb -s " + self.serNum +
             " shell screenrecord --bit-rate 10000000 --time-limit " +
             str(times) + " " + self.saveDir + name)
         time.sleep(2)
     MLog.info(u"video_operation screenRecord: 录屏开始")
def json_file_to_type(types, devices, apks):
    MLog.info(u"data_transform :传入的参数如下:")
    MLog.info(u"data_transform json_file_to_type:"
              u"apks = " + list2str(apks) + u" devices = " +
              list2str(devices) + u" types = " + list2str(types))
    result_name = u"chart"
    lines = []
    for type in types:
        src = json_file_path + type
        if fileExist(src):
            for device in devices:
                new_src = src + os.sep + device
                if fileExist(new_src):
                    if count_file(new_src, u".json") > 0:
                        lines.append(json_file_to_charts(type, device, apks))

    if len(lines) == 0:
        MLog.error(u"收集到的折线为0,直接返回!")
        return
    create_charts(result_name, lines)
 def startAppBySwipe(self, d, times, name):
     conf = Config("default.ini")
     app_name = conf.getconf("default").app_name
     try:
         MLog.info("startAppBySwipe:" + u"try start app ,name = " +
                   app_name)
         bounds = d(text=app_name).info['bounds']
         print bounds
     except Exception, e:
         MLog.info(repr(e))
         app_name = "@" + app_name
         MLog.info(
             u"start_app startAppBySwipe: change app's start name , appname is "
             + app_name)
Exemple #19
0
def create_page(lines, result_file_name):
    page = Page()

    for line in lines:
        if line is not None:
            page.add(line)

    file_name = file_path + result_file_name + ".html"
    MLog.info(u"create_page: 开始生成图表...")
    MLog.info(u"create_page: 图表包含的折线图数量为:" + str(len(page)))
    MLog.info(u"create_page: 图表生成路径:" + file_name)

    checkSrcVialdAndAutoCreate(file_path)
    page.render(file_name.decode('utf-8'))
Exemple #20
0
def write_data_local(device_name, enter_liveroom_datas, first_launch_all_datas,
                     first_lunch_splash_datas, normal_launch_all_datas,
                     normal_launch_splash_datas):
    # write log data
    MLog.info(
        u"--------------------------开始写入json数据到本地--------------------------")
    MLog.debug(u"首次启动总耗时->")
    MLog.info(
        json.dumps(first_launch_all_datas, ensure_ascii=False).decode('utf8'))
    MLog.debug(u"非首次启动总耗时>")
    MLog.info(
        json.dumps(normal_launch_all_datas, ensure_ascii=False).decode('utf8'))
    MLog.debug(u"首次启动闪屏页耗时->")
    MLog.info(
        json.dumps(first_lunch_splash_datas,
                   ensure_ascii=False).decode('utf8'))
    MLog.debug(u"非首次启动闪屏页耗时->")
    MLog.info(
        json.dumps(normal_launch_splash_datas,
                   ensure_ascii=False).decode('utf8'))
    MLog.debug(u"进直播间耗时->")
    MLog.info(
        json.dumps(enter_liveroom_datas, ensure_ascii=False).decode('utf8'))
    # 写 JSON 数据
    write_data_to_file(u"首次启动总耗时", device_name,
                       getApkName().split(".apk")[0], first_launch_all_datas)
    write_data_to_file(u"非首次启动总耗时", device_name,
                       getApkName().split(".apk")[0], normal_launch_all_datas)
    write_data_to_file(u"首次启动闪屏页耗时", device_name,
                       getApkName().split(".apk")[0], first_lunch_splash_datas)
    write_data_to_file(u"非首次启动闪屏页耗时", device_name,
                       getApkName().split(".apk")[0],
                       normal_launch_splash_datas)
    write_data_to_file(u"进直播间耗时", device_name,
                       getApkName().split(".apk")[0], enter_liveroom_datas)
    MLog.info(
        u"--------------------------写入json数据到本地结束--------------------------")
    # MLog.debug(u"json_file_to_charts: 开始生成折线图...")
    lines = []
    for apk in apks:
        file = get_json_file(type, device, apk)
        try:
            MLog.debug(u"尝试打开文件生成折线图,file = " + file)
            if not fileExist(file):
                continue
            lines.append(read_json(file))
        except Exception, e:
            MLog.error(u"打开文件失败" + file)
            MLog.error(u"e = " + repr(e))
            print lines
    # MLog.debug(u"json_file_to_charts: 生成折线图完成...")
    # MLog.info(u"------------------折线图生成异常请看下面折线数量是否大于0-----------------")
    MLog.info(u"可生成折线数量 = " + str(len(lines)))
    return ChartItem(device + type, lines)


# 通过每幅图的file.json文件生成图表,src代表目录
def create_from_file_per(src, title, show_avg):
    MLog.debug(u"data_transform create_from_file_per: 通过读取json文件生成图表数据")

    # 子目录或文件
    lst = []
    for item in os.listdir(src):
        item = item.decode('GB2312')
        path = os.path.join(src, item)
        if os.path.splitext(path)[1] == '.json':
            lst.append(path)
            MLog.debug(u"create_from_file_per: add path " + path)
    def startAppBySwipe(self, d, times, name):
        conf = Config("default.ini")
        app_name = conf.getconf("default").app_name
        try:
            MLog.info("startAppBySwipe:" + u"try start app ,name = " +
                      app_name)
            bounds = d(text=app_name).info['bounds']
            print bounds
        except Exception, e:
            MLog.info(repr(e))
            app_name = "@" + app_name
            MLog.info(
                u"start_app startAppBySwipe: change app's start name , appname is "
                + app_name)
        self.videoOperation.screenRecord(d, times, name)
        MLog.info(u"start_app startAppBySwipe: click app logo.")
        d(text=app_name).click()

    def cap(self):
        out_path = os.path.dirname(__file__) + os.sep + "cap" + os.sep
        img_name = self.serNum + "_cap.png"
        cmd1 = r"adb -s " + self.serNum + " shell /system/bin/screencap -p /sdcard/" + img_name
        cmd2 = r"adb -s " + self.serNum + " pull /sdcard/" + img_name + " " + out_path + img_name
        checkSrcVialdAndAutoCreate('./cap/')
        os.system(cmd1)
        os.system(cmd2)
        print 'cap ====1'
        return out_path + img_name, out_path

    # 进入直播间
    def enter(self, d, times, video, package):
Exemple #23
0
 def start_python(self):
     MLog.info(u"screen_record_main start_python: serial_num = " + str(self.serNum))
     self.screenmain()
Exemple #24
0
    params.app_name = config.getAppName()
    params.package_name = config.getPackage()
    params.features = config.getFeaturePath()
    return params


if __name__ == '__main__':
    MLog.debug(u"程序启动...")
    config = BaseConfig()
    params = configToParams(config)
    os.system("python -m uiautomator2 init")
    time.sleep(10)
    # 取序列号
    start_time = datetime.datetime.now()
    serial = getDevices()
    MLog.info(u"读取到的序列号 = " + str(serial))
    devices = []
    pool = Pool(len(serial) + 1)  # 取电脑核数
    for index in range(len(serial)):
        serial_number = serial[index]
        MLog.info(u"启动一个新进程 : index = " + str(index) + u" serial_number = " +
                  serial_number)
        deviceInfo = DeviceInfo(serial_number)
        devices.append(deviceInfo.getDeviceInfo())
        # pool.apply_async(test_main, args=(serial_number,))
        # 下面方法注释开会导致进程阻塞,debug时可以打开,运行时注释掉!!!
        result = pool.apply_async(test_main, args=(
            serial_number,
            1,
            params,
        ))
Exemple #25
0
 def uninstallAPK(self):
     MLog.info(u"app_operation uninstallAPK: 执行卸载应用,sernum =" + self.serNum)
     os.system('adb -s ' + self.serNum + '  uninstall ' + self.getPackage())
Exemple #26
0
 def clearData(self):
     MLog.info(u"app_operation clearData: 执行清除数据,sernum = " + self.serNum)
     os.system('adb -s ' + self.serNum + ' shell pm clear ' +
               self.getPackage())
Exemple #27
0
 def killProcess(self):
     MLog.info(u"app_operation killProcess: 执行杀进程 ,sernum = " + self.serNum)
     os.system('adb -s ' + self.serNum + ' shell am force-stop ' +
               self.getPackage())
Exemple #28
0
def create_sheet(json_detail_data, json_avg_detail, device_name):
    MLog.info(u"--------------------------开始准备生成表格---------------------------")
    MLog.info(u"data_to_format create_sheet:创建表格开始...")
    apk_name = getApkName()
    sheet_name = device_name + "_detail_time_cost"
    file_name = device_name + "_data_detail"
    checkSrcVialdAndAutoCreate(file_path)
    write_json(json_detail_data, file_path + 'alldata.json')
    write_json(json_avg_detail, file_path + 'avgdata.json')

    MLog.info(u"创建耗时统计 -> json数据文件为json_detail_data: ")
    MLog.info(json.dumps(json_detail_data, ensure_ascii=False).decode('utf8'))
    title = device_name + " " + apk_name + u" 耗时统计"
    create_detail_sheet_by_json(sheet_name, file_name, title, json_detail_data)

    MLog.info(u"创建平均耗时统计 -> json数据文件为json_avg_detail: ")
    MLog.info(json.dumps(json_avg_detail, ensure_ascii=False).decode('utf8'))
    title = device_name + " " + apk_name + u" 平均耗时统计"
    create_detail_sheet_by_json(sheet_name, "avg_data_result", title,
                                json_avg_detail)
    MLog.info(u"--------------------------生成表格结束---------------------------")
Exemple #29
0
def format_data(first_launch_result, normal_launch_result, enter_ent,
                apk_name):
    # 算平均值啥的
    total_datas1 = []
    launching_datas1 = []
    homepage_datas1 = []
    ent_live_room_result = []
    for x, y, z in enter_ent:
        print(x, y, z)
        cost = (z - x + 1) * 20
        ent_live_room_result.append(cost)

    for i in range(0, len(first_launch_result)):
        total_datas1.append(first_launch_result[i][4])
        launching_datas1.append(first_launch_result[i][5])
        homepage_datas1.append(first_launch_result[i][6])

    total_datas2 = []
    launching_datas2 = []
    homepage_datas2 = []
    for i in range(0, len(normal_launch_result)):
        total_datas2.append(normal_launch_result[i][4])
        launching_datas2.append(normal_launch_result[i][5])
        homepage_datas2.append(normal_launch_result[i][6])

    detail_data = []
    max_count = max(len(total_datas1), len(total_datas2),
                    len(ent_live_room_result))
    for i in range(1, max_count + 1):
        dict_temp = collections.OrderedDict()
        dict_temp[u"次数"] = str(i)
        dict_temp[u"首次启动总耗时"] = checkVaild(launching_datas1, i - 1)
        dict_temp[u"首次启动首页加载耗时"] = checkVaild(homepage_datas1, i - 1)
        dict_temp[u"非首次启动总耗时"] = checkVaild(total_datas2, i - 1)
        dict_temp[u"非首次启动耗时"] = checkVaild(launching_datas2, i - 1)
        dict_temp[u"非首次启动首页加载耗时"] = checkVaild(homepage_datas2, i - 1)
        dict_temp[u"进入直播间耗时"] = checkVaild(ent_live_room_result, i - 1)
        detail_data.append(dict_temp)
    MLog.info(u"Excel表格耗时详细数据")
    MLog.info(json.dumps(detail_data, ensure_ascii=False).decode('utf8'))

    avg_detail_data = []
    dict_avg = {
        u"平均首次启动总耗时": avg_list(total_datas1),
        u"平均首次启动耗时": avg_list(launching_datas1),
        u"平均首次启动首页加载耗时": avg_list(homepage_datas1),
        u"平均非首次启动总耗时": avg_list(total_datas2),
        u"平均非首次启动耗时": avg_list(launching_datas2),
        u"平均非首次启动首页加载耗时": avg_list(homepage_datas2)
    }
    avg_detail_data.append(dict_avg)
    MLog.info(u"Excel表格平均耗时详细数据")
    MLog.info(json.dumps(avg_detail_data, ensure_ascii=False).decode('utf8'))

    first_launch_all_datas = {"app": apk_name, "datas": total_datas1}

    normal_launch_all_datas = {"app": apk_name, "datas": total_datas2}

    first_lunch_splash_datas = {
        "app": apk_name + u"_launching",
        "datas": launching_datas1
    }

    normal_launch_splash_datas = {
        "app": apk_name + u"_launching",
        "datas": launching_datas2
    }

    enter_liveroom_datas = {
        "app": getApkName().split(".apk")[0],
        "datas": ent_live_room_result
    }
    return first_launch_all_datas, normal_launch_all_datas, detail_data, avg_detail_data, first_lunch_splash_datas, normal_launch_splash_datas, enter_liveroom_datas