<commit_before>from __future__ import division
from __future__ import print_function

import hashlib
import os
import shutil
import tarfile
import tempfile
import zipfile

import filelock
from six.moves.urllib import request

import sys
import time

from chainer.dataset.download import get_dataset_directory
from chainer.dataset.download import get_dataset_root


def _reporthook(count, block_size, total_size):
    global start_time
    if count == 0:
        start_time = time.time()
        return
    duration = time.time() - start_time
    progress_size = int(count * block_size)
    try:
        speed = int(progress_size / (1024 * duration))
    except ZeroDivisionError:
        speed = float('inf')
    percent = int(count * block_size * 100 / total_size)
    sys.stdout.write('\r...{}, {} MB, {} KB/s, {} seconds passed'.format(
        percent, progress_size / (1024 * 1024), speed, duration))
    sys.stdout.flush()


def cached_download(url):
    """Downloads a file and caches it.

    This is different from the original ``cached_download`` in that the
    download progress is reported.
<commit_msg>update message<commit_after>from __future__ import division
from __future__ import print_function

import hashlib
import os
import shutil
import tarfile
import tempfile
import zipfile

import filelock
from six.moves.urllib import request

import sys
import time

from chainer.dataset.download import get_dataset_directory
from chainer.dataset.download import get_dataset_root


def _reporthook(count, block_size, total_size):
    global start_time
    if count == 0:
        start_time = time.time()
        return
    duration = time.time() - start_time
    progress_size = int(count * block_size)
    try:
        speed = int(progress_size / ((1 << 10) * duration))
    except ZeroDivisionError:
        speed = float('inf')
    percent = int(count * block_size * 100 / total_size)
    sys.stdout.write(
        '\r... {:d} %, {:.2f} MiB, {:.2f} KiB/s, {:.1f} seconds passed'.format(
            percent, progress_size / (1 << 20), speed, duration))
    sys.stdout.flush()


def cached_download(url):
    """Downloads a file and caches it.

    This is different from the original ``cached_download`` in that the
    download progress is reported.

{'fraction_non_alphanumeric': 0.09223300970873786, 'fraction_numerical': 0.012797881729920565, 'mean_word_length': 3.4450980392156865, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1178006', 'n_tokens_mistral': 696, 'n_tokens_neox': 664, 'n_words': 215}