40
40
import emission .storage .decorations .stats_queries as esds
41
41
42
42
import emission .core .wrapper .user as ecwu
43
+ import emission .analysis .result .user_stat as eaurs
43
44
44
45
def run_intake_pipeline (process_number , uuid_list , skip_if_no_new_data = False ):
45
46
"""
@@ -202,83 +203,7 @@ def run_intake_pipeline_for_user(uuid, skip_if_no_new_data):
202
203
with ect .Timer () as gsr :
203
204
logging .info ("*" * 10 + "UUID %s: storing user stats " % uuid + "*" * 10 )
204
205
print (str (arrow .now ()) + "*" * 10 + "UUID %s: storing user stats " % uuid + "*" * 10 )
205
- _get_and_store_range (uuid , "analysis/composite_trip" )
206
+ eaurs . get_and_store_user_stats (uuid , "analysis/composite_trip" )
206
207
207
208
esds .store_pipeline_time (uuid , 'STORE_USER_STATS' ,
208
- time .time (), gsr .elapsed )
209
-
210
- def _get_and_store_range (user_id , trip_key ):
211
- """
212
- Extends the user profile with pipeline_range, total_trips, labeled_trips, and last_call.
213
-
214
- Parameters:
215
- - user_id (str): The UUID of the user.
216
- - trip_key (str): The key representing the trip data in the time series.
217
- """
218
- time_format = 'YYYY-MM-DD HH:mm:ss'
219
- try :
220
- logging .info (f"Starting _get_and_store_range for user_id: { user_id } , trip_key: { trip_key } " )
221
-
222
- # Fetch the time series for the user
223
- ts = esta .TimeSeries .get_time_series (user_id )
224
- logging .debug ("Fetched time series data." )
225
-
226
- # Get start timestamp
227
- start_ts = ts .get_first_value_for_field (trip_key , "data.start_ts" , pymongo .ASCENDING )
228
- start_ts = None if start_ts == - 1 else start_ts
229
- logging .debug (f"Start timestamp: { start_ts } " )
230
-
231
- # Get end timestamp
232
- end_ts = ts .get_first_value_for_field (trip_key , "data.end_ts" , pymongo .DESCENDING )
233
- end_ts = None if end_ts == - 1 else end_ts
234
- logging .debug (f"End timestamp: { end_ts } " )
235
-
236
- # Retrieve trip entries
237
- total_trips = ts .find_entries_count (
238
- key_list = ["analysis/confirmed_trip" ],
239
- )
240
-
241
- labeled_trips = ts .find_entries_count (
242
- key_list = ["analysis/confirmed_trip" ],
243
- extra_query_list = [{'data.user_input' : {'$ne' : {}}}]
244
- )
245
-
246
- logging .info (f"Total trips: { total_trips } , Labeled trips: { labeled_trips } " )
247
- logging .info (type (user_id ))
248
- logging .debug ("Fetched API call statistics." )
249
-
250
- last_call_ts = ts .get_first_value_for_field (
251
- key = 'stats/server_api_time' ,
252
- field = 'data.ts' ,
253
- sort_order = pymongo .DESCENDING
254
- )
255
-
256
- logging .info (f"Last call timestamp: { last_call_ts } " )
257
-
258
- # Update the user profile with pipeline_range, total_trips, labeled_trips, and last_call
259
- user = ecwu .User .fromUUID (user_id )
260
- if last_call_ts != - 1 :
261
- # Format the timestamp using arrow
262
- formatted_last_call = arrow .get (last_call_ts ).format (time_format )
263
- # Assign using attribute access or the update method
264
- # Option 1: Attribute Assignment (if supported)
265
- # user.last_call = formatted_last_call
266
-
267
- # Option 2: Using the update method
268
- user .update ({
269
- "last_call" : formatted_last_call
270
- })
271
- user .update ({
272
- "pipeline_range" : {
273
- "start_ts" : start_ts ,
274
- "end_ts" : end_ts
275
- },
276
- "total_trips" : total_trips ,
277
- "labeled_trips" : labeled_trips ,
278
- "last_call" : last_call_ts
279
- })
280
- logging .debug ("User profile updated successfully." )
281
- logging .debug ("After updating, new profile is %s" , user .getProfile ())
282
-
283
- except Exception as e :
284
- logging .error (f"Error in _get_and_store_range for user_id { user_id } : { e } " )
209
+ time .time (), gsr .elapsed )
0 commit comments