1414import logfilters
1515import analyticsstructures
1616import analyticsexplorer
17-
18- #TODO - split this file into analyticsexplorer.py and analyticsstructures.py
17+ import uuid
18+ from time import sleep
19+ import uuidmgr
1920
2021def analytics_loader (stdscr ,serverdir ):
2122 telemetry .telemetric_action ("analytics" )
2223 if uicomponents .resource_warning (stdscr ):
2324 return
2425 renaminghandler .autoupdate_cache (stdscr ,serverdir )
26+ uuidmgr .load_from_logs (stdscr ,serverdir )
27+
2528 analytics_file_path = serverdir + os .sep + "anacache.json.gz"
2629 cursesplus .displaymsg (stdscr ,["Loading from cache..." ],False )
2730 readfrom = datetime .datetime (2000 ,1 ,1 ,0 ,0 ,0 )
@@ -129,6 +132,7 @@ def analytics_loader(stdscr,serverdir):
129132
130133 for k in final :
131134 final [k ].onlineplayers = utils .remove_duplicates_from_list (final [k ].onlineplayers )
135+ final [k ].onlineplayers = utils .recursive_remove_if_contains (final [k ].onlineplayers ,["\" " ,"{" ,"/" ])
132136
133137 #Find last zeroed time to store in cache
134138 storeto = analyticsstructures .get_minute_id_from_datetime (readfrom )#By default, store none. Then, try to find the last zero point
@@ -297,7 +301,7 @@ def analytics_loader(stdscr,serverdir):
297301 elif wtd == 10 :
298302 plf = 0
299303 cursesplus .displaymsg (stdscr ,["Analyzing data" ,f"{ plf } players found" ],False )
300- sortop = uicomponents .menu (stdscr ,["Alphabetically" ,"Recent -> Old" ],"Choose search option" )
304+ sortop = uicomponents .menu (stdscr ,["Alphabetically" ,"Recent -> Old" , "Export UUIDs" ],"Choose search option or data option" )
301305 fjblock :dict [str ,datetime .datetime ] = {}
302306 for line in reversed (list (workingdata .values ())):
303307 for pl in line .onlineplayers :
@@ -306,6 +310,10 @@ def analytics_loader(stdscr,serverdir):
306310 plf += 1
307311 cursesplus .displaymsg (stdscr ,["Analyzing data" ,f"{ plf } players found" ],False )
308312
313+ if sortop == 2 :
314+ do_date_based_uuid_export (stdscr ,fjblock )
315+ continue
316+
309317 if sortop == 0 :
310318 fjblock = dict (sorted (fjblock .items ()))#Sort A-Z
311319
@@ -318,7 +326,7 @@ def analytics_loader(stdscr,serverdir):
318326 elif wtd == 11 :
319327 plf = 0
320328 cursesplus .displaymsg (stdscr ,["Analyzing data" ,f"{ plf } players found" ],False )
321- sortop = uicomponents .menu (stdscr ,["Alphabetically" ,"Oldest to newest" ],"Choose search option" )
329+ sortop = uicomponents .menu (stdscr ,["Alphabetically" ,"Oldest to newest" , "Export UUIDs" ],"Choose search option or data option" )
322330 fjblock :dict [str ,datetime .datetime ] = {}
323331 for line in list (workingdata .values ()):
324332 for pl in line .onlineplayers :
@@ -327,6 +335,10 @@ def analytics_loader(stdscr,serverdir):
327335 plf += 1
328336 cursesplus .displaymsg (stdscr ,["Analyzing data" ,f"{ plf } players found" ],False )
329337
338+ if sortop == 2 :
339+ do_date_based_uuid_export (stdscr ,fjblock )
340+ continue
341+
330342 if sortop == 0 :
331343 fjblock = dict (sorted (fjblock .items ()))#Sort A-Z
332344
@@ -342,4 +354,43 @@ def analytics_loader(stdscr,serverdir):
342354 cursesplus .messagebox .showinfo (stdscr ,["The analytics cache has been reset." ])
343355 return
344356
357+ def do_date_based_uuid_export (stdscr ,vals :dict [str ,datetime .datetime ]) -> None :
358+ """Produces and writes a file. Each line is one user. First block before space is uuid. All names are built to handle name changes"""
359+ cursesplus .displaymsg (stdscr ,["Please wait..." ],False )
345360
361+ tempresult :dict [str ,int ] = {}
362+
363+ for kvpair in list (vals .items ()):
364+ latest_uname = renaminghandler .get_current_name_of (kvpair [0 ])
365+ tempresult [latest_uname ] = int (kvpair [1 ].timestamp ())
366+
367+ cursesplus .displaymsg (stdscr ,["It is now time to convert names into UUIDs" ,"They will be processed at 1/second max" ,"Press enter to proceed." ])
368+
369+ result :dict [str ,int ] = {}
370+ all_items = list (tempresult .items ())
371+
372+ pbar = cursesplus .ProgressBar (stdscr ,len (all_items ),bar_type = cursesplus .ProgressBarTypes .FullScreenProgressBar ,show_log = True ,message = "Loading UUIDs" )
373+
374+ while len (all_items ) > 0 :
375+
376+ selitem = all_items .pop ()
377+ mresult = uuidmgr .get_uuid_from_name (selitem [0 ])
378+ if mresult == "" :
379+ continue
380+
381+ cursesplus .displaymsg (stdscr ,[f"{ len (all_items )} remaining" ],False )
382+ result [str (mresult )] = selitem [1 ]
383+ pbar .step (f"{ selitem [0 ]} -> { mresult } " ,True )
384+
385+ pbar .done ()
386+
387+
388+ outfile = cursesplus .savefile_selector (stdscr )
389+ with open (outfile ,"w+" ) as f :
390+ for resitem in list (result .items ()):
391+ f .write (resitem [0 ])
392+ f .write (" " )
393+ f .write (str (resitem [1 ]))
394+ f .write ("\n " )
395+
396+ cursesplus .messagebox .showinfo (stdscr ,["Saved successfully" ])
0 commit comments