Skip to content
Snippets Groups Projects
Select Git revision
  • d1151538ce0686324008626dede274b540db86e9
  • master default protected
  • MAM-106-add-plots
  • MAM-90-executor-with-cwltool
  • MAM-88-change-status-names
  • MAM-50-specification-GUI
  • MAM-44-build-specification-functionality
  • MAM-42-ATDBspec-add-endpoints
  • MAM-41-ATDBspec-database-changes
  • bugfix-ingested-sizes
  • SDC-1663-inputs-validation
  • SDC-1649-compression-pipeline-quality-indicators
  • SDC-1635-monitoring-page
  • split-pipeline-for-gitlab
  • SDC-1590-database-changes
  • SDC-1580-adapt-configuration-to-multi-service
  • multi-edit
  • SDC-1552-datamodel-add-service-host
  • logentry_graph
  • SDC-1549-aggregation-task-ux
  • imaging-compression-pipeline-commissioning
21 results

common.py

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    common.py 2.57 KiB
    """
    common helper functions
    """
    import logging;
    from datetime import *
    import time
    from enum import Enum
    
    logger = logging.getLogger(__name__)
    class State(Enum):
        DEFINED = "defined"
        STAGED = "staged"
        FETCHED = "fetched"
        PROCESSED = "processed"
        STORED = 'stored'
        VALIDATED = "validated"
        SCRUBBED = "scrubbed"
        PRE_ARCHIVING = "pre_archiving"
        PRE_ARCHIVED = "pre_archived"
        ARCHIVING = "archiving"
        ARCHIVED = "archived"
        FINISHED = "finished"
        FINISHING = "finishing"
        SUSPENDED = "suspended"
        DISCARDED = "discarded"
        FAILED = "failed"
    
    verified_statusses = [State.STORED.value, State.VALIDATED.value, State.SCRUBBED.value, State.PRE_ARCHIVED,
                          State.ARCHIVED.value, State.FINISHED.value, State.SUSPENDED.value, State.DISCARDED.value]
    
    processed_statusses = [State.PROCESSED.value, State.STORED.value, State.DISCARDED.value]
    
    class SummaryFlavour(Enum):
        DEFAULT = "default"
        LINC_CALIBRATOR = "linc_calibrator"
        LINC_TARGET = "linc_target"
        IMAGING_COMPRESSION = "imaging_compression"
    
    # this is a decorator that can be put in front (around) a function all to measure its execution time
    def timeit(method):
        def timed(*args, **kw):
            ts = time.time()
            result = method(*args, **kw)
            te = time.time()
            if 'log_time' in kw:
                name = kw.get('log_name', method.__name__.upper())
                kw['log_time'][name] = int((te - ts) * 1000)
            else:
                print('execution time: %r  %2.2f ms' % \
                      (method.__name__, (te - ts) * 1000))
            return result
        return timed
    
    def get_summary_flavour(task):
        """
        not every workflow has the same summary structure
        determine the flavour based on the selected task, and construct the html accordingly
        this could be made implicit in the future by adding a setting to the Workflow,
        but currently it is derived in a yucky way. But at least the yuck is confined to this function
        """
    
        summary_flavour = SummaryFlavour.DEFAULT.value
    
        # so... yikes... what distinguishes the summary flavours?
        workflow_uri = task.workflow.workflow_uri
    
        # for linc, look at the workflow_uri
        if "linc_calibrator" in workflow_uri:
            return SummaryFlavour.LINC_CALIBRATOR.value
        if "linc_target" in workflow_uri:
            return SummaryFlavour.LINC_TARGET.value
    
        try:
            summary = task.quality_json["summary"]
        except:
            # no summary found
            return None
    
        if 'details' in summary.keys():
            summary_flavour = SummaryFlavour.IMAGING_COMPRESSION.value
    
        return summary_flavour