<commit_before>from time import mktime

from omeroweb.webgateway.marshal import shapeMarshal

from utils import switch_to_default_search_group


def _date_to_timestamp(date):
    return mktime(date.timetuple())


def _get_image_resolution(image_object):
    return image_object.getSizeX() * image_object.getSizeY()


def _project_to_json(project_object, datasets_map=None):
    prj_json = {
        'id': project_object.getId(),
        'name': project_object.getName(),
        'description': project_object.getDescription(),
        'datasets': []
    }
    if datasets_map is not None:
        for dset, imgs in datasets_map:
            prj_json['datasets'].append(_dataset_to_json(dset, imgs))
    return prj_json


def _dataset_to_json(dataset_object, image_objects=None):
    dset_obj = {
        'id': dataset_object.getId(),
        'type': dataset_object.OMERO_CLASS,
        'name': dataset_object.getName(),
        'description': dataset_object.getDescription(),
        'childCount': dataset_object.countChildren(),
        'images': []
    }
    if image_objects is not None:
        for img_obj in image_objects:
            dset_obj['images'].append(_image_to_json(img_obj))
    return dset_obj


def _image_to_json(image_object, full_info=False, roi_objects=None):
    img_obj = {
        'id': image_object.getId(),
        'type': 'image',
        'description': image_object.getDescription(),
        'name': image_object.getName(),
        'author': image_object.getAuthor(),
        'creationTime': _date_to_timestamp(image_object.getDate()),
        'importTime': _date_to_timestamp(image_object.creationEventDate()),
        'lastUpdate': _date_to_timestamp(image_object.updateEventDate()),
        'rois': []
    }
    if full_info:
        img_obj.update({
            'filesetId': image_object.getFileset().getId(),
            'projectId': image_object.getProject().getId(),
            'projectName': image_object.getProject().getName(),
            'projectDescription': image_object.getProject().getDescription(),
            'datasetId': image_object.getParent().getId(),
            'datasetName': image_object.getParent().getName(),
            'datasetDescription': image_object.getParent().getDescription()
        })
    if roi_objects is not None:
        for roi in roi_objects:
            img_obj['rois'].append(_roi_to_json(roi))
    return img_obj


def _roi_to_json(roi_object):
    return {<commit_msg>added width and height to image JSON<commit_after>from time import mktime

from omeroweb.webgateway.marshal import shapeMarshal

from utils import switch_to_default_search_group


def _date_to_timestamp(date):
    return mktime(date.timetuple())


def _get_image_resolution(image_object):
    return image_object.getSizeX() * image_object.getSizeY()


def _project_to_json(project_object, datasets_map=None):
    prj_json = {
        'id': project_object.getId(),
        'name': project_object.getName(),
        'description': project_object.getDescription(),
        'datasets': []
    }
    if datasets_map is not None:
        for dset, imgs in datasets_map:
            prj_json['datasets'].append(_dataset_to_json(dset, imgs))
    return prj_json


def _dataset_to_json(dataset_object, image_objects=None):
    dset_obj = {
        'id': dataset_object.getId(),
        'type': dataset_object.OMERO_CLASS,
        'name': dataset_object.getName(),
        'description': dataset_object.getDescription(),
        'childCount': dataset_object.countChildren(),
        'images': []
    }
    if image_objects is not None:
        for img_obj in image_objects:
            dset_obj['images'].append(_image_to_json(img_obj))
    return dset_obj


def _image_to_json(image_object, full_info=False, roi_objects=None):
    img_obj = {
        'id': image_object.getId(),
        'type': 'image',
        'description': image_object.getDescription(),
        'name': image_object.getName(),
        'author': image_object.getAuthor(),
        'width': image_object.getSizeX(),
        'height': image_object.getSizeY(),
        'creationTime': _date_to_timestamp(image_object.getDate()),
        'importTime': _date_to_timestamp(image_object.creationEventDate()),
        'lastUpdate': _date_to_timestamp(image_object.updateEventDate()),
        'rois': []
    }
    if full_info:
        img_obj.update({
            'filesetId': image_object.getFileset().getId(),
            'projectId': image_object.getProject().getId(),
            'projectName': image_object.getProject().getName(),
            'projectDescription': image_object.getProject().getDescription(),
            'datasetId': image_object.getParent().getId(),
            'datasetName': image_object.getParent().getName(),
            'datasetDescription': image_object.getParent().getDescription()
        })
    if roi_objects is not None:
        for roi in roi_objects:
            img_obj['rois'].append(_roi_to_json(roi))
    return img_obj


def _roi_to_json(roi_object):
    return {
{'fraction_non_alphanumeric': 0.11990407673860912, 'fraction_numerical': 0.0, 'mean_word_length': 3.2887746358183376, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4414150', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1518, 'n_words': 264}