<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def stats(path, fmt, nocolor, timezones, utc, noprogress, most_common, resolve, length):
 """Analysis of Facebook chat history."""

    with colorize_output(nocolor):
        try:
            chat_history = _process_history(
                path=path, thread='', timezones=timezones,
                utc=utc, noprogress=noprogress, resolve=resolve)
        except ProcessingFailure:
            return
        statistics = ChatHistoryStatistics(
            chat_history, most_common=None if most_common < 0 else most_common)
        if fmt == 'text':
            statistics.write_text(sys.stdout, -1 if length < 0 else length)
        elif fmt == 'json':
            statistics.write_json(sys.stdout)
        elif fmt == 'pretty-json':
            statistics.write_json(sys.stdout, pretty=True)
        elif fmt == 'yaml':
            statistics.write_yaml(sys.stdout)