@@ -555,58 +555,42 @@ def generate_plugin_releases():
555
555
f (redis_key , v )
556
556
557
557
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.
561
560
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.
565
565
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
571
568
572
- for col_name in res :
573
- col_name_list . append ( col_name [ 1 ] )
569
+ """
570
+ time = datetime . now (). strftime ( '%m-%d-%y' )
574
571
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 ()
578
577
578
+ # Retreave available software
579
+ software_list = list (qdb .software .Software .iter (active = active ))
580
+ scommands = {}
579
581
for software in software_list :
580
582
sname = software .name
581
583
sversion = software .version
582
584
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 ] = {}
605
587
606
- """
607
- time = datetime . now (). strftime ( '%m-%d-%y' )
588
+ if sversion not in scommands [ sname ]:
589
+ scommands [ sname ][ sversion ] = {}
608
590
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
610
594
611
595
redis_key = 'resources:commands'
612
596
r_client .set (redis_key , str (scommands ))
@@ -615,38 +599,41 @@ def update_resource_allocation_redis(active=True):
615
599
for version , commands in versions .items ():
616
600
for cname , col_name_list in commands .items ():
617
601
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 " +
624
604
f" software: { sname } " +
625
605
f" version: { version } " +
626
606
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 } " ))
627
613
continue
628
614
# column_name_str looks like col1*col2*col3, etc
629
615
for col_name_str in col_name_list :
630
- df_copy = df .copy ()
631
616
new_column = None
632
617
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 )
634
619
635
620
# Create a column with the desired columns
636
621
for curr_column in col_name_split :
637
622
if new_column is None :
638
623
new_column = df_copy [curr_column ]
639
624
else :
640
625
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 } " ))
646
632
647
633
fig , axs = resource_allocation_plot (df_copy ,
648
634
col_name_str ,
649
- new_column )
635
+ new_column ,
636
+ verbose = verbose )
650
637
titles = [0 , 0 ]
651
638
images = [0 , 0 ]
652
639
@@ -697,11 +684,12 @@ def update_resource_allocation_redis(active=True):
697
684
("title_mem" , titles [0 ], r_client .set ),
698
685
("title_time" , titles [1 ], r_client .set )
699
686
]
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 } " ))
705
693
706
694
for k , v , f in values :
707
695
redis_key = 'resources$#%s$#%s$#%s$#%s:%s' % (
0 commit comments