def get_reports(filter_form, pagination): opsysrelease_ids = [ osr.id for osr in (filter_form.opsysreleases.data or []) ] component_ids = component_names_to_ids(filter_form.component_names.data) if filter_form.associate.data: associate_id = filter_form.associate.data.id else: associate_id = None arch_ids = [arch.id for arch in (filter_form.arch.data or [])] types = filter_form.type.data or [] if filter_form.daterange.data: (since_date, to_date) = filter_form.daterange.data else: since_date = None to_date = None r = query_reports(db, opsysrelease_ids=opsysrelease_ids, component_ids=component_ids, associate_id=associate_id, arch_ids=arch_ids, types=types, occurrence_since=since_date, occurrence_to=to_date, limit=pagination.limit, offset=pagination.offset, order_by=filter_form.order_by.data, solution=filter_form.solution) return r
def get_reports(filter_form, pagination): opsysrelease_ids = [ osr.id for osr in (filter_form.opsysreleases.data or [])] component_ids = component_names_to_ids(filter_form.component_names.data) if filter_form.associate.data: associate_id = filter_form.associate.data.id else: associate_id = None arch_ids = [arch.id for arch in (filter_form.arch.data or [])] types = filter_form.type.data or [] if filter_form.daterange.data: (since_date, to_date) = filter_form.daterange.data else: since_date = None to_date = None r = query_reports( db, opsysrelease_ids=opsysrelease_ids, component_ids=component_ids, associate_id=associate_id, arch_ids=arch_ids, types=types, occurrence_since=since_date, occurrence_to=to_date, limit=pagination.limit, offset=pagination.offset, order_by=filter_form.order_by.data, solution=filter_form.solution) return r
def index_plot_data_cache(summary_form): key = summary_form.caching_key() cached = flask_cache.get(key) if cached is not None: return cached reports = [] hist_table, hist_field = get_history_target( summary_form.resolution.data) component_ids = component_names_to_ids(summary_form.component_names.data) (since_date, to_date) = summary_form.daterange.data if summary_form.opsysreleases.data: opsysreleases = summary_form.opsysreleases.data else: opsysreleases = ( db.session.query(OpSysRelease) .filter(OpSysRelease.status != "EOL") .order_by(OpSysRelease.releasedate) .all()) for osr in opsysreleases: counts = ( db.session.query(hist_field.label("time"), func.sum(hist_table.count).label("count")) .group_by(hist_field) .order_by(hist_field)) counts = counts.filter(hist_table.opsysrelease_id == osr.id) if component_ids: counts = (counts.join(Report) .filter(Report.component_id.in_(component_ids))) counts = (counts.filter(hist_field >= since_date) .filter(hist_field <= to_date)) counts = counts.all() dates = set(date_iterator(since_date, summary_form.resolution.data, to_date)) for time, count in counts: dates.remove(time) for date in dates: counts.append((date, 0)) counts = sorted(counts, key=itemgetter(0)) reports.append((str(osr), counts)) cached = render_template("summary/index_plot_data.html", reports=reports, resolution=summary_form.resolution.data[0]) flask_cache.set(key, cached, timeout=60*60) return cached
def index_plot_data_cache(summary_form): key = summary_form.caching_key() cached = flask_cache.get(key) if cached is not None: return cached reports = [] hist_table, hist_field = get_history_target(summary_form.resolution.data) component_ids = component_names_to_ids(summary_form.component_names.data) (since_date, to_date) = summary_form.daterange.data if summary_form.opsysreleases.data: opsysreleases = summary_form.opsysreleases.data else: opsysreleases = (db.session.query(OpSysRelease).filter( OpSysRelease.status != "EOL").order_by( OpSysRelease.opsys_id).order_by(OpSysRelease.version).all()) for osr in opsysreleases: counts = (db.session.query( hist_field.label("time"), func.sum(hist_table.count).label("count")).group_by( hist_field).order_by(hist_field)) counts = counts.filter(hist_table.opsysrelease_id == osr.id) if component_ids: counts = (counts.join(Report).filter( Report.component_id.in_(component_ids))) counts = (counts.filter(hist_field >= since_date).filter( hist_field <= to_date)) counts = counts.all() dates = set( date_iterator(since_date, summary_form.resolution.data, to_date)) for time, _ in counts: dates.remove(time) for date in dates: counts.append((date, 0)) counts = sorted(counts, key=itemgetter(0)) reports.append((str(osr), counts)) cached = render_template("summary/index_plot_data.html", reports=reports, resolution=summary_form.resolution.data[0]) flask_cache.set(key, cached, timeout=60 * 60) return cached
def compute_totals(summary_form): component_ids = component_names_to_ids(summary_form.component_names.data) from_date, to_date = summary_form.daterange.data resolution = summary_form.resolution.data table, date_column = get_history_target(summary_form.resolution.data) # Generate sequence of days/weeks/months in the specified range. from_date, to_date, delta = interval_delta(from_date, to_date, resolution) dates = (db.session.query( func.generate_series(from_date, to_date, delta).label('date')).subquery()) if summary_form.opsysreleases.data: # Query only requested opsys releases. releases = (db.session.query(OpSysRelease).filter( OpSysRelease.id.in_([ osr.id for osr in summary_form.opsysreleases.data ])).subquery()) else: # Query all active opsys releases. releases = (db.session.query(OpSysRelease).filter( OpSysRelease.status != 'EOL').subquery()) # Sum daily counts for each date in the range and each opsys release. history = (db.session.query( date_column.label('date'), func.sum(table.count).label('count'), table.opsysrelease_id).filter(from_date <= date_column).filter( date_column <= to_date).group_by(table.opsysrelease_id, date_column)) if component_ids: history = history.join(Report).filter( Report.component_id.in_(component_ids)) history = history.subquery() q = (db.session.query( dates.c.date, func.coalesce(history.c.count, 0).label('count'), OpSys.name, releases.c.version).outerjoin( releases, dates.c.date == dates.c.date).outerjoin( history, (history.c.date == dates.c.date) & (history.c.opsysrelease_id == releases.c.id)).join( OpSys, OpSys.id == releases.c.opsys_id).order_by( OpSys.id, releases.c.version, dates.c.date)) by_opsys = dict() groups = groupby(q.all(), lambda r: f'{r.name} {r.version}') for osr, rows in groups: counts = [(r.date, r.count) for r in rows] by_opsys[osr] = counts result = {'by_opsys': by_opsys, 'from_date': from_date, 'to_date': to_date} return result
def get_problems(filter_form, pagination): opsysrelease_ids = [ osr.id for osr in (filter_form.opsysreleases.data or []) ] component_ids = component_names_to_ids(filter_form.component_names.data) if filter_form.associate.data: associate_id = filter_form.associate.data.id else: associate_id = None arch_ids = [arch.id for arch in (filter_form.arch.data or [])] types = filter_form.type.data or [] exclude_taintflag_ids = [ tf.id for tf in (filter_form.exclude_taintflags.data or []) ] (since_date, to_date) = filter_form.daterange.data date_delta = to_date - since_date if date_delta < datetime.timedelta(days=16): resolution = "daily" elif date_delta < datetime.timedelta(weeks=10): resolution = "weekly" else: resolution = "monthly" hist_table, hist_field = get_history_target(resolution) probable_fix_osr_ids = [ osr.id for osr in (filter_form.probable_fix_osrs.data or []) ] p = query_problems( db, hist_table, opsysrelease_ids, component_ids, associate_id, arch_ids, exclude_taintflag_ids, types, lambda query: (query.filter(hist_field >= since_date).filter(hist_field <= to_date)), function_names=filter_form.function_names.data, binary_names=filter_form.binary_names.data, source_file_names=filter_form.source_file_names.data, since_version=filter_form.since_version.data, since_release=filter_form.since_release.data, to_version=filter_form.to_version.data, to_release=filter_form.to_release.data, probable_fix_osr_ids=probable_fix_osr_ids, bug_filter=filter_form.bug_filter.data, limit=pagination.limit, offset=pagination.offset, solution=filter_form.solution) return p
def get_problems(filter_form, pagination): opsysrelease_ids = [ osr.id for osr in (filter_form.opsysreleases.data or [])] component_ids = component_names_to_ids(filter_form.component_names.data) if filter_form.associate.data: associate_id = filter_form.associate.data.id else: associate_id = None arch_ids = [arch.id for arch in (filter_form.arch.data or [])] types = filter_form.type.data or [] exclude_taintflag_ids = [ tf.id for tf in (filter_form.exclude_taintflags.data or [])] (since_date, to_date) = filter_form.daterange.data date_delta = to_date - since_date if date_delta < datetime.timedelta(days=16): resolution = "daily" elif date_delta < datetime.timedelta(weeks=10): resolution = "weekly" else: resolution = "monthly" hist_table, hist_field = get_history_target(resolution) probable_fix_osr_ids = [ osr.id for osr in (filter_form.probable_fix_osrs.data or [])] p = query_problems(db, hist_table, opsysrelease_ids, component_ids, associate_id, arch_ids, exclude_taintflag_ids, types, lambda query: ( query.filter(hist_field >= since_date) .filter(hist_field <= to_date)), function_names=filter_form.function_names.data, binary_names=filter_form.binary_names.data, source_file_names=filter_form.source_file_names.data, since_version=filter_form.since_version.data, since_release=filter_form.since_release.data, to_version=filter_form.to_version.data, to_release=filter_form.to_release.data, probable_fix_osr_ids=probable_fix_osr_ids, bug_filter=filter_form.bug_filter.data, limit=pagination.limit, offset=pagination.offset, solution=filter_form.solution) return p