|
24 | 24 |
|
25 | 25 | import os |
26 | 26 | import hashlib |
| 27 | +import random |
27 | 28 |
|
28 | 29 | if "RELMON_SA" in os.environ: |
29 | 30 | from .dirstructure import Comparison,Directory |
@@ -492,27 +493,44 @@ def directory2html(directory, hashing, standalone, depth=0): |
492 | 493 |
|
493 | 494 | #chdir(old_cwd) |
494 | 495 |
|
495 | | -#------------------------------------------------------------------------------- |
| 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): |
| 501 | + |
| 502 | + color = to_rgba(gauge_cmap(rate-minrate)) |
| 503 | + font_size = int(w/5) |
| 504 | + text_offs = int(w/8) |
| 505 | + gauge_max = 1. - rate |
| 506 | + |
| 507 | + name = random.getrandbits(64) # just a random has for the canvas |
| 508 | + 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) |
| 513 | + |
| 514 | + # "gauge" chart |
| 515 | + html += '<script> new Chart("%s",'%(name) |
| 516 | + html += '{ type: "doughnut",' |
496 | 517 |
|
497 | | -def build_gauge(total_success_rate,minrate=.80,small=False,escaped=False): |
498 | | - total_success_rate_scaled=(total_success_rate-minrate) |
499 | | - total_success_rate_scaled_repr=total_success_rate_scaled/(1-minrate) |
500 | | - if total_success_rate_scaled_repr<0: |
501 | | - total_success_rate_scaled_repr=0 |
502 | | - size_s="200x100" |
503 | | - if small: |
504 | | - size_s="40x30" |
505 | | - #print "Total success rate %2.2f and scaled %2.2f "%(total_success_rate,total_success_rate_scaled) |
506 | | - gauge_link ="https://chart.googleapis.com/chart?chs=%s&cht=gom"%size_s |
507 | | - gauge_link+="&chd=t:%2.1f"%(total_success_rate_scaled_repr*100.) |
508 | | - if not small: |
509 | | - gauge_link+="&chxt=x,y&chxl=0:|%2.1f%%|1:|%i%%|%i%%|100%%"%(total_success_rate*100,minrate*100.,(1+minrate)*50) |
510 | | - gauge_link+="&chma=10,10,10,0" |
511 | | - img_tag= '<img src="%s">'%gauge_link |
512 | | - if escaped: |
513 | | - img_tag=html.escape(img_tag) |
514 | | - return img_tag |
| 518 | + # data |
| 519 | + html += 'data: {' |
| 520 | + html += 'datasets: [{ backgroundColor: ["%s", "rgba(0, 0, 0, 0.1)"],'%(color) |
| 521 | + html += 'data: [%f,%f]}] },'%(rate,gauge_max) |
515 | 522 |
|
| 523 | + #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") |
| 532 | + |
| 533 | + return html |
516 | 534 | #------------------------------------------------------------------------------- |
517 | 535 |
|
518 | 536 | def get_aggr_pairs_info(dir_dict,the_aggr_pairs=[]): |
@@ -615,7 +633,7 @@ def make_categories_summary(dir_dict,aggregation_rules): |
615 | 633 | html+='</div>' |
616 | 634 |
|
617 | 635 | html+='<div class="span-6 last">' |
618 | | - html+=build_gauge(average_success_rate) |
| 636 | + html+=build_gauge_js(average_success_rate) |
619 | 637 | html+='</div>' |
620 | 638 |
|
621 | 639 | html+='<hr>' |
@@ -649,7 +667,7 @@ def make_twiki_table(dir_dict,aggregation_rules): |
649 | 667 |
|
650 | 668 | for cat_name,present_subdirs,total_weight,average_success_rate in aggr_pairs_info: |
651 | 669 | #print cat_name,present_subdirs,total_weight,average_success_rate |
652 | | - html+=build_gauge(average_success_rate,small=True,escaped=True) |
| 670 | + html+=build_gauge_js(average_success_rate,w=40) |
653 | 671 | html+=" | " |
654 | 672 |
|
655 | 673 | html+='</div> <a href="#top">Top...</a>' |
|
0 commit comments