@@ -50,7 +50,8 @@ async def index():
5050 if request .method == 'PUT' :
5151
5252 data = request .get_json ()
53- arq_job = await redis .enqueue_job ("cache_plots" , data ['repo' ], data ['collection' ])
53+ arq_job = await redis .enqueue_job ("cache_plots" , data ['repo' ], data ['collection' ],
54+ data .get ("filter_collections" , False ))
5455 return jsonify ({"jobId" : arq_job .job_id })
5556
5657 else :
@@ -71,12 +72,32 @@ async def job(job_id):
7172 return jsonify ({"status" : await arq_job .status (),
7273 "result" : job_result .result if job_result is not None else "" })
7374
74- async def cache_plots (ctx , repo , collection ):
75+ async def cache_plots (ctx , repo , collection , filter_collections = False ):
76+ """
77+ Generate the plot cache file and write it to S3.
78+
79+ Parameters
80+ ----------
81+ repo : string
82+ Butler repository
83+
84+ collection : string
85+ Butler collection to search for plots.
86+
87+ filter_collections : bool, optional
88+ Only include plots in run collections named with the same prefix as `collection`.
89+
90+ Returns
91+ -------
92+ string
93+ Success or error message.
94+ """
7595
7696 butler = dafButler .Butler (repo )
7797
7898 try :
79- summary = summarize_collection (butler , collection )
99+ summary = summarize_collection (butler , collection ,
100+ filter_prefix = collection if apply_filter else "" )
80101 except dafButler .MissingCollectionError as e :
81102 return f"Error: { e } "
82103
@@ -107,7 +128,7 @@ class Worker:
107128 password = os .getenv ("REDIS_PASSWORD" ))
108129
109130
110- def summarize_collection (butler , collection_name ):
131+ def summarize_collection (butler , collection_name , filter_prefix = "" ):
111132
112133 out = {}
113134
@@ -121,21 +142,24 @@ def summarize_collection(butler, collection_name):
121142 tract_datasets = list (butler .registry .queryDatasets (tract_plot_types , collections = collection_name , findFirst = True ))
122143 out ['tracts' ] = {}
123144 for plot_type in tract_plot_types :
124- ref_dicts = [{"dataId" : json .dumps (dict (datasetRef .dataId .mapping )), "id" : str (datasetRef .id )} for datasetRef in tract_datasets if datasetRef .datasetType == plot_type ]
145+ ref_dicts = [{"dataId" : json .dumps (dict (datasetRef .dataId .mapping )), "id" : str (datasetRef .id )} for datasetRef in tract_datasets
146+ if datasetRef .datasetType == plot_type and datasetRef .run .startswith (filter_prefix )]
125147 if (len (ref_dicts ) > 0 ):
126148 out ['tracts' ][plot_type .name ] = ref_dicts
127149
128150 visit_datasets = list (butler .registry .queryDatasets (visit_plot_types , collections = collection_name , findFirst = True ))
129151 out ['visits' ] = {}
130152 for plot_type in visit_plot_types :
131- ref_dicts = [{"dataId" : json .dumps (dict (datasetRef .dataId .mapping )), "id" : str (datasetRef .id )} for datasetRef in visit_datasets if datasetRef .datasetType == plot_type ]
153+ ref_dicts = [{"dataId" : json .dumps (dict (datasetRef .dataId .mapping )), "id" : str (datasetRef .id )} for datasetRef in visit_datasets
154+ if datasetRef .datasetType == plot_type and datasetRef .run .startswith (filter_prefix )]
132155 if (len (ref_dicts ) > 0 ):
133156 out ['visits' ][plot_type .name ] = ref_dicts
134157
135158 global_datasets = list (butler .registry .queryDatasets (global_plot_types , collections = collection_name , findFirst = True ))
136159 out ['global' ] = {}
137160 for plot_type in global_plot_types :
138- ref_dicts = [{"dataId" : json .dumps (dict (datasetRef .dataId .mapping )), "id" : str (datasetRef .id )} for datasetRef in global_datasets if datasetRef .datasetType == plot_type ]
161+ ref_dicts = [{"dataId" : json .dumps (dict (datasetRef .dataId .mapping )), "id" : str (datasetRef .id )} for datasetRef in global_datasets
162+ if datasetRef .datasetType == plot_type and datasetRef .run .startswith (filter_prefix )]
139163 if (len (ref_dicts ) > 0 ):
140164 out ['global' ][plot_type .name ] = ref_dicts
141165
0 commit comments