<commit_before>from .apiresource import CreateableAPIResource
from .apiresource import ListableAPIResource
from .apiresource import DeletableAPIResource
from .apiresource import DownloadableAPIResource

import time


class DatasetExport(CreateableAPIResource, ListableAPIResource,
                    DownloadableAPIResource, DeletableAPIResource):
    """
    DatasetExport represent an export task that takes
    a Dataset or filtered Dataset (Query) and exports
    the contents to a flat file (CSV, JSON, or XLSX).

    For interactive use, DatasetExport can be "followed" to watch
    the progression of the task.
    """
    RESOURCE_VERSION = 2
    PRINTABLE_NAME = 'dataset export'

    LIST_FIELDS = (
        ('id', 'ID'),
        ('documents_count', 'Records'),
        ('format', 'Format'),
        ('status', 'Status'),
        ('created_at', 'Created'),
    )

    def dataset(self):
        from .dataset import Dataset
        return Dataset.retrieve(self['dataset'])

    def follow(self, loop=True):
        if self.status == 'queued':
            print("Waiting for export (id = {0}) to start..."
                  .format(self.id))

        export_status = self.status
        while self.status in ['queued', 'running']:
            if self.status != export_status:
                print("Export is now {0} (was {1})"
                      .format(self.status, export_status))
                export_status = self.status

            if self.status == 'running':
                print("Export '{0}' is {1}: {2}/{3} records exported"
                      .format(self.id,
                              self.status,
                              self.metadata['progress']['processed_records'],
                              self.documents_count))

            if not loop:
                return<commit_msg>handle case where an export hasn't updated initial progress yet and progress is requested<commit_after>from .apiresource import CreateableAPIResource
from .apiresource import ListableAPIResource
from .apiresource import DeletableAPIResource
from .apiresource import DownloadableAPIResource

import time


class DatasetExport(CreateableAPIResource, ListableAPIResource,
                    DownloadableAPIResource, DeletableAPIResource):
    """
    DatasetExport represent an export task that takes
    a Dataset or filtered Dataset (Query) and exports
    the contents to a flat file (CSV, JSON, or XLSX).

    For interactive use, DatasetExport can be "followed" to watch
    the progression of the task.
    """
    RESOURCE_VERSION = 2
    PRINTABLE_NAME = 'dataset export'

    LIST_FIELDS = (
        ('id', 'ID'),
        ('documents_count', 'Records'),
        ('format', 'Format'),
        ('status', 'Status'),
        ('created_at', 'Created'),
    )

    def dataset(self):
        from .dataset import Dataset
        return Dataset.retrieve(self['dataset'])

    def follow(self, loop=True):
        if self.status == 'queued':
            print("Waiting for export (id = {0}) to start..."
                  .format(self.id))

        export_status = self.status
        while self.status in ['queued', 'running']:
            if self.status != export_status:
                print("Export is now {0} (was {1})"
                      .format(self.status, export_status))
                export_status = self.status

            if self.status == 'running':
                print("Export '{0}' is {1}: {2}/{3} records exported"
                      .format(self.id,
                              self.status,
                              self.metadata.get('progress', {}).get('processed_records', 0),  # noqa
                              self.documents_count))

            if not loop:
                return
{'fraction_non_alphanumeric': 0.10237270061316982, 'fraction_numerical': 0.0045321247667288725, 'mean_word_length': 2.0578647106764465, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3379191', 'n_tokens_mistral': 997, 'n_tokens_neox': 952, 'n_words': 291}