1
= Using datetime to generate a partial OOPS summary =
3
OOPS summaries can be generated for a shorter period of time than a day.
5
>>> from oopstools.oops.helpers import generate_summary, load_database
7
>>> from datetime import datetime
8
>>> start_date = datetime(2007, 11, 20, 11, 55, 0)
9
>>> end_date = datetime(2007, 11, 20, 12, 20, 0)
11
Before generating the summary, let's load the sample data into the database.
13
>>> load_database(start_date.date(), end_date.date())
14
'Oopses loaded into the database.'
16
Now let's generate it.
18
>>> webapp_summary = generate_summary(
19
... prefixes, from_date=start_date, to_date=end_date)
21
And check that we get only OOPSes that happen during the 35m period requested.
23
>>> from oopstools.oops.helpers import get_section_contents
24
>>> print get_section_contents("Statistics", webapp_summary)
26
* Analyzed period: ...
32
* 0 Informational Only Errors
33
* 0 User Generated Errors
34
* 0 Unauthorized Errors
37
>>> print get_section_contents("All Soft Time Outs", webapp_summary)
38
1 SELECT product, ... question_count DESC LIMIT $INT:
39
Other: 1 Robots: 1 Local: 1
40
1 https://answers.staging.launchpad.net/questions/+index (FooBar:+questions)
43
Demonstrate that there are more OOPS reports for the day (one was reported, so
44
> 1 need to exist to show the report did limit what it showed).
46
>>> from datetime import timedelta
47
>>> from oopstools.oops.models import Oops
48
>>> for oops in Oops.objects.filter(date__gte=start_date.date(),
49
... date__lt=end_date.date() + timedelta(days=1),
50
... prefix__value__in=prefixes).order_by('date'):
51
... print oops, oops.date
52
OOPS-689S4 2007-11-20 12:00:31
53
OOPS-689S6 2007-11-20 12:31:24
55
And reset the database.
57
>>> from oopstools.oops.helpers import reset_database
59
'Oops, DBOopsRootDirectory and Infestation deleted.'