@@ -555,58 +555,42 @@ def generate_plugin_releases():
555555 f (redis_key , v )
556556
557557
558- def _build_software_commands_col_names_object (active ):
559- '''
560- Helper function for update_resource_allocation_redis
558+ def update_resource_allocation_redis (active = True , verbose = False ):
559+ """Updates redis with plots and information about current software.
561560
562- Constructs a nested dictionary containing software commands and associated
563- column names from the database.
564- '''
561+ Parameters
562+ ----------
563+ active: boolean, optional
564+ Defaults to True. Should only be False when testing.
565565
566- col_name_list = []
567- with qdb .sql_connection .TRN :
568- sql = ''' SELECT * FROM qiita.resource_allocation_column_names; '''
569- qdb .sql_connection .TRN .add (sql )
570- res = qdb .sql_connection .TRN .execute_fetchindex ()
566+ verbose: boolean, optional
567+ Defaults to False. Prints status on what functin
571568
572- for col_name in res :
573- col_name_list . append ( col_name [ 1 ] )
569+ """
570+ time = datetime . now (). strftime ( '%m-%d-%y' )
574571
575- software_list = [s for s in qdb .software .Software .iter (active = active )]
576- software_commands = defaultdict (lambda : defaultdict (
577- lambda : defaultdict (list )))
572+ # Retreave available col_name for commands
573+ with qdb .sql_connection .TRN :
574+ sql = 'SELECT col_name FROM qiita.resource_allocation_column_names;'
575+ qdb .sql_connection .TRN .add (sql )
576+ col_names_list = qdb .sql_connection .TRN .execute_fetchflatten ()
578577
578+ # Retreave available software
579+ software_list = list (qdb .software .Software .iter (active = active ))
580+ scommands = {}
579581 for software in software_list :
580582 sname = software .name
581583 sversion = software .version
582584
583- for command in software .commands :
584- cmd_name = command .name
585- for col in col_name_list :
586- software_commands [sname ][sversion ][cmd_name ].append (col )
587-
588- final_obj = {
589- sname : {
590- sversion : dict (commands )
591- for sversion , commands in dict (versions ).items ()
592- }
593- for sname , versions in dict (software_commands ).items ()
594- }
595- return final_obj
596-
597-
598- def update_resource_allocation_redis (active = True ):
599- """Updates redis with plots and information about current software.
600-
601- Parameters
602- ----------
603- active: boolean, optional
604- Defaults to True. Should only be False when testing.
585+ if sname not in scommands :
586+ scommands [sname ] = {}
605587
606- """
607- time = datetime . now (). strftime ( '%m-%d-%y' )
588+ if sversion not in scommands [ sname ]:
589+ scommands [ sname ][ sversion ] = {}
608590
609- scommands = _build_software_commands_col_names_object (active )
591+ for command in software .commands :
592+ cmd_name = command .name
593+ scommands [sname ][sversion ][cmd_name ] = col_names_list
610594
611595 redis_key = 'resources:commands'
612596 r_client .set (redis_key , str (scommands ))
@@ -615,38 +599,41 @@ def update_resource_allocation_redis(active=True):
615599 for version , commands in versions .items ():
616600 for cname , col_name_list in commands .items ():
617601 df = retrieve_resource_data (cname , sname , version , COLUMNS )
618- print (("Retrieving allocation resources for " +
619- f" software: { sname } " +
620- f" version: { version } " +
621- f" command: { cname } " ))
622- if len (df ) == 0 :
623- print (("No allocation resources available for" +
602+ if verbose :
603+ print (("Retrieving allocation resources for " +
624604 f" software: { sname } " +
625605 f" version: { version } " +
626606 f" command: { cname } " ))
607+ if len (df ) == 0 :
608+ if verbose :
609+ print (("No allocation resources available for" +
610+ f" software: { sname } " +
611+ f" version: { version } " +
612+ f" command: { cname } " ))
627613 continue
628614 # column_name_str looks like col1*col2*col3, etc
629615 for col_name_str in col_name_list :
630- df_copy = df .copy ()
631616 new_column = None
632617 col_name_split = col_name_str .split ('*' )
633- df_copy .dropna (subset = col_name_split , inplace = True )
618+ df_copy = df .dropna (subset = col_name_split )
634619
635620 # Create a column with the desired columns
636621 for curr_column in col_name_split :
637622 if new_column is None :
638623 new_column = df_copy [curr_column ]
639624 else :
640625 new_column *= df_copy [curr_column ]
641- print (("Building resource allocation plot for " +
642- f" software: { sname } " +
643- f" version: { version } " +
644- f" command: { cname } " +
645- f" column name: { col_name_str } " ))
626+ if verbose :
627+ print (("Building resource allocation plot for " +
628+ f" software: { sname } " +
629+ f" version: { version } " +
630+ f" command: { cname } " +
631+ f" column name: { col_name_str } " ))
646632
647633 fig , axs = resource_allocation_plot (df_copy ,
648634 col_name_str ,
649- new_column )
635+ new_column ,
636+ verbose = verbose )
650637 titles = [0 , 0 ]
651638 images = [0 , 0 ]
652639
@@ -697,11 +684,12 @@ def update_resource_allocation_redis(active=True):
697684 ("title_mem" , titles [0 ], r_client .set ),
698685 ("title_time" , titles [1 ], r_client .set )
699686 ]
700- print (("Saving resource allocation image for " +
701- f" software: { sname } " +
702- f" version: { version } " +
703- f" command: { cname } " +
704- f" column name: { col_name_str } " ))
687+ if verbose :
688+ print (("Saving resource allocation image for " +
689+ f" software: { sname } " +
690+ f" version: { version } " +
691+ f" command: { cname } " +
692+ f" column name: { col_name_str } " ))
705693
706694 for k , v , f in values :
707695 redis_key = 'resources$#%s$#%s$#%s$#%s:%s' % (
0 commit comments