summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashantsinalkar2019-09-25 17:44:01 +0530
committerprashantsinalkar2019-09-25 17:44:01 +0530
commitda5988d90055b9cc7deea8dbba70cfba553cd77c (patch)
treebb3032783d2f0d66073222109204ed9fa60f5e64
parent57a530976f576cf9b3493b9994e46242ae39b4b9 (diff)
downloadR_on_Cloud_Web_Interface-da5988d90055b9cc7deea8dbba70cfba553cd77c.tar.gz
R_on_Cloud_Web_Interface-da5988d90055b9cc7deea8dbba70cfba553cd77c.tar.bz2
R_on_Cloud_Web_Interface-da5988d90055b9cc7deea8dbba70cfba553cd77c.zip
added plot feature
-rw-r--r--instances.py33
-rw-r--r--website/static/website/js/cloud.js11
-rw-r--r--website/views.py8
3 files changed, 26 insertions, 26 deletions
diff --git a/instances.py b/instances.py
index bbdfd1f..6f97563 100644
--- a/instances.py
+++ b/instances.py
@@ -1,6 +1,7 @@
# importing the global modules
import pexpect
import os
+import os.path
import re
import time
import sys
@@ -15,7 +16,7 @@ from django.template.loader import render_to_string, get_template
from django.core.mail import EmailMultiAlternatives
# importing the local variables
from R_on_Cloud.settings import PROJECT_DIR
-from R_on_Cloud.config import (BIN, API_URL, API_URL_PLOT)
+from R_on_Cloud.config import (BIN, API_URL, TEMP_DIR)
def execute_code(code, user_id, R_file_id):
@@ -35,29 +36,29 @@ def execute_code(code, user_id, R_file_id):
code = re.sub(r"View\(", "print(", code)
body = {
- 'code': code,
- 'user_id': user_id,
- 'R_file_id': R_file_id,
+ 'code': code,
+ 'user_id': user_id,
+ 'R_file_id': R_file_id,
}
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
}
jsondata = json.dumps(body)
- #jsondata = urllib.parse.urlencode(body)
- #print(jsondata)
-
- result=requests.post(API_URL, json=jsondata, headers=headers)
+ if not os.path.exists(TEMP_DIR):
+ os.makedirs(TEMP_DIR)
+ result = requests.post(API_URL, json=jsondata, headers=headers)
output = result.json()
- output_data= json.dumps(output['data'])
- output_error = json.dumps(output['error'])
- graph_exist = ""
- graph_path = ""
+ output_data = json.loads(json.dumps(output['data']))
+ output_error = json.loads(json.dumps(output['error']))
+ plot_exist = json.loads(json.dumps(output['is_plot']))
+ plot_path_req = json.loads(json.dumps(output['plot_path_req']))
+
data = {
- 'output': json.loads(output_data),
- 'error': json.loads(output_error)
- #'graph_exist': graph_exist,
- #'graph_path': graph_path,
+ 'output': output_data,
+ 'error': output_error,
+ 'plot_exist': plot_exist,
+ 'plot_path': plot_path_req,
}
return data
diff --git a/website/static/website/js/cloud.js b/website/static/website/js/cloud.js
index ab71be1..ab4efa1 100644
--- a/website/static/website/js/cloud.js
+++ b/website/static/website/js/cloud.js
@@ -679,24 +679,21 @@ $(document.body).ready(function() {
{
alert(data.error);
}
- if(data.graph_exist){
+ if(data.plot_exist =='True'){
$plot = $("<img>");
$plot.attr({
- src: data.graph_path,
+ src: data.plot_path,
width: '100%'
});
$plotbox.html($plot);
$plotbox_wrapper.modal('show');
- var dt = $(
- "#examples option:selected"
- )
- .text();
+ var dt = new Date().getTime();
$("#plot_download").show();
$("#plot_download").attr(
"download", dt +
'.png');
$("#plot_download").attr(
- "href", data.graph_path
+ "href", data.plot_path
);
}
});
diff --git a/website/views.py b/website/views.py
index d5eca56..01e0cc6 100644
--- a/website/views.py
+++ b/website/views.py
@@ -89,15 +89,17 @@ def get_code(file_path, commit_sha):
code = utils.get_file(file_path, commit_sha, main_repo=True)
return code
-
def index(request):
context = {}
user_id = uuid.uuid4()
- context['user_id'] = str(user_id)
context['api_url_upload'] = API_URL_UPLOAD
- request.session['user_id'] = str(user_id)
book_id = request.GET.get('book_id')
user = request.user
+ if(request.session['user_id']):
+ context['user_id'] = request.session['user_id']
+ else:
+ context['user_id'] = str(user_id)
+ request.session['user_id'] = str(user_id)
if not (request.GET.get('eid') or request.GET.get('book_id')):
catg_all = catg(None, all_cat=True)