-
Notifications
You must be signed in to change notification settings - Fork 79
Resource Allocation data in Redis #3430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
88dc031
Update to DB qiita.slurm_resource_allocations
Gossty 447e01a
Merge branch 'dev' of https://github.com/qiita-spots/qiita into dev
Gossty 442e735
Merge branch 'dev' of https://github.com/qiita-spots/qiita into dev
Gossty 43aa8bf
Merge branch 'dev' of https://github.com/qiita-spots/qiita into dev
Gossty 3afba3a
Merge branch 'dev' of https://github.com/qiita-spots/qiita into dev
Gossty a36dc8a
Merge branch 'dev' of https://github.com/qiita-spots/qiita into dev
Gossty 071eb5f
Merge branch 'dev' of https://github.com/qiita-spots/qiita into dev
Gossty ddff1c4
qiita-cron-job initialize-resource-allocations-redis
Gossty 8fc1b64
Populate redis with resource-allocation data
Gossty 7241754
Removed changes to qiita_pet
Gossty 437b8c8
Minor changes
Gossty 4fa0c70
Updates to Antonio’s coments
Gossty f5ab035
Update meta_util.py
Gossty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,11 +37,18 @@ | |
from re import sub | ||
from json import loads, dump, dumps | ||
|
||
from qiita_db.util import create_nested_path | ||
from qiita_db.util import create_nested_path, _retrieve_resource_data | ||
from qiita_db.util import resource_allocation_plot | ||
from qiita_core.qiita_settings import qiita_config, r_client | ||
from qiita_core.configuration_manager import ConfigurationManager | ||
import qiita_db as qdb | ||
|
||
# global constant list used in resource_allocation_page | ||
columns = [ | ||
|
||
"sName", "sVersion", "cID", "cName", "processing_job_id", | ||
"parameters", "samples", "columns", "input_size", "extra_info", | ||
"MaxRSSRaw", "ElapsedRaw", "Start", "node_name", "node_model"] | ||
|
||
|
||
def _get_data_fpids(constructor, object_id): | ||
"""Small function for getting filepath IDS associated with data object | ||
|
@@ -546,3 +553,102 @@ def generate_plugin_releases(): | |
# important to "flush" variables to avoid errors | ||
r_client.delete(redis_key) | ||
f(redis_key, v) | ||
|
||
|
||
def get_software_commands(active): | ||
software_list = [s for s in qdb.software.Software.iter(active=active)] | ||
software_commands = dict() | ||
for software in software_list: | ||
sname = software.name | ||
sversion = software.version | ||
commands = software.commands | ||
if sname not in software_commands: | ||
software_commands[sname] = {} | ||
if sversion not in software_commands[sname]: | ||
software_commands[sname][sversion] = [] | ||
for command in commands: | ||
software_commands[sname][sversion].append(command.name) | ||
|
||
return software_commands | ||
|
||
|
||
def update_resource_allocation_redis(active=True): | ||
"""Updates redis with plots and information about current software. | ||
|
||
Parameters | ||
---------- | ||
active: boolean, optional | ||
Defaults to True. Should only be False when testing. | ||
|
||
""" | ||
time = datetime.now().strftime('%m-%d-%y') | ||
scommands = get_software_commands(active) | ||
redis_key = 'resources:commands' | ||
r_client.set(redis_key, str(scommands)) | ||
|
||
for sname, versions in scommands.items(): | ||
for version, commands in versions.items(): | ||
for cname in commands: | ||
|
||
col_name = "samples * columns" | ||
df = _retrieve_resource_data(cname, sname, version, columns) | ||
if len(df) == 0: | ||
continue | ||
|
||
fig, axs = resource_allocation_plot(df, cname, sname, col_name) | ||
titles = [0, 0] | ||
images = [0, 0] | ||
|
||
# Splitting 1 image plot into 2 separate for better layout. | ||
for i, ax in enumerate(axs): | ||
titles[i] = ax.get_title() | ||
ax.set_title("") | ||
# new_fig, new_ax – copy with either only memory plot or | ||
# only time | ||
new_fig = plt.figure() | ||
new_ax = new_fig.add_subplot(111) | ||
|
||
scatter_data = ax.collections[0] | ||
new_ax.scatter(scatter_data.get_offsets()[:, 0], | ||
scatter_data.get_offsets()[:, 1], | ||
s=scatter_data.get_sizes(), label="data") | ||
|
||
line = ax.lines[0] | ||
new_ax.plot(line.get_xdata(), line.get_ydata(), | ||
linewidth=1, color='orange') | ||
|
||
if len(ax.collections) > 1: | ||
failure_data = ax.collections[1] | ||
new_ax.scatter(failure_data.get_offsets()[:, 0], | ||
failure_data.get_offsets()[:, 1], | ||
color='red', s=3, label="failures") | ||
|
||
new_ax.set_xscale('log') | ||
new_ax.set_yscale('log') | ||
new_ax.set_xlabel(ax.get_xlabel()) | ||
new_ax.set_ylabel(ax.get_ylabel()) | ||
new_ax.legend(loc='upper left') | ||
|
||
new_fig.tight_layout() | ||
plot = BytesIO() | ||
new_fig.savefig(plot, format='png') | ||
plot.seek(0) | ||
img = 'data:image/png;base64,' + quote( | ||
b64encode(plot.getvalue()).decode('ascii')) | ||
images[i] = img | ||
plt.close(new_fig) | ||
plt.close(fig) | ||
|
||
# SID, CID, col_name | ||
values = [ | ||
("img_mem", images[0], r_client.set), | ||
("img_time", images[1], r_client.set), | ||
('time', time, r_client.set), | ||
("title_mem", titles[0], r_client.set), | ||
("title_time", titles[1], r_client.set) | ||
] | ||
|
||
for k, v, f in values: | ||
redis_key = 'resources$#%s$#%s$#%s$#%s:%s' % ( | ||
cname, sname, version, col_name, k) | ||
r_client.delete(redis_key) | ||
f(redis_key, v) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
_retrieve_resource_data
is going to be use outside of util, then it should not start with _, could you change?