This module defines the command for debugging a pipeline run, which prints out statistics and logging.
Command
Bases: BaseCommand
This script is used to debug data on specific pipeline run(s) or all. Use --help for usage.
Source code in vast_pipeline/management/commands/debugrun.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 | class Command(BaseCommand):
"""
This script is used to debug data on specific pipeline run(s) or all.
Use --help for usage.
"""
help = (
'Print out total metrics such as nr of measurements for runs'
)
def add_arguments(self, parser: ArgumentParser) -> None:
"""
Enables arguments for the command.
Args:
parser (ArgumentParser): The parser object of the command.
Returns:
None
"""
# positional arguments (required)
parser.add_argument(
'piperuns',
nargs='+',
type=str,
help=(
'Name or path of pipeline run(s) to debug.Pass "all" to'
' print summary data of all the runs.'
)
)
def handle(self, *args, **options) -> None:
"""
Handle function of the command.
Args:
*args: Variable length argument list.
**options: Variable length options.
Returns:
None
"""
piperuns = options['piperuns']
flag_all_runs = True if 'all' in piperuns else False
if flag_all_runs:
piperuns = list(Run.objects.values_list('name', flat=True))
print(' '.join(40 * ['*']))
for piperun in piperuns:
p_run_name = get_p_run_name(piperun)
try:
p_run = Run.objects.get(name=p_run_name)
except Run.DoesNotExist:
raise CommandError(f'Pipeline run {p_run_name} does not exist')
print(
f'Printing summary data of pipeline run "{p_run.name}"'
)
images = list(p_run.image_set.values_list('name', flat=True))
print(f'Nr of images: {len(images)}', )
print(
'Nr of measurements:',
Measurement.objects.filter(image__name__in=images).count()
)
print(
'Nr of forced measurements:',
(
Measurement.objects.filter(
image__name__in=images,
forced=True
)
.count()
)
)
sources = (
Source.objects.filter(run__name=p_run.name)
.values_list('id', flat=True)
)
print('Nr of sources:',len(sources))
print(
'Nr of association:',
Association.objects.filter(source_id__in=sources).count()
)
print(' '.join(40 * ['*']))
|
add_arguments(parser)
Enables arguments for the command.
Parameters:
Name | Type | Description | Default |
parser | ArgumentParser | The parser object of the command. | required |
Returns:
Source code in vast_pipeline/management/commands/debugrun.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 | def add_arguments(self, parser: ArgumentParser) -> None:
"""
Enables arguments for the command.
Args:
parser (ArgumentParser): The parser object of the command.
Returns:
None
"""
# positional arguments (required)
parser.add_argument(
'piperuns',
nargs='+',
type=str,
help=(
'Name or path of pipeline run(s) to debug.Pass "all" to'
' print summary data of all the runs.'
)
)
|
handle(*args, **options)
Handle function of the command.
Parameters:
Name | Type | Description | Default |
*args | | Variable length argument list. | () |
**options | | | {} |
Returns:
Source code in vast_pipeline/management/commands/debugrun.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 | def handle(self, *args, **options) -> None:
"""
Handle function of the command.
Args:
*args: Variable length argument list.
**options: Variable length options.
Returns:
None
"""
piperuns = options['piperuns']
flag_all_runs = True if 'all' in piperuns else False
if flag_all_runs:
piperuns = list(Run.objects.values_list('name', flat=True))
print(' '.join(40 * ['*']))
for piperun in piperuns:
p_run_name = get_p_run_name(piperun)
try:
p_run = Run.objects.get(name=p_run_name)
except Run.DoesNotExist:
raise CommandError(f'Pipeline run {p_run_name} does not exist')
print(
f'Printing summary data of pipeline run "{p_run.name}"'
)
images = list(p_run.image_set.values_list('name', flat=True))
print(f'Nr of images: {len(images)}', )
print(
'Nr of measurements:',
Measurement.objects.filter(image__name__in=images).count()
)
print(
'Nr of forced measurements:',
(
Measurement.objects.filter(
image__name__in=images,
forced=True
)
.count()
)
)
sources = (
Source.objects.filter(run__name=p_run.name)
.values_list('id', flat=True)
)
print('Nr of sources:',len(sources))
print(
'Nr of association:',
Association.objects.filter(source_id__in=sources).count()
)
print(' '.join(40 * ['*']))
|