def test_get_average_frame_error_list(self): frame_error_list = { 1: 0, 2: 0.5, 3: 1.0 } v = mmapi.get_average_frame_error_list(frame_error_list) assert self.approx_equal(v, 0.5) frame_error_list = {1: 1.0} v = mmapi.get_average_frame_error_list(frame_error_list) assert self.approx_equal(v, 1.0) frame_error_list = {} v = mmapi.get_average_frame_error_list(frame_error_list) assert self.approx_equal(v, 0.0) col = create_example_solve_scene() results = col.execute() success = results[0].get_success() err = results[0].get_final_error() self.assertTrue(isinstance(success, bool)) self.assertTrue(isinstance(err, float)) frame_error_list = dict(results[0].get_frame_error_list()) v = mmapi.get_average_frame_error_list(frame_error_list) assert isinstance(v, float)
def test_perfect_solve(self): """ Open a file and trigger a solve to get perfect results. Make sure solver results doesn't fail in this case. """ # Open the Maya file file_name = 'mmSolverBasicSolveA_triggerMaxFrameErrorTraceback.ma' path = self.get_data_path('scenes', file_name) maya.cmds.file(path, open=True, force=True) # Run solver! s = time.time() col = mmapi.Collection(node='collection1') solres_list = col.execute() e = time.time() print 'total time:', e - s # save the output path = self.get_data_path('solveresult_testPerfectSolve_after.ma') maya.cmds.file(rename=path) maya.cmds.file(save=True, type='mayaAscii', force=True) # Ensure the values are correct solres = solres_list[0] success = solres.get_success() err = solres.get_final_error() frame_error_list = mmapi.merge_frame_error_list([solres]) avg_error = mmapi.get_average_frame_error_list(frame_error_list) max_frame_error = mmapi.get_max_frame_error(frame_error_list) self.assertEqual(max_frame_error[0], None) self.assertIsInstance(max_frame_error[1], float) self.assertTrue(success) self.assertGreater(err, 0.0) return
def log_solve_results(log, solres_list, total_time=None): """ Displays / saves the Solve Results. :param log: Logging object to log with. :type log: logger :param solres_list: List of Solve Results to log. :type solres_list: list of SolveResult :param total_time: :type total_time: None or float :returns: Nothing. :rtype: None """ frame_error_list = mmapi.merge_frame_error_list(solres_list) frame_error_txt = pprint.pformat(dict(frame_error_list)) log.debug('Per-Frame Errors:\n%s', frame_error_txt) timer_stats = mmapi.combine_timer_stats(solres_list) timer_stats_txt = pprint.pformat(dict(timer_stats)) log.debug('Timer Statistics:\n%s', timer_stats_txt) avg_error = mmapi.get_average_frame_error_list(frame_error_list) log.info('Average Error: %.2f pixels', avg_error) max_frame_error = mmapi.get_max_frame_error(frame_error_list) log.info('Max Frame Error: %.2f pixels at frame %s', max_frame_error[1], int(max_frame_error[0])) if total_time is not None: log.info('Total Time: %.3f seconds', total_time) return
def checkSolveResults(self, solres_list): # Ensure the values are correct for res in solres_list: success = res.get_success() err = res.get_final_error() print 'final error', err self.assertTrue(success) self.assertTrue(isinstance(err, float)) # Check the final error values frm_err_list = mmapi.merge_frame_error_list(solres_list) avg_err = mmapi.get_average_frame_error_list(frm_err_list) print 'avg error', avg_err self.assertLess(avg_err, 1.0) max_err_frm, max_err_val = mmapi.get_max_frame_error(frm_err_list) print 'max error frame and value:', max_err_frm, max_err_val self.assertLess(max_err_val, 1.0) return
def log_solve_results(log, solres_list, timestamp=None, total_time=None, status_fn=None): """ Displays / saves the Solve Results. :param log: Logging object to log with. :type log: logger :param solres_list: List of Solve Results to log. :type solres_list: list of SolveResult :param timestamp: The current time; as a UNIX Epoch floating point number (as returned by 'time.time()'). :type timestamp: None or float :param total_time: The duration of the solve to log. :type total_time: None or float :param status_fn: Function to set the status text. :type status_fn: callable function or None :returns: Nothing. :rtype: None """ status_str = '' long_status_str = '' if timestamp is not None: stamp = mmapi.format_timestamp(timestamp) status_str += stamp + ' | ' long_status_str += stamp + ' | ' # Get Solver success. success = True for solres in solres_list: value = solres.get_success() if value is not True: success = False break if success is True: status_str += 'Solved | ' long_status_str += 'Solved | ' else: status_str += 'Failed | ' long_status_str += 'Failed | ' frame_error_list = mmapi.merge_frame_error_list(solres_list) frame_error_txt = pprint.pformat(dict(frame_error_list)) if log: log.debug('Per-Frame Errors:\n%s', frame_error_txt) timer_stats = mmapi.combine_timer_stats(solres_list) timer_stats_txt = pprint.pformat(dict(timer_stats)) if log: log.debug('Timer Statistics:\n%s', timer_stats_txt) avg_error = mmapi.get_average_frame_error_list(frame_error_list) status_str += 'avg deviation %.2fpx' % avg_error long_status_str += 'Average Deviation %.2fpx' % avg_error max_frame, max_error = mmapi.get_max_frame_error(frame_error_list) status_str += ' | max deviation %.2fpx at %s' % (max_error, max_frame) long_status_str += ' | Max Deviation %.2fpx at %s' % (max_error, max_frame) if total_time is not None: if log: log.info('Total Time: %.3f seconds', total_time) status_str += ' | time %.3fsec' % total_time long_status_str += ' | Time %.3fsec' % total_time if log: log.info('Max Frame Deviation: %.2f pixels at frame %s', max_error, max_frame) log.info('Average Deviation: %.2f pixels', avg_error) if status_fn is not None: status_fn(status_str) if log: log.warning(long_status_str) return
def log_solve_results(log, solres_list, total_time=None, status_fn=None): """ Displays / saves the Solve Results. :param log: Logging object to log with. :type log: logger :param solres_list: List of Solve Results to log. :type solres_list: list of SolveResult :param total_time: :type total_time: None or float :returns: Nothing. :rtype: None """ status_str = '' long_status_str = '' # Get Solver success. success = True for solres in solres_list: value = solres.get_success() if value is not True: success = False break if success is True: status_str += 'Solved: ' long_status_str += 'Solved: ' else: status_str += 'Failed: ' long_status_str += 'Failed: ' frame_error_list = mmapi.merge_frame_error_list(solres_list) frame_error_txt = pprint.pformat(dict(frame_error_list)) log.debug('Per-Frame Errors:\n%s', frame_error_txt) timer_stats = mmapi.combine_timer_stats(solres_list) timer_stats_txt = pprint.pformat(dict(timer_stats)) log.debug('Timer Statistics:\n%s', timer_stats_txt) avg_error = mmapi.get_average_frame_error_list(frame_error_list) status_str += 'avg err %.2fpx' % avg_error long_status_str += 'Average Error %.2fpx' % avg_error max_frame_error = mmapi.get_max_frame_error(frame_error_list) status_str += ' | max err %.2fpx at %s' % (max_frame_error[1], max_frame_error[0]) long_status_str += ' | Max Error %.2fpx at %s' % (max_frame_error[1], max_frame_error[0]) if total_time is not None: log.info('Total Time: %.3f seconds', total_time) status_str += ' | time %.3fsec' % total_time long_status_str += ' | Time %.3fsec' % total_time log.info('Max Frame Error: %.2f pixels at frame %s', max_frame_error[1], max_frame_error[0]) log.info('Average Error: %.2f pixels', avg_error) if status_fn is not None: status_fn(status_str) log.warning(long_status_str) return