2525import os
2626import hashlib
2727import random
28+ from matplotlib .colors import to_hex
2829
2930if "RELMON_SA" in os .environ :
3031 from .dirstructure import Comparison ,Directory
@@ -85,6 +86,9 @@ def get_page_header(directory=None, standalone=False, additional_header=""):
8586 style_location = "http://cms-service-reldqm.web.cern.ch/" + style_location + "/"
8687 javascripts = ''
8788 style = ''
89+ tablestyle = ''
90+ thead_h = 400
91+ wrapper_h = 1500
8892 if directory != None and len (directory .comparisons )> 0 :
8993 meta = directory .meta
9094 style = 'img.fail {border:1px solid #ff0000;}\n ' + \
@@ -95,9 +99,23 @@ def get_page_header(directory=None, standalone=False, additional_header=""):
9599 'a.black_link:hover {color: #737373}\n ' + \
96100 'a.black_link:visited {color: #333333}\n ' + \
97101 'a.black_link:active {color: #333333}\n '
102+ ## fixed first row and first column table
103+
104+ wrapper_h = min (thead_h + (70 * len (directory .comparisons )),1800 )
105+
106+ tablestyle = '\n .wrapper { overflow: auto; height: %dpx;} \n ' % (wrapper_h )
107+ tablestyle += 'table { position: relative; border-collapse: separate; border-spacing: 0;} \n '
108+ tablestyle += 'table { position: relative; border-collapse: separate; border-spacing: 0;} \n '
109+ tablestyle += 'table th, table td { width: 50px; padding: 5px; background-color: white;} \n '
110+ tablestyle += 'table th { position: sticky; top: 0; z-index: 2; height: %dpx;} \n ' % (thead_h )
111+ tablestyle += 'table th:nth-child(1) { left:0; z-index:3;} \n '
112+ tablestyle += '.sticky-col { position: sticky; background-color: #C9FFD1 ; width: 200px; left:0}\n '
113+ tablestyle += '.center_head { position: absolute; top: 50%; left: 50%;} \n '
114+ tablestyle += '.vertical_head {top: 60%; -webkit-transform: translateX(-50%) translateY(-50%) rotate(-90deg); -moz-transform: translateX(-50%) translateY(-50%) rotate(-90deg);} \n '
98115 javascripts = ""
116+
99117
100-
118+
101119 html = '<html>' + \
102120 '<head>' + \
103121 '<title>RelMon Summary</title>' + \
@@ -108,6 +126,7 @@ def get_page_header(directory=None, standalone=False, additional_header=""):
108126 '<style type="text/css">' + \
109127 '.rotation {display: block;-webkit-transform: rotate(-90deg);-moz-transform: rotate(-90deg); }' + \
110128 '%s' % style + \
129+ '%s' % tablestyle + \
111130 '</style>' + \
112131 '%s' % javascripts + \
113132 '%s' % additional_header + \
@@ -125,10 +144,7 @@ def get_page_footer():
125144#-------------------------------------------------------------------------------
126145
127146def get_title_section (directory , hashing_flag , standalone , depth = 2 ):
128- if standalone :
129- cms_logo_url = "http://cms-service-reldqm.web.cern.ch/cms-service-reldqm/style/CMS.gif"
130- else :
131- cms_logo_url = "cms-service-reldqm/style/CMS.gif"
147+
132148 mother_name = basename (directory .mother_dir )
133149 mother_file_name = ""
134150 if depth == 1 :
@@ -214,7 +230,7 @@ def get_subdirs_section(directory, hashing_flag):
214230 html += '</div>'
215231
216232 html += '<div class="span-6 last">'
217- html += subdir .get_piechart_js (150 ,link )
233+ html += subdir .get_piechart_js (120 ,link )
218234 html += '</div>'
219235
220236 html += '<hr>'
@@ -265,7 +281,7 @@ def get_summary_section(directory,matrix_page=True):
265281 html += '</div>'
266282
267283 html += '<div class="span-7 colborder">' + \
268- '%s' % (directory .get_piechart_js (200 )) + \
284+ '%s' % (directory .get_piechart_js (150 )) + \
269285 '</div>' + \
270286 '<div class="span-9 last">'
271287 if matrix_page :
@@ -493,42 +509,33 @@ def directory2html(directory, hashing, standalone, depth=0):
493509
494510 #chdir(old_cwd)
495511
496- def to_rgba (t ):
497- ''' Convert a RGBA tuple to string'''
498- return "rgba(%f,%f,%f,%f)" % (t )
499-
500- def build_gauge_js (rate ,w = 100 ,minrate = .80 ):
512+ def build_gauge_js (rate ,w = 100 ,minrate = .80 ,add_rate = False ):
501513
502- color = to_rgba (gauge_cmap (rate - minrate ))
503- font_size = int (w / 5 )
504- text_offs = int (w / 8 )
514+ color = to_hex (gauge_cmap ((rate - minrate )/ (1.0 - minrate )))
515+ font_size = int (w / 9 )
505516 gauge_max = 1. - rate
506517
507518 name = random .getrandbits (64 ) # just a random has for the canvas
508519 html = ""
509- html += '<div style="width:100%%;max-width:%d; position: relative;">' % (w )
510- html += '<div style="width: 100%%; position: absolute; top: 75%%; margin-top: -%dpx; text-align: center;">' % (text_offs )
511- html += '<span style="color: %s; font-family: courier; font-size: %dpx;">%.2f%%</span>' % (color ,font_size ,rate * 100. )
512- html += '<canvas id="%s"></canvas>' % (name )
520+ html += '<canvas id="%s" style="width:100%%;max-width:%d"></canvas>' % (name ,w )
513521
514522 # "gauge" chart
515523 html += '<script> new Chart("%s",' % (name )
516524 html += '{ type: "doughnut",'
517525
518526 # data
519527 html += 'data: {'
520- html += 'datasets: [{ backgroundColor: ["%s", "rgba(0, 0, 0, 0.1)"],' % (color )
528+ html += 'labels: ["Success", "Failure"],'
529+ html += 'datasets: [{ backgroundColor: ["%s", "#C7C7C7"],' % (color )
521530 html += 'data: [%f,%f]}] },' % (rate ,gauge_max )
522531
523532 #options
524- html += 'options: { responsive: true, rotation: -90, circumference: 180 },'
525-
526- html += '}); </script> </div> </div>'
527-
528- print ("here" )
529-
530- img_link = "https://upload.wikimedia.org/wikipedia/commons/a/a8/Circle_Davys-Grey_Solid.svg"
531- html = '<img src="%s" title="%s" height=50 width=50>' % (img_link ,"test" )
533+ html += 'options: { responsive: true, rotation: -3.1415926536, circumference: 3.1415926536 ,' ## in radiants
534+ html += ' legend: { display: false }, tooltips: {enabled: false}, hover: {mode: null}},'
535+ html += '}); </script>'
536+ if add_rate :
537+ html += '<div style="width: 100%%; position: relative; left: %d; margin-top: -%dpx; font-align: center">' % (int (2 * w / 7 ),font_size )
538+ html += '<span style="color: %s; font-family: courier; font-size: %dpx;">%.2f%%</span></div>' % (color ,font_size ,rate * 100. )
532539
533540 return html
534541#-------------------------------------------------------------------------------
@@ -633,7 +640,7 @@ def make_categories_summary(dir_dict,aggregation_rules):
633640 html += '</div>'
634641
635642 html += '<div class="span-6 last">'
636- html += build_gauge_js (average_success_rate )
643+ html += build_gauge_js (average_success_rate , add_rate = True )
637644 html += '</div>'
638645
639646 html += '<hr>'
@@ -710,7 +717,7 @@ def make_barchart_summary(dir_dict,name="the_chart",title="DQM directory",the_ag
710717 });
711718 }
712719 </script>
713- """ % (name ,40 * counter ,title )
720+ """ % (name ,35 * counter ,title )
714721 return script
715722
716723
@@ -821,7 +828,7 @@ def make_summary_table(indir,aggregation_rules,aggregation_rules_twiki, hashing_
821828 page_html += make_categories_summary (dir_dict ,aggregation_rules )
822829
823830 # Make the Directories chart
824- page_html += '<div class="span-24"><h2 class="alt"><a name="detailed_barchart">Detailed Barchart</a></h2></div>'
831+ # page_html+='<div class="span-24"><h2 class="alt"><a name="detailed_barchart">Detailed Barchart</a></h2></div>'
825832 page_html += '<div id="dir_chart"></div> <a href="#top">Top...</a><hr>'
826833
827834 # Barbarian vertical space. Suggestions are welcome
@@ -830,24 +837,31 @@ def make_summary_table(indir,aggregation_rules,aggregation_rules_twiki, hashing_
830837
831838
832839 # Prepare the table
833- page_html += '<div class="span-24"><h2 class="alt"><a name="summary_table">Summary Table</a></h2></div>'
840+ page_html += '<div class="span-24"><h2 class="alt"><a name="summary_table">Summary Table</a></h2> <h4> <span class="alt"> (scrollable) </span> </h4> </div>'
834841
835- for i in range (5 ):
836- page_html += '<div class="span-24"><p></p></div>\n '
837-
842+ # for i in range(5):
843+ # page_html+='<div class="span-24"><p></p></div>\n'
844+
845+ div_width = min (len (dir_dict .keys ()) * 70 + 500 ,1500 ) #80 px per column + 200 for the first column
846+ page_html += '<div class="wrapper" style = "width: %dpx;">' % (div_width )
838847 page_html += """
839- <table border="1" >
848+ <table>
849+ <thead>
840850 <tr>
841- <td > </td>
851+ <th > <p class = "vertical_head center_head"></p> </th>
842852 """
843853
844854 # First row with samples
845855 page_html += """
846- <td><div class="span-1"> <p class="rotation" style="alt"><b> Summary</b></ p></div></td >"""
856+ <th> <p class = "vertical_head center_head"> Summary</p></th >"""
847857
848858 sorted_samples = sorted (dir_dict .keys ())
849859 for sample in sorted_samples :
850- sample_nick = sample
860+ if "_" in sample :
861+ sample_nick = "_" .join (sample .split ("X_" )[0 ].split ("_" )[:- 1 ])
862+ #slightly cleaner: _X is for the GT string, the _ split take away the 123X
863+ else :
864+ sample_nick = sample
851865 ## For runs: put only the number after the _
852866 #if "_" in sample:
853867 #run_number=sample.split("_")[-1]
@@ -856,34 +870,34 @@ def make_summary_table(indir,aggregation_rules,aggregation_rules_twiki, hashing_
856870
857871
858872 page_html += """
859- <td><div class="span-1"> <p class="rotation" style="" >%s</p ></div></td >""" % sample_nick
860- page_html += " </tr> \n "
873+ <th> <p class = "vertical_head center_head" >%s</th ></p >""" % sample_nick
874+ page_html += "</tr> \n </thead> \n </tbody> \n "
861875
862876
863877 # FIRST ROW
864878 # Now the summaries at the beginning of the table
865879 page_html += "<tr>"
866- page_html += '<td style="background-color:white;"><div class="span-1 ">'
880+ page_html += '<td class="sticky-col ">'
867881
868- page_html += '<b>Summary</b></div></ td>'
869- page_html += '<td style="background-color:white;" class = "colborder" ><div class="span-1"> %s </div></td>' % (global_dir .get_piechart_js (55 ))
882+ page_html += '<b>Summary</b></td>'
883+ page_html += '<td><div class="span-1"> %s </div></td>' % (global_dir .get_piechart_js (50 ))
870884 for sample in sorted_samples :
871885 col = dir_dict [sample ]
872886 # check if the directory was a top one or not
873887 summary_page_name = "RelMonSummary.html"
874888 if col .name != "" :
875889 summary_page_name = hash_name (col .name , hashing_flag )+ ".html"
876890 title = get_pie_tooltip (col )
877- chart = col .get_piechart_js (55 ,sample + "/" + summary_page_name , title )
878- page_html += '<td style="background-color:white;"><div class="span-1" >'
879- page_html += '%s </a></div></ td>' % (chart )
891+ chart = col .get_piechart_js (50 ,sample + "/" + summary_page_name )
892+ page_html += '<td>'
893+ page_html += '%s </a></td>' % (chart )
880894 page_html += "</tr>"
881895
882896 # Now the content
883897 for subdir_name in all_subdirs :
884898
885899 page_html += ' <tr>\n '
886- page_html += ' <td style="background-color:white ;">%s</td>\n ' % subdir_name
900+ page_html += ' <td class="sticky-col" style="font-weight:bold ;">%s</td>\n ' % subdir_name
887901
888902 row_summary = Directory ("row_summary" ,"" )
889903 sample_counter = 0
@@ -899,8 +913,8 @@ def make_summary_table(indir,aggregation_rules,aggregation_rules_twiki, hashing_
899913 # one first row for the summary!
900914 row_summary .calcStats ()
901915 title = get_pie_tooltip (col )
902- chart = row_summary .get_piechart_js (55 , None , title )
903- page_html += '<td style="background-color:white;"> <div class="span-1">'
916+ chart = row_summary .get_piechart_js (50 )
917+ page_html += '<td><div>' # <div class="span-1">'
904918 page_html += chart + '</div></td>'
905919
906920 for sample in sorted_samples :
@@ -925,27 +939,26 @@ def make_summary_table(indir,aggregation_rules,aggregation_rules_twiki, hashing_
925939 dir_is_there = subdir_name in subdirs_dict
926940
927941 img_link = "https://upload.wikimedia.org/wikipedia/commons/a/a8/Circle_Davys-Grey_Solid.svg"
928- img_tooltip = "N/A"
929- page_html += '<td style="background-color:white;"><div class="span-1">'
942+ page_html += '<td><div class="span-1">'
930943
931944 if dir_is_there :
932945 #row_summary.subdirs.append(subdirs_dict[subdir_name])
933- img_tooltip = get_pie_tooltip (subdirs_dict [subdir_name ])
934- chart = subdirs_dict [subdir_name ].get_piechart_js (50 ,summary_page ,img_tooltip )
946+ chart = subdirs_dict [subdir_name ].get_piechart_js (50 ,summary_page )
935947 page_html += '%s' % chart
936948 else :
937- page_html += '<img src="%s" title="%s" height=50 width=50>' % (img_link , img_tooltip )
949+ page_html += '<img src="%s" title="%s" height=50 width=50>' % (img_link )
938950 page_html += '</div></td>'
939951
940952 page_html += " </tr>\n "
941953
942954
943955
944- page_html += '</table> <a href="#top">Top...</a><hr>'
956+ page_html += '</tbody> </ table> </div > <a href="#top">Top...</a><hr>'
945957
946958 page_html += get_rank_section (global_dir )
947959
948- page_html += make_twiki_table (dir_dict ,aggregation_rules_twiki )
960+ #page_html+=make_twiki_table(dir_dict,aggregation_rules_twiki)
961+ # ^ commenting out for the moment, not really useful nor used
949962
950963 page_html += get_page_footer ()
951964 return page_html
0 commit comments