-
Notifications
You must be signed in to change notification settings - Fork 80
Webpage for resource allocation #3432
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
charles-cowart
merged 16 commits into
qiita-spots:dev
from
Gossty:resource-allocation-page
Sep 13, 2024
Merged
Changes from 15 commits
Commits
Show all changes
16 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 3220b7f
Added webpage for resource allocation plots
Gossty 5b235db
Merge branch 'dev' into resource-allocation-page
Gossty 6b4a718
Update resources.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
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
|
||
from tornado.gen import coroutine, Task | ||
from tornado.web import authenticated, HTTPError | ||
import json | ||
import ast | ||
from .base_handlers import BaseHandler | ||
from qiita_core.qiita_settings import r_client | ||
from qiita_core.util import execute_as_transaction | ||
|
||
commands = 'resources:commands' | ||
default_col_name = "samples * columns" | ||
|
||
|
||
class ResourcesHandler(BaseHandler): | ||
def check_admin(self): | ||
if self.current_user.level != "admin": | ||
raise HTTPError(403, reason="%s does not have access to portal " | ||
"editing!" % self.current_user.id) | ||
|
||
@execute_as_transaction | ||
def _get_resources(self, cname, sname, version, col_name, callback): | ||
resources = {} | ||
vals = [ | ||
('img_mem', r_client.get), | ||
('img_time', r_client.get), | ||
('time', r_client.get), | ||
('title_mem', r_client.get), | ||
('title_time', r_client.get) | ||
] | ||
for k, f in vals: | ||
redis_key = 'resources$#%s$#%s$#%s$#%s:%s' % (cname, sname, | ||
version, col_name, k) | ||
resources[k] = f(redis_key) | ||
callback(resources) | ||
|
||
@execute_as_transaction | ||
def _get_commands(self, callback): | ||
res = r_client.get(commands) | ||
callback(res) | ||
|
||
@authenticated | ||
@coroutine | ||
@execute_as_transaction | ||
def get(self): | ||
self.check_admin() | ||
commands = yield Task(self._get_commands) | ||
|
||
commands_str = commands.decode('utf-8') | ||
commands_dict = ast.literal_eval(commands_str) | ||
commands_json = json.dumps(commands_dict) | ||
|
||
self.render('resources.html', | ||
img_mem=None, img_time=None, | ||
time=None, | ||
mk=None, ma=None, mb=None, | ||
mmodel=None, mreal=None, | ||
mcalc=None, mfail=None, | ||
tk=None, ta=None, tb=None, | ||
tmodel=None, treal=None, | ||
tcalc=None, tfail=None, | ||
commands=commands_json, | ||
initial_load=True) | ||
|
||
@authenticated | ||
@coroutine | ||
@execute_as_transaction | ||
def post(self): | ||
try: | ||
data = json.loads(self.request.body) | ||
software = data.get('software') | ||
version = data.get('version') | ||
command = data.get('command') | ||
|
||
resources = yield Task(self._get_resources, command, software, | ||
version, default_col_name) | ||
|
||
mcof, mmodel, mreal, mcalc, mfail = list( | ||
map(lambda x: x.split(b": ")[1].strip().decode('utf-8'), | ||
resources['title_mem'].split(b"\n"))) | ||
|
||
tcof, tmodel, treal, tcalc, tfail = list( | ||
map(lambda x: x.split(b": ")[1].strip().decode('utf-8'), | ||
resources['title_time'].split(b"\n"))) | ||
|
||
mk, ma, mb = mcof.split("||") | ||
tk, ta, tb = tcof.split("||") | ||
|
||
response_data = { | ||
"status": "success", | ||
"img_mem": resources[ | ||
'img_mem'].decode('utf-8') if isinstance( | ||
resources['img_mem'], bytes) else resources['img_mem'], | ||
"img_time": resources[ | ||
'img_time'].decode('utf-8') if isinstance( | ||
resources['img_time'], bytes) else resources['img_time'], | ||
"time": resources[ | ||
'time'].decode('utf-8') if isinstance( | ||
resources['time'], bytes) else resources['time'], | ||
"mk": mk, "ma": ma, "mb": mb, | ||
"tk": tk, "ta": ta, "tb": tb, | ||
"mmodel": mmodel, "mreal": mreal, | ||
"mcalc": mcalc, "mfail": mfail, | ||
"tcof": tcof, | ||
"tmodel": tmodel, "treal": treal, | ||
"tcalc": tcalc, "tfail": tfail, | ||
"initial_load": False | ||
} | ||
self.write(json.dumps(response_data)) | ||
charles-cowart marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
except json.JSONDecodeError: | ||
self.set_status(400) | ||
self.finish({"error": "Invalid JSON data"}) | ||
except Exception as e: | ||
import traceback | ||
print(traceback.format_exc()) | ||
if resources['title_mem'] is None: | ||
response_data = { | ||
"status": "no_data", | ||
"img_mem": None, | ||
"img_time": None, | ||
"time": None, | ||
"mk": None, "ma": None, "mb": None, | ||
"tk": None, "ta": None, "tb": None, | ||
"mmodel": None, "mreal": None, | ||
"mcalc": None, "mfail": None, | ||
"tcof": None, | ||
"tmodel": None, "treal": None, | ||
"tcalc": None, "tfail": None, | ||
"initial_load": False | ||
} | ||
self.set_status(200) | ||
self.write(json.dumps(response_data)) | ||
else: | ||
self.set_status(500) | ||
self.finish({"error": str(e)}) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.