1818 PageProjectAggregate ,
1919 UserAggregate ,
2020)
21+ from extlinks .aggregates .storage import (
22+ find_unique ,
23+ calculate_totals ,
24+ download_aggregates ,
25+ )
2126from extlinks .common .forms import FilterForm
2227from extlinks .common .helpers import (
2328 get_linksearchtotal_data_by_time ,
@@ -192,10 +197,16 @@ def _fill_chart_context(self, context, queryset_filter):
192197 existing_link_aggregates = {}
193198 eventstream_dates = []
194199 eventstream_net_change = []
195- current_date = date .today ()
196200 filtered_link_aggregate = LinkAggregate .objects .filter (queryset_filter )
197201 to_date = None
198202
203+ # Figure out what date the graph should end on.
204+ date_cursor = self .request .GET .get ("end_date" )
205+ if date_cursor :
206+ date_cursor = datetime .strptime (date_cursor , "%Y-%m-%d" ).date ()
207+ else :
208+ date_cursor = date .today ()
209+
199210 if filtered_link_aggregate .exists ():
200211 earliest_link_date = filtered_link_aggregate .earliest ("full_date" ).full_date
201212
@@ -207,7 +218,21 @@ def _fill_chart_context(self, context, queryset_filter):
207218 else :
208219 # No link information from that collection, so setting earliest_link_date
209220 # to the first of the current month
210- earliest_link_date = current_date .replace (day = 1 )
221+ earliest_link_date = date_cursor .replace (day = 1 )
222+
223+ links_aggregated_date = []
224+
225+ # Download aggregates from object storage and calculate totals grouped
226+ # by year and month.
227+ totals = calculate_totals (
228+ download_aggregates (
229+ prefix = "aggregates_linkaggregate" ,
230+ queryset_filter = queryset_filter ,
231+ to_date = to_date ,
232+ ),
233+ group_by = lambda record : (record ["year" ], record ["month" ]),
234+ )
235+ links_aggregated_date .extend (totals )
211236
212237 links_aggregated_date = []
213238
@@ -222,7 +247,7 @@ def _fill_chart_context(self, context, queryset_filter):
222247 group_by = lambda record : (record ["year" ], record ["month" ]),
223248 )
224249 links_aggregated_date .extend (totals )
225-
250+
226251 # Fetch remaining aggregates that are present in the database and
227252 # append them after the aggregates from the archives.
228253 links_aggregated_date .extend (
@@ -242,10 +267,10 @@ def _fill_chart_context(self, context, queryset_filter):
242267 earliest_link_date = full_date
243268
244269 # Filling an array of dates that should be in the chart
245- while current_date >= earliest_link_date :
246- dates .append (current_date .strftime ("%Y-%m" ))
270+ while date_cursor >= earliest_link_date :
271+ dates .append (date_cursor .strftime ("%Y-%m" ))
247272 # Figure out what the last month is regardless of today's date
248- current_date = current_date .replace (day = 1 ) - timedelta (days = 1 )
273+ date_cursor = date_cursor .replace (day = 1 ) - timedelta (days = 1 )
249274
250275 dates = dates [::- 1 ]
251276
0 commit comments