|
38 | 38 | from json import loads, dump, dumps
|
39 | 39 |
|
40 | 40 | from qiita_db.util import create_nested_path, _retrieve_resource_data
|
41 |
| -from qiita_db.util import resource_allocation_plot, get_software_commands |
| 41 | +from qiita_db.util import resource_allocation_plot |
42 | 42 | from qiita_core.qiita_settings import qiita_config, r_client
|
43 | 43 | from qiita_core.configuration_manager import ConfigurationManager
|
44 | 44 | import qiita_db as qdb
|
|
49 | 49 | "parameters", "samples", "columns", "input_size", "extra_info",
|
50 | 50 | "MaxRSSRaw", "ElapsedRaw", "Start", "node_name", "node_model"]
|
51 | 51 |
|
| 52 | + |
52 | 53 | def _get_data_fpids(constructor, object_id):
|
53 | 54 | """Small function for getting filepath IDS associated with data object
|
54 | 55 |
|
@@ -554,40 +555,96 @@ def generate_plugin_releases():
|
554 | 555 | f(redis_key, v)
|
555 | 556 |
|
556 | 557 |
|
557 |
| -def initialize_resource_allocations_redis(): |
558 |
| - time = datetime.now().strftime('%m-%d-%y %H:%M:%S') |
| 558 | +def get_software_commands(): |
| 559 | + # TODO change active=False to True. In test, the data is active=False. |
| 560 | + software_list = [s for s in qdb.software.Software.iter(active=False)] |
| 561 | + software_commands = dict() |
| 562 | + for software in software_list: |
| 563 | + sname = software.name |
| 564 | + sversion = software.version |
| 565 | + commands = software.commands |
| 566 | + if sname not in software_commands: |
| 567 | + software_commands[sname] = {} |
| 568 | + if sversion not in software_commands[sname]: |
| 569 | + software_commands[sname][sversion] = [] |
| 570 | + for command in commands: |
| 571 | + software_commands[sname][sversion].append(command.name) |
| 572 | + return software_commands |
| 573 | + |
| 574 | + |
| 575 | +def update_resource_allocation_redis(): |
| 576 | + time = datetime.now().strftime('%m-%d-%y') |
559 | 577 | scommands = get_software_commands()
|
560 |
| - for software, versions in scommands.items(): |
561 |
| - for version, commands in versions.items(): |
562 |
| - for command in commands: |
563 |
| - print("Generating plot for:", software, version, command) |
564 |
| - update_resource_allocation_redis(command, software, |
565 |
| - version, time) |
566 | 578 | redis_key = 'resources:commands'
|
567 | 579 | r_client.set(redis_key, str(scommands))
|
568 | 580 |
|
| 581 | + for sname, versions in scommands.items(): |
| 582 | + for version, commands in versions.items(): |
| 583 | + for cname in commands: |
569 | 584 |
|
570 |
| -def update_resource_allocation_redis(cname, sname, version, time): |
571 |
| - col_name = "samples * columns" |
572 |
| - |
573 |
| - df = _retrieve_resource_data(cname, sname, version, columns) |
574 |
| - fig, axs = resource_allocation_plot(df, cname, sname, col_name) |
575 |
| - |
576 |
| - fig.tight_layout() |
577 |
| - plot = BytesIO() |
578 |
| - fig.savefig(plot, format='png') |
579 |
| - plot.seek(0) |
580 |
| - |
581 |
| - img = 'data:image/png;base64,' + quote(b64encode(plot.getbuffer()).decode('ascii')) |
582 |
| - plt.close(fig) |
583 |
| - |
584 |
| - # SID, CID, col_name |
585 |
| - values = [ |
586 |
| - ("img", img, r_client.set), |
587 |
| - ('time', time, r_client.set) |
588 |
| - ] |
589 |
| - |
590 |
| - for k, v, f in values: |
591 |
| - redis_key = 'resources$#%s$#%s$#%s:%s' % (cname, sname, col_name, k) |
592 |
| - r_client.delete(redis_key) |
593 |
| - f(redis_key, v) |
| 585 | + print("Generating plot for:", sname, version, cname) |
| 586 | + col_name = "samples * columns" |
| 587 | + df = _retrieve_resource_data(cname, sname, version, columns) |
| 588 | + if len(df) == 0: |
| 589 | + print("No available data for", sname, version, cname) |
| 590 | + continue |
| 591 | + |
| 592 | + fig, axs = resource_allocation_plot(df, cname, sname, col_name) |
| 593 | + titles = [0, 0] |
| 594 | + images = [0, 0] |
| 595 | + |
| 596 | + # Splitting 1 image plot into 2 separate for better layout. |
| 597 | + for i, ax in enumerate(axs): |
| 598 | + titles[i] = ax.get_title() |
| 599 | + ax.set_title("") |
| 600 | + # new_fig, new_ax – copy with either only memory plot or |
| 601 | + # only time |
| 602 | + new_fig = plt.figure() |
| 603 | + new_ax = new_fig.add_subplot(111) |
| 604 | + |
| 605 | + scatter_data = ax.collections[0] |
| 606 | + new_ax.scatter(scatter_data.get_offsets()[:, 0], |
| 607 | + scatter_data.get_offsets()[:, 1], |
| 608 | + s=scatter_data.get_sizes(), label="data") |
| 609 | + |
| 610 | + line = ax.lines[0] |
| 611 | + new_ax.plot(line.get_xdata(), line.get_ydata(), |
| 612 | + linewidth=1, color='orange') |
| 613 | + |
| 614 | + if len(ax.collections) > 1: |
| 615 | + failure_data = ax.collections[1] |
| 616 | + new_ax.scatter(failure_data.get_offsets()[:, 0], |
| 617 | + failure_data.get_offsets()[:, 1], |
| 618 | + color='red', s=3, label="failures") |
| 619 | + |
| 620 | + new_ax.set_xscale('log') |
| 621 | + new_ax.set_yscale('log') |
| 622 | + new_ax.set_xlabel(ax.get_xlabel()) |
| 623 | + new_ax.set_ylabel(ax.get_ylabel()) |
| 624 | + new_ax.legend(loc='upper left') |
| 625 | + |
| 626 | + new_fig.tight_layout() |
| 627 | + plot = BytesIO() |
| 628 | + new_fig.savefig(plot, format='png') |
| 629 | + plot.seek(0) |
| 630 | + img = 'data:image/png;base64,' + quote( |
| 631 | + b64encode(plot.getvalue()).decode('ascii')) |
| 632 | + images[i] = img |
| 633 | + plt.close(new_fig) |
| 634 | + plt.close(fig) |
| 635 | + |
| 636 | + # SID, CID, col_name |
| 637 | + values = [ |
| 638 | + ("img_mem", images[0], r_client.set), |
| 639 | + ("img_time", images[1], r_client.set), |
| 640 | + ('time', time, r_client.set), |
| 641 | + ("title_mem", titles[0], r_client.set), |
| 642 | + ("title_time", titles[1], r_client.set) |
| 643 | + ] |
| 644 | + print(time, titles[0], titles[1]) |
| 645 | + |
| 646 | + for k, v, f in values: |
| 647 | + redis_key = 'resources$#%s$#%s$#%s$#%s:%s' % ( |
| 648 | + cname, sname, version, col_name, k) |
| 649 | + r_client.delete(redis_key) |
| 650 | + f(redis_key, v) |
0 commit comments