コード例 #1
0
def signature_graph_data(request, params, channel):
    '''Return data for the graph of crashes/ADU against build date'''

    signature = params['signature'][0]

    # Check that a product was specified
    if not params['product'] or not params['product'][0]:
        return http.HttpResponseBadRequest('"product" parameter is mandatory')
    product = params['product'][0]

    # Initialise start and end dates
    start_date = None
    end_date = None

    # Store one day as variable for readability
    one_day = datetime.timedelta(days=1)

    # Check for dates
    if 'date' in params:
        for date in params['date']:
            # Set the earliest given start date as the start date
            if date.startswith('>'):
                if date.startswith('>='):
                    d = utils.parse_isodate(date.lstrip('>='))
                else:
                    d = utils.parse_isodate(date.lstrip('>')) + one_day
                if not start_date or d < start_date:
                    start_date = d
            # Set the latest given end date as the end date
            elif date.startswith('<'):
                if date.startswith('<='):
                    d = utils.parse_isodate(date.lstrip('<='))
                else:
                    d = utils.parse_isodate(date.lstrip('<')) - one_day
                if not end_date or d > end_date:
                    end_date = d

    # If start date wasn't given, set it to 7 days before the end date
    # If end date wasn't given either, set it to 7 days before today
    if not start_date:
        if end_date:
            start_date = end_date - datetime.timedelta(days=7)
        else:
            start_date = datetime.datetime.utcnow() - datetime.timedelta(
                days=7)

    # If end date wasn't given, set it to today
    if not end_date:
        end_date = datetime.datetime.utcnow()

    # Get the graph data
    api = models.AduBySignature()
    data = api.get(signature=signature,
                   product_name=product,
                   start_date=start_date,
                   end_date=end_date,
                   channel=channel)

    return data
コード例 #2
0
def time_tag(dt, format='%a, %b %d %H:%M %Z', future=False):
    if not isinstance(dt, (datetime.date, datetime.datetime)):
        try:
            dt = parse_isodate(dt)
        except isodate.ISO8601Error:
            return dt
    return jinja2.Markup('<time datetime="{}" class="{}">{}</time>'.format(
        dt.isoformat(), future and 'in' or 'ago', dt.strftime(format)))
コード例 #3
0
    def to_python(self, value):
        if value:
            try:
                return parse_isodate(value).replace(tzinfo=utc)
            except (ValueError, isodate.isoerror.ISO8601Error):
                # let the super method deal with that
                pass

        return super().to_python(value)
コード例 #4
0
ファイル: form_fields.py プロジェクト: willkg/socorro
    def to_python(self, value):
        if value:
            try:
                return parse_isodate(value).replace(tzinfo=utc)
            except (ValueError, isodate.isoerror.ISO8601Error):
                # let the super method deal with that
                pass

        return super().to_python(value)
コード例 #5
0
ファイル: jinja_helpers.py プロジェクト: mozilla/socorro
def time_tag(dt, format='%a, %b %d %H:%M %Z', future=False):
    if not isinstance(dt, (datetime.date, datetime.datetime)):
        try:
            dt = parse_isodate(dt)
        except isodate.ISO8601Error:
            return dt
    return jinja2.Markup(
        '<time datetime="{}" class="{}">{}</time>'.format(
            dt.isoformat(),
            future and 'in' or 'ago',
            dt.strftime(format)
        )
    )
コード例 #6
0
def human_readable_iso_date(dt):
    """ Python datetime to a human readable ISO datetime. """
    if not isinstance(dt, (datetime.date, datetime.datetime)):
        try:
            dt = parse_isodate(dt)
        except isodate.ISO8601Error:
            # Because we're paranoid, we don't want to fail
            # the whole template rendering just because one date
            # couldn't be displayed in a more human readable format.
            # This, for example, can happen if the date isn't really
            # valid but something. E.g. 2015-10-10 15:32:07.620535
            return dt

    format = '%Y-%m-%d %H:%M:%S'
    return dt.strftime(format)
コード例 #7
0
ファイル: jinja_helpers.py プロジェクト: mozilla/socorro
def human_readable_iso_date(dt):
    """ Python datetime to a human readable ISO datetime. """
    if not isinstance(dt, (datetime.date, datetime.datetime)):
        try:
            dt = parse_isodate(dt)
        except isodate.ISO8601Error:
            # Because we're paranoid, we don't want to fail
            # the whole template rendering just because one date
            # couldn't be displayed in a more human readable format.
            # This, for example, can happen if the date isn't really
            # valid but something. E.g. 2015-10-10 15:32:07.620535
            return dt

    format = '%Y-%m-%d %H:%M:%S'
    return dt.strftime(format)
コード例 #8
0
def signature_graph_data(request, params, channel):
    '''Return data for the graph of crashes/ADU against build date'''

    signature = params['signature'][0]

    # Check that a product was specified
    if not params['product'] or not params['product'][0]:
        return http.HttpResponseBadRequest(
            '"product" parameter is mandatory'
        )
    product = params['product'][0]

    # Initialise start and end dates
    start_date = None
    end_date = None

    # Store one day as variable for readability
    one_day = datetime.timedelta(days=1)

    # Check for dates
    if 'date' in params:
        for date in params['date']:
            # Set the earliest given start date as the start date
            if date.startswith('>'):
                if date.startswith('>='):
                    d = utils.parse_isodate(date.lstrip('>='))
                else:
                    d = utils.parse_isodate(date.lstrip('>')) + one_day
                if not start_date or d < start_date:
                    start_date = d
            # Set the latest given end date as the end date
            elif date.startswith('<'):
                if date.startswith('<='):
                    d = utils.parse_isodate(date.lstrip('<='))
                else:
                    d = utils.parse_isodate(date.lstrip('<')) - one_day
                if not end_date or d > end_date:
                    end_date = d

    # If start date wasn't given, set it to 7 days before the end date
    # If end date wasn't given either, set it to 7 days before today
    if not start_date:
        if end_date:
            start_date = end_date - datetime.timedelta(days=7)
        else:
            start_date = datetime.datetime.utcnow() - datetime.timedelta(
                days=7
            )

    # If end date wasn't given, set it to today
    if not end_date:
        end_date = datetime.datetime.utcnow()

    # Get the graph data
    api = models.AduBySignature()
    data = api.get(
        signature=signature,
        product_name=product,
        start_date=start_date,
        end_date=end_date,
        channel=channel
    )

    return data