def report(request): from sentry.tasks import reports random = get_random(request) duration = 60 * 60 * 24 * 7 timestamp = to_timestamp( reports.floor_to_utc_day( to_datetime( random.randint( to_timestamp(datetime(2015, 6, 1, 0, 0, 0, tzinfo=timezone.utc)), to_timestamp(datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), ) ) ) ) start, stop = interval = reports._to_interval(timestamp, duration) organization = Organization(id=1, slug="example", name="Example") projects = [] for i in xrange(0, random.randint(1, 8)): name = " ".join(random.sample(loremipsum.words, random.randint(1, 4))) projects.append( Project( id=i, organization=organization, slug=slugify(name), name=name, date_added=start - timedelta(days=random.randint(0, 120)), ) ) def make_release_generator(): id_sequence = itertools.count(1) while True: dt = to_datetime(random.randint(timestamp - (30 * 24 * 60 * 60), timestamp)) p = random.choice(projects) yield Release( id=next(id_sequence), project=p, organization_id=p.organization_id, version="".join([random.choice("0123456789abcdef") for _ in range(40)]), date_added=dt, ) def build_issue_summaries(): summaries = [] for i in range(3): summaries.append(int(random.weibullvariate(10, 1) * random.paretovariate(0.5))) return summaries def build_usage_summary(): return ( int(random.weibullvariate(3, 1) * random.paretovariate(0.2)), int(random.weibullvariate(5, 1) * random.paretovariate(0.2)), ) def build_calendar_data(project): start, stop = reports.get_calendar_query_range(interval, 3) rollup = 60 * 60 * 24 series = [] weekend = frozenset((5, 6)) value = int(random.weibullvariate(5000, 3)) for timestamp in tsdb.get_optimal_rollup_series(start, stop, rollup)[1]: damping = random.uniform(0.2, 0.6) if to_datetime(timestamp).weekday in weekend else 1 jitter = random.paretovariate(1.2) series.append((timestamp, int(value * damping * jitter))) value = value * random.uniform(0.25, 2) return reports.clean_calendar_data(project, series, start, stop, rollup, stop) def build_report(project): daily_maximum = random.randint(1000, 10000) rollup = 60 * 60 * 24 series = [ ( timestamp + (i * rollup), (random.randint(0, daily_maximum), random.randint(0, daily_maximum)), ) for i in xrange(0, 7) ] aggregates = [ random.randint(0, daily_maximum * 7) if random.random() < 0.9 else None for _ in xrange(0, 4) ] return reports.Report( series, aggregates, build_issue_summaries(), build_usage_summary(), build_calendar_data(project), ) if random.random() < 0.85: personal = {"resolved": random.randint(0, 100), "users": int(random.paretovariate(0.2))} else: personal = {"resolved": 0, "users": 0} return MailPreview( html_template="sentry/emails/reports/body.html", text_template="sentry/emails/reports/body.txt", context={ "duration": reports.durations[duration], "interval": {"start": reports.date_format(start), "stop": reports.date_format(stop)}, "report": reports.to_context( organization, interval, {project: build_report(project) for project in projects} ), "organization": organization, "personal": personal, "user": request.user, }, ).render(request)
def report(request): from sentry.tasks import reports random = get_random(request) duration = 60 * 60 * 24 * 7 timestamp = random.randint( to_timestamp(datetime(2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc)), to_timestamp(datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), ) organization = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=organization, ) project = Project( id=1, organization=organization, team=team, slug='project', name='My Project', ) start, stop = reports._to_interval(timestamp, duration) group_instances = {} def fetch_group_instances(id_list): results = {} for id in id_list: instance = group_instances.get(id) if instance is not None: results[id] = instance return results def make_group_id_generator(): group_generator = make_group_generator(random, project) while True: group = next(group_generator) if random.random() < 0.95: group_instances[group.id] = group yield group.id group_id_sequence = make_group_id_generator() def make_release_generator(): id_sequence = itertools.count(1) while True: dt = to_datetime( random.randint( timestamp - (30 * 24 * 60 * 60), timestamp, ), ) yield Release( id=next(id_sequence), project=project, version=''.join([ random.choice('0123456789abcdef') for _ in range(40) ]), date_added=dt, date_started=dt, ) release_instances = {} def make_release_id_generator(): release_generator = make_release_generator() while True: release = next(release_generator) release_instances[release.id] = release yield release.id release_id_generator = make_release_id_generator() def build_issue_list(): summaries = [] for i in range(3): summaries.append( int(random.weibullvariate(10, 1) * random.paretovariate(0.5)) ) return summaries, [( next(group_id_sequence), ( int(random.paretovariate(0.3)), int(random.paretovariate(0.3)), ), ) for _ in xrange(0, random.randint(1, 5))] def build_release_list(): return reports.trim_release_list([ ( next(release_id_generator), max(1, int(random.weibullvariate(20, 0.15))), ) for _ in range(random.randint(0, 10)) ]) def build_report(): daily_maximum = random.randint(1000, 10000) rollup = 60 * 60 * 24 series = [( timestamp + (i * rollup), (random.randint(0, daily_maximum), random.randint(0, daily_maximum)) ) for i in xrange(0, 7)] aggregates = [ random.randint(0, daily_maximum * 7) if random.random() < 0.9 else None for _ in xrange(0, 4) ] return series, aggregates, build_issue_list(), build_release_list() report = reduce( reports.merge_reports, [build_report() for _ in xrange(0, random.randint(1, 3))] ) if random.random() < 0.85: personal = { 'resolved': random.randint(0, 100), 'users': int(random.paretovariate(0.2)), } else: personal = { 'resolved': 0, 'users': 0, } return MailPreview( html_template='sentry/emails/reports/body.html', text_template='sentry/emails/reports/body.txt', context={ 'duration': reports.durations[duration], 'interval': { 'start': reports.date_format(start), 'stop': reports.date_format(stop), }, 'report': reports.to_context( report, fetch_group_instances, ), 'organization': organization, 'personal': personal, 'user': request.user, }, ).render(request)
def report(request): from sentry.tasks import reports random = get_random(request) duration = 60 * 60 * 24 * 7 timestamp = to_timestamp( reports.floor_to_utc_day( to_datetime( random.randint( to_timestamp(datetime(2015, 6, 1, 0, 0, 0, tzinfo=timezone.utc)), to_timestamp(datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), ) ) ) ) start, stop = interval = reports._to_interval(timestamp, duration) organization = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=organization, ) projects = [] for i in xrange(0, random.randint(1, 8)): name = ' '.join( random.sample( WORDS, random.randint(1, 4) ) ) projects.append( Project( id=i, organization=organization, team=team, slug=slugify(name), name=name, date_added=start - timedelta(days=random.randint(0, 120)), ) ) def make_release_generator(): id_sequence = itertools.count(1) while True: dt = to_datetime( random.randint( timestamp - (30 * 24 * 60 * 60), timestamp, ), ) yield Release( id=next(id_sequence), project=random.choice(projects), version=''.join([ random.choice('0123456789abcdef') for _ in range(40) ]), date_added=dt, date_started=dt, ) release_instances = {} def make_release_id_generator(): release_generator = make_release_generator() while True: release = next(release_generator) release_instances[release.id] = release yield release.id release_id_generator = make_release_id_generator() def build_issue_summaries(): summaries = [] for i in range(3): summaries.append( int(random.weibullvariate(10, 1) * random.paretovariate(0.5)) ) return summaries def build_release_list(): return reports.trim_release_list([ ( next(release_id_generator), max(1, int(random.weibullvariate(20, 0.15))), ) for _ in range(random.randint(0, 10)) ]) def build_usage_summary(): return ( int(random.weibullvariate(3, 1) * random.paretovariate(0.2)), int(random.weibullvariate(5, 1) * random.paretovariate(0.2)), ) def build_calendar_data(project): start, stop = reports.get_calendar_query_range(interval, 3) rollup = 60 * 60 * 24 series = [] weekend = frozenset((5, 6)) value = int(random.weibullvariate(5000, 3)) for timestamp in tsdb.get_optimal_rollup_series(start, stop, rollup)[1]: damping = random.uniform(0.2, 0.6) if to_datetime(timestamp).weekday in weekend else 1 jitter = random.paretovariate(1.2) series.append((timestamp, int(value * damping * jitter))) value = value * random.uniform(0.25, 2) return reports.clean_calendar_data( project, series, start, stop, rollup, stop ) def build_report(project): daily_maximum = random.randint(1000, 10000) rollup = 60 * 60 * 24 series = [( timestamp + (i * rollup), (random.randint(0, daily_maximum), random.randint(0, daily_maximum)) ) for i in xrange(0, 7)] aggregates = [ random.randint(0, daily_maximum * 7) if random.random() < 0.9 else None for _ in xrange(0, 4) ] return reports.Report( series, aggregates, build_issue_summaries(), build_release_list(), build_usage_summary(), build_calendar_data(project), ) if random.random() < 0.85: personal = { 'resolved': random.randint(0, 100), 'users': int(random.paretovariate(0.2)), } else: personal = { 'resolved': 0, 'users': 0, } return MailPreview( html_template='sentry/emails/reports/body.html', text_template='sentry/emails/reports/body.txt', context={ 'duration': reports.durations[duration], 'interval': { 'start': reports.date_format(start), 'stop': reports.date_format(stop), }, 'report': reports.to_context( organization, interval, {project: build_report(project) for project in projects} ), 'organization': organization, 'personal': personal, 'user': request.user, }, ).render(request)
def report(request): from sentry.tasks import reports random = get_random(request) duration = 60 * 60 * 24 * 7 timestamp = to_timestamp( reports.floor_to_utc_day( to_datetime( random.randint( to_timestamp(datetime(2015, 6, 1, 0, 0, 0, tzinfo=timezone.utc)), to_timestamp(datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), ) ) ) ) start, stop = interval = reports._to_interval(timestamp, duration) organization = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=organization, ) projects = [] for i in xrange(0, random.randint(1, 8)): name = ' '.join( random.sample( WORDS, random.randint(1, 4) ) ) projects.append( Project( id=i, organization=organization, team=team, slug=slugify(name), name=name, date_added=start - timedelta(days=random.randint(0, 120)), ) ) def make_release_generator(): id_sequence = itertools.count(1) while True: dt = to_datetime( random.randint( timestamp - (30 * 24 * 60 * 60), timestamp, ), ) p = random.choice(projects) yield Release( id=next(id_sequence), project=p, organization_id=p.organization_id, version=''.join([ random.choice('0123456789abcdef') for _ in range(40) ]), date_added=dt, date_started=dt, ) def build_issue_summaries(): summaries = [] for i in range(3): summaries.append( int(random.weibullvariate(10, 1) * random.paretovariate(0.5)) ) return summaries def build_usage_summary(): return ( int(random.weibullvariate(3, 1) * random.paretovariate(0.2)), int(random.weibullvariate(5, 1) * random.paretovariate(0.2)), ) def build_calendar_data(project): start, stop = reports.get_calendar_query_range(interval, 3) rollup = 60 * 60 * 24 series = [] weekend = frozenset((5, 6)) value = int(random.weibullvariate(5000, 3)) for timestamp in tsdb.get_optimal_rollup_series(start, stop, rollup)[1]: damping = random.uniform(0.2, 0.6) if to_datetime(timestamp).weekday in weekend else 1 jitter = random.paretovariate(1.2) series.append((timestamp, int(value * damping * jitter))) value = value * random.uniform(0.25, 2) return reports.clean_calendar_data( project, series, start, stop, rollup, stop ) def build_report(project): daily_maximum = random.randint(1000, 10000) rollup = 60 * 60 * 24 series = [( timestamp + (i * rollup), (random.randint(0, daily_maximum), random.randint(0, daily_maximum)) ) for i in xrange(0, 7)] aggregates = [ random.randint(0, daily_maximum * 7) if random.random() < 0.9 else None for _ in xrange(0, 4) ] return reports.Report( series, aggregates, build_issue_summaries(), build_usage_summary(), build_calendar_data(project), ) if random.random() < 0.85: personal = { 'resolved': random.randint(0, 100), 'users': int(random.paretovariate(0.2)), } else: personal = { 'resolved': 0, 'users': 0, } return MailPreview( html_template='sentry/emails/reports/body.html', text_template='sentry/emails/reports/body.txt', context={ 'duration': reports.durations[duration], 'interval': { 'start': reports.date_format(start), 'stop': reports.date_format(stop), }, 'report': reports.to_context( organization, interval, {project: build_report(project) for project in projects} ), 'organization': organization, 'personal': personal, 'user': request.user, }, ).render(request)
def report(request): from sentry.tasks import reports random = get_random(request) duration = 60 * 60 * 24 * 7 timestamp = random.randint( to_timestamp(datetime(2016, 6, 1, 0, 0, 0, tzinfo=timezone.utc)), to_timestamp(datetime(2016, 7, 1, 0, 0, 0, tzinfo=timezone.utc)), ) organization = Organization( id=1, slug='example', name='Example', ) team = Team( id=1, slug='example', name='Example', organization=organization, ) projects = [] for i in xrange(0, random.randint(1, 8)): name = ' '.join( random.sample( WORDS, random.randint(1, 4) ) ) projects.append( Project( id=i, organization=organization, team=team, slug=slugify(name), name=name, ) ) start, stop = reports._to_interval(timestamp, duration) def make_release_generator(): id_sequence = itertools.count(1) while True: dt = to_datetime( random.randint( timestamp - (30 * 24 * 60 * 60), timestamp, ), ) yield Release( id=next(id_sequence), project=random.choice(projects), version=''.join([ random.choice('0123456789abcdef') for _ in range(40) ]), date_added=dt, date_started=dt, ) release_instances = {} def make_release_id_generator(): release_generator = make_release_generator() while True: release = next(release_generator) release_instances[release.id] = release yield release.id release_id_generator = make_release_id_generator() def build_issue_summaries(): summaries = [] for i in range(3): summaries.append( int(random.weibullvariate(10, 1) * random.paretovariate(0.5)) ) return summaries def build_release_list(): return reports.trim_release_list([ ( next(release_id_generator), max(1, int(random.weibullvariate(20, 0.15))), ) for _ in range(random.randint(0, 10)) ]) def build_usage_summary(): return ( int(random.weibullvariate(3, 1) * random.paretovariate(0.2)), int(random.weibullvariate(5, 1) * random.paretovariate(0.2)), ) def build_report(): daily_maximum = random.randint(1000, 10000) rollup = 60 * 60 * 24 series = [( timestamp + (i * rollup), (random.randint(0, daily_maximum), random.randint(0, daily_maximum)) ) for i in xrange(0, 7)] aggregates = [ random.randint(0, daily_maximum * 7) if random.random() < 0.9 else None for _ in xrange(0, 4) ] return series, aggregates, build_issue_summaries(), build_release_list(), build_usage_summary() if random.random() < 0.85: personal = { 'resolved': random.randint(0, 100), 'users': int(random.paretovariate(0.2)), } else: personal = { 'resolved': 0, 'users': 0, } return MailPreview( html_template='sentry/emails/reports/body.html', text_template='sentry/emails/reports/body.txt', context={ 'duration': reports.durations[duration], 'interval': { 'start': reports.date_format(start), 'stop': reports.date_format(stop), }, 'report': reports.to_context( {project: build_report() for project in projects} ), 'organization': organization, 'personal': personal, 'user': request.user, }, ).render(request)