From 06e73e7cd1c99ce224ee594b1e11129bc9a4e422 Mon Sep 17 00:00:00 2001 From: Jayaram Pai Date: Wed, 25 Dec 2013 03:23:55 +0530 Subject: code tested for Scilab 5.3.3 --- static/tmp/a.sci | 2 + static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci | 48 +++++++++++ static/tmp/out.txt | 74 +++++++++++++++++ static/website/css/main.css | 2 + static/website/js/cloud.js | 104 ++++++++++++++++++++++++ static/website/js/placeholder.js | 48 +++++++++++ static/website/templates/ajax-books.html | 9 ++ static/website/templates/ajax-chapters.html | 9 ++ static/website/templates/ajax-examples.html | 9 ++ static/website/templates/index.html | 83 +++++++++++-------- 10 files changed, 354 insertions(+), 34 deletions(-) create mode 100644 static/tmp/a.sci create mode 100644 static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci create mode 100644 static/tmp/out.txt create mode 100644 static/website/js/cloud.js create mode 100644 static/website/js/placeholder.js create mode 100644 static/website/templates/ajax-books.html create mode 100644 static/website/templates/ajax-chapters.html create mode 100644 static/website/templates/ajax-examples.html (limited to 'static') diff --git a/static/tmp/a.sci b/static/tmp/a.sci new file mode 100644 index 0000000..ac1be22 --- /dev/null +++ b/static/tmp/a.sci @@ -0,0 +1,2 @@ +exec('/home/cheese/cloud/soc/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci') +quit diff --git a/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci b/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci new file mode 100644 index 0000000..f635a71 --- /dev/null +++ b/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci @@ -0,0 +1,48 @@ +lines(0) + +disp("Example 2.1") +printf("\n") +printf("Given") +disp("Resistance used is 4 ohm") +disp("Current flow is i=2.5*sin(w*t)") +disp("Angular frequency(w)=500 rad/s") + +R=4; +iamp=2.5;w=500; +t=0:0.001:0.012566 +i=2.5*sin(w*t) + + +Vamp=iamp*R; +printf("v=%d*sin(%d*t)(V)\n",Vamp,w) + +pamp=iamp*iamp*R; +printf("p=%d(sin(%d*t))^2(W)\n",pamp,w) +p=pamp*sin(w*t)^2; + +//On integrating p with respect to t +W=25*(t/2-sin(2*w*t)/(4*w)) + +function p=f(t),p=pamp*sin(w*t)^2,endfunction +w1=intg(0,2*%pi/w,f); + + +subplot(221) +plot(t,i) +xs2jpg(gcf(), "/home/cheese/cloud/soc/static/tmp/1387919154.jpg"); +xtitle ('i vs wt','wt','i '); + +subplot(222) +plot(t,p) +xs2jpg(gcf(), "/home/cheese/cloud/soc/static/tmp/1387919155.jpg"); +xtitle ('p vs wt','wt','p '); + + + +subplot(223) +plot(t,W) +xs2jpg(gcf(), "/home/cheese/cloud/soc/static/tmp/1387919156.jpg"); +xtitle ('w vs wt','wt','w '); + + +exit diff --git a/static/tmp/out.txt b/static/tmp/out.txt new file mode 100644 index 0000000..26c869c --- /dev/null +++ b/static/tmp/out.txt @@ -0,0 +1,74 @@ + + + +-->lines(0) + + +-->disp("Example 2.1") + + Example 2.1 + +-->printf("\n") + + +-->printf("Given") +Given +-->disp("Resistance used is 4 ohm") + + Resistance used is 4 ohm + +-->disp("Current flow is i=2.5*sin(w*t)") + + Current flow is i=2.5*sin(w*t) + +-->disp("Angular frequency(w)=500 rad/s") + + Angular frequency(w)=500 rad/s + + +-->R=4; + +-->iamp=2.5;w=500; + +-->t=0:0.001:0.012566 + t = + + 0. 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01 0.011 0.012 + +-->i=2.5*sin(w*t) + i = + + 0. 1.1985638 2.1036775 2.4937375 2.2732436 1.4961804 0.3528000 - 0.8769581 - 1.8920062 - 2.4438253 - 2.3973107 - 1.7638508 - 0.6985387 + + + +-->Vamp=iamp*R; + +-->printf("v=%d*sin(%d*t)(V)\n",Vamp,w) +v=10*sin(500*t)(V) + + +-->pamp=iamp*iamp*R; + +-->printf("p=%d(sin(%d*t))^2(W)\n",pamp,w) +p=25(sin(500*t))^2(W) + +-->p=pamp*sin(w*t)^2; + + +-->//On integrating p with respect to t + +-->W=25*(t/2-sin(2*w*t)/(4*w)) + W = + + 0. 0.0019816 0.0136338 0.035736 0.0594600 0.0744866 0.0784927 0.0792877 0.0876330 0.1073485 0.1318003 0.1499999 0.1567072 + + +-->funcion p=f(t),p=pamp*sin(w*t)^2,endfunction +funcion p=f(t),p=pamp*sin(w*t)^2,endfunction + !--error 4 +Undefined variable: funcion +at line 26 of exec file called by : +exec('/home/cheese/cloud/soc/static/tmp/mLnhjbU1jr3BCrLv8tMJai6ElivgI1dJ.sci') + + diff --git a/static/website/css/main.css b/static/website/css/main.css index 802aa5f..8f95975 100644 --- a/static/website/css/main.css +++ b/static/website/css/main.css @@ -5,6 +5,8 @@ select { display: inline; margin-bottom: 15px; + min-width: 220px; + width: auto; } .CodeMirror { height: 99%; diff --git a/static/website/js/cloud.js b/static/website/js/cloud.js new file mode 100644 index 0000000..1b64532 --- /dev/null +++ b/static/website/js/cloud.js @@ -0,0 +1,104 @@ +$(document).ready(function() { + /* Code Mirror Controls */ + $fullscreen_code = $("#fullscreen-code"); + $toggle_code = $("#toggle-code"); + + $fullscreen_code.click(function(e) { + editor.setOption("fullScreen", !editor.getOption("fullScreen")); + editor.focus(); + }); + $toggle_code.click(function() { + if(editor.getOption("theme") == "monokai") { + editor.setOption("theme", "default"); + } else{ + editor.setOption("theme", "monokai"); + } + }); + + $fullscreen_result = $("#fullscreen-result"); + $toggle_result = $("#toggle-result"); + + $fullscreen_result.click(function(e) { + result.setOption("fullScreen", !result.getOption("fullScreen")); + result.focus(); + }); + $toggle_result.click(function() { + if(result.getOption("theme") == "monokai") { + result.setOption("theme", "default"); + } else{ + result.setOption("theme", "monokai"); + } + }); + + /* + * Selectors function + * Write the queries using live + */ + $("#categories").change(function() { + $("#books-wrapper").html(""); + $("#chapters-wrapper").html(""); + $("#examples-wrapper").html(""); + + $.ajax({ + url: "/ajax-books/", + type: "POST", + data: { + category_id: $(this).val() + }, + dataType: "html", + success: function(data) { + $("#books-wrapper").html(data); + } + }); + }); + + $(document).on("change", "#books", function(){ + $("#chapters-wrapper").html(""); + $("#examples-wrapper").html(""); + + $.ajax({ + url: "/ajax-chapters/", + type: "POST", + data: { + book_id: $("#books").val() + }, + dataType: "html", + success: function(data) { + $("#chapters-wrapper").html(data); + } + }); + }); + + $(document).on("change", "#chapters", function(){ + $("#examples-wrapper").html(""); + $.ajax({ + url: "/ajax-examples/", + type: "POST", + data: { + chapter_id: $("#chapters").val() + }, + dataType: "html", + success: function(data) { + $("#examples-wrapper").html(data); + } + }); + }); + + /* Execute the code */ + $("#execute").click(function() { + var csrfmiddlewaretoken = $("[name='csrfmiddlewaretoken']").val(); + var code = editor.getValue(); + $.ajax({ + url:"/ajax-execute/", + type: "POST", + data: { + csrfmiddlewaretoken: csrfmiddlewaretoken, + code: code + }, + dataType: "text", + success: function(data) { + result.setValue(data); + } + }); + }); +}); diff --git a/static/website/js/placeholder.js b/static/website/js/placeholder.js new file mode 100644 index 0000000..748afe7 --- /dev/null +++ b/static/website/js/placeholder.js @@ -0,0 +1,48 @@ +(function() { + CodeMirror.defineOption("placeholder", "", function(cm, val, old) { + var prev = old && old != CodeMirror.Init; + if (val && !prev) { + cm.on("blur", onBlur); + cm.on("change", onChange); + onChange(cm); + } else if (!val && prev) { + cm.off("blur", onBlur); + cm.off("change", onChange); + clearPlaceholder(cm); + var wrapper = cm.getWrapperElement(); + wrapper.className = wrapper.className.replace(" CodeMirror-empty", ""); + } + + if (val && !cm.hasFocus()) onBlur(cm); + }); + + function clearPlaceholder(cm) { + if (cm.state.placeholder) { + cm.state.placeholder.parentNode.removeChild(cm.state.placeholder); + cm.state.placeholder = null; + } + } + function setPlaceholder(cm) { + clearPlaceholder(cm); + var elt = cm.state.placeholder = document.createElement("pre"); + elt.style.cssText = "height: 0; overflow: visible"; + elt.className = "CodeMirror-placeholder"; + elt.appendChild(document.createTextNode(cm.getOption("placeholder"))); + cm.display.lineSpace.insertBefore(elt, cm.display.lineSpace.firstChild); + } + + function onBlur(cm) { + if (isEmpty(cm)) setPlaceholder(cm); + } + function onChange(cm) { + var wrapper = cm.getWrapperElement(), empty = isEmpty(cm); + wrapper.className = wrapper.className.replace(" CodeMirror-empty", "") + (empty ? " CodeMirror-empty" : ""); + + if (empty) setPlaceholder(cm); + else clearPlaceholder(cm); + } + + function isEmpty(cm) { + return (cm.lineCount() === 1) && (cm.getLine(0) === ""); + } +})(); diff --git a/static/website/templates/ajax-books.html b/static/website/templates/ajax-books.html new file mode 100644 index 0000000..a7eba3e --- /dev/null +++ b/static/website/templates/ajax-books.html @@ -0,0 +1,9 @@ +{% if books %} + + +{% endif %} diff --git a/static/website/templates/ajax-chapters.html b/static/website/templates/ajax-chapters.html new file mode 100644 index 0000000..e9ef640 --- /dev/null +++ b/static/website/templates/ajax-chapters.html @@ -0,0 +1,9 @@ +{% if chapters %} + + +{% endif %} diff --git a/static/website/templates/ajax-examples.html b/static/website/templates/ajax-examples.html new file mode 100644 index 0000000..c69e5c7 --- /dev/null +++ b/static/website/templates/ajax-examples.html @@ -0,0 +1,9 @@ +{% if examples %} + + +{% endif %} diff --git a/static/website/templates/index.html b/static/website/templates/index.html index 85f0ce3..a4b200b 100644 --- a/static/website/templates/index.html +++ b/static/website/templates/index.html @@ -34,43 +34,59 @@
- -
-
- - -
-
- - -
-
- - +
+
+
+
- +
Execute
- - + +
Report bug / Give Feedback @@ -88,9 +104,11 @@
+ + + {% csrf_token %} -- cgit