Commit f819b436 authored by Martin Urban's avatar Martin Urban
Browse files

Remove examples extension and move it to different repo

parent 7bc7b853
# -*- coding: utf-8 -*-
import cherrypy
from vispa.server import AbstractExtension
from controller import ExamplesController
from vispa.controller import AbstractController
class ExamplesExtension(AbstractExtension):
def name(self):
return "examples"
def dependencies(self):
return []
def setup(self):
self.add_controller(ExamplesController(self))
self.add_js("js/extension.js")
self.add_js("js/prefs.js")
self.add_js("js/view.js")
self.add_workspace_directoy()
#self.add_controller(FileController())
\ No newline at end of file
# -*- coding: utf-8 -*-
# imports
import cherrypy
import vispa.workspace
from vispa.controller import AbstractController
from vispa import MessageException
class ExamplesController(AbstractController):
def __init__(self, extension):
AbstractController.__init__(self)
self.extension = extension
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def create_folder(self, path):
self.release_session()
rpc = self.get("proxy", "ExamplesRpc")
self.release_database()
return rpc.create_folder(path)
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def getcontent(self, path, type="example"):
self.release_session()
rpc = self.get("proxy", "ExamplesRpc")
self.release_database()
return rpc.getcontent(path, type)
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def check_workspace_settigns(self, path):
self.release_session()
rpc = self.get("proxy", "ExamplesRpc")
self.release_database()
return rpc.check_workspace_settigns(path)
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def check_destination(self, path):
self.release_session()
rpc = self.get("proxy", "ExamplesRpc")
self.release_database()
return rpc.check_destination(path)
'''
@cherrypy.expose
@cherrypy.tools.ajax(encoded=True)
def rsync(self, src, dest, opt):
self.release_session()
rpc = self.get("proxy", "ExamplesRpc")
self.release_database()
return rpc.rsync(src, dest, opt)
'''
<style type="text/css">
h4 {
margin: 6px 0px 0px 0px;
}
.examples {
margin: 20px 18px 20px 18px;
}
.example {
margin: 60px 18px 40px 18px;
}
.example img {
width: 200px;
float: left;
margin: 0px 10px 0px 0px;
}
.btn-open {
float: right;
margin: 8px 0px 0px 4px
}
</style>
<div class="examples">
<h2>Installed Software</h2>
<div class="row">
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_pxl.png" alt="logo_pxl.png" title="pxl"><h4>PXL</h4>The Physics eXtension Library (PXL) is a C++ class collection for advanced level analysis in high energy physics experiments. PXL classes are based on the ANSI C++ language standard together with the Standard Template Library (STL). All classes are accessible and usable from Python. <a data-toggle="collapse" href="#collapsePXL">more...</a><div id="collapsePXL" class="collapse">During the reconstruction of a high energy physics data event, PXL enables storing all event information in objects (<code><a href="https://forge.physik.rwth-aachen.de/public/pxl/3.5/doxygen/classpxl_1_1Object.html" target="_blank">pxl::Object</a></code>) such as particles (<code><a href="https://forge.physik.rwth-aachen.de/public/pxl/3.5/doxygen/classpxl_1_1Particle.html" target="_blank">pxl::Particle</a></code>), vertices (<code><a href="https://forge.physik.rwth-aachen.de/public/pxl/3.5/doxygen/classpxl_1_1Vertex.html" target="_blank">pxl::Vertex</a></code>) and collisions (<code><a href="https://forge.physik.rwth-aachen.de/public/pxl/3.5/doxygen/classpxl_1_1Collision.html" target="_blank">pxl::Collision</a></code>). Each of them allows storing all information that users need to keep for their analysis. In addition, the program allows to include self-defined C++ PXL classes in order to maintain structures of analysis-specific event information. Between all such objects, relations can be established, e.g. to build particle decay trees.<br>At this level, PXL objects contain single aspects of an individual event. For maintaining information about a whole process, PXL provides the building block <code><a href="https://forge.physik.rwth-aachen.de/public/pxl/3.5/doxygen/classpxl_1_1EventView.html" target="_blank">pxl::EventView</a></code>. This is a generalized event container where, beyond the aforementioned physics objects, user information can be stored as well.</div> <a href="https://forge.physik.rwth-aachen.de/public/pxl/3.5/doxygen/" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_root.gif" alt="logo_root.png" title="ROOT"><h4>ROOT</h4>For almost two decades, ROOT has established itself as the framework for HENP data processing and analysis. The ROOT system provides a set of frameworks with all the functionality needed to handle and analyze large amounts of data in a very efficient way. <a data-toggle="collapse" href="#collapseROOT">more...</a><div id="collapseROOT" class="collapse">The class <code><a href="http://root.cern.ch/root/html/TF1.html" target="_blank">root::TF1</a></code> will allow you display a function of one variable, whereas <code><a href="http://root.cern.ch/root/html/TF2.html" target="_blank">root::TF2</a></code> gives you the opportunity of plotting 2-dimensional functions. For histograms, use <code><a href="http://root.cern.ch/root/htmldoc/TH1.html" target="_blank">root::TH1</a></code>, respectively <code><a href="http://root.cern.ch/root/html/TH2.html" target="_blank">root::TH2</a></code>. If you want to illustrate measured data, make use of <code><a href="http://root.cern.ch/root/html/TGraphErrors.html" target="_blank">root::TGraphErrors</a></code> and perform a fit to an arbitrary function with <code><a href="http://root.cern.ch/root/html/TGraph.html#TGraph:Fit" target="_blank">TGraph::Fit</a></code>. For more details, look at the <a href="http://root.cern.ch/drupal/content/users-guide" target="_blank">ROOT User's Guide Homepage</a> where you will also find a <a href="http://root.cern.ch/root/html534/guides/primer/ROOTPrimer.pdf" target="_blank">primer</a> for a quick access into ROOT. </div> <a href="http://root.cern.ch/drupal/content/documentation" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_python.png" alt="logo_python.png" title="python"><h4>python</h4>Python is a programming language that lets you work more quickly and integrate your systems more effectively. Learning to use python, you will notice almost immediate gains in productivity and lower maintenance costs.<a href="https://docs.python.org/2.7/" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_condor.png" alt="logo_condor.png" title="Condor"><h4>Condor HTC</h4>Condor's goal is to develop, implement, deploy, evaluate mechanisms and policies that support High Throughput Computing (HTC) on large collections of distributively owned computing resources. <br><a href="http://research.cs.wisc.edu/htcondor/manual/" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_numpy.png" alt="logo_numpy.png" title="numpy"><h4>NumPy</h4>NumPy is the fundamental package for scientific computing with Python. It contains among other things: a powerful N-dimensional array object, sophisticated (broadcasting) functions, useful linear algebra, Fourier transform, and random number capabilities.<a href="http://docs.scipy.org/doc/" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_scipy.png" alt="logo_scipy.png" title="SciPy"><h4>SciPy</h4>SciPy refers to several related but distinct entities: the SciPy Stack, a collection of open source software for scientific computing in Python, and particularly a specified set of core packages.<br><a href="http://docs.scipy.org/doc/" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_crpropa.png" alt="crpropa.png" title="CRPropa"><h4>CRPropa</h4>CRPropa is a publicly available code to study the propagation of ultra high energy nuclei up to iron on their voyage through an extra galactic environment. It takes into account: pion production, photodisintegration, and energy losses by pair production of all relevant isotopes in the ambient low energy photon fields as well as nuclear decay. <a href="https://github.com/CRPropa/CRPropa3/wiki" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_matplotlib.png" alt="logo_matplotlib.png" title="matplotlib"><h4>matplotlib</h4>Matplotlib is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in python scripts, the python and ipython shell, web application servers, and six graphical user interface toolkits.<br><br><a href="http://matplotlib.org/contents.html" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_gsl.png" alt="gsl.png" title="GSL"><h4>GSL</h4>The GNU Scientific Library (GSL) is a collection of routines for numerical computing. The routines have been written from scratch in C, and present a modern Applications Programming Interface (API) for C programmers allowing wrappers to be written for very high-level languages.<br><a href="http://www.gnu.org/doc/doc.html" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/software/logo_boost.png" alt="logo_boost.png" title="boost"><h4>boost</h4>Boost is a set of libraries for the C++ programming language that provides support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It contains over 80 individual libraries.<a href="http://www.boost.org/doc/" target="blank" class="btn btn-primary btn-open">Open Documentation</a>
</div>
</div>
</div>
</div>
\ No newline at end of file
<style type="text/css">
h4 {
margin: 6px 0px 0px 0px;
}
.examples {
margin: 20px 18px 20px 18px;
}
.example {
margin: 60px 18px 40px 18px;
}
.example img {
width: 200px;
float: left;
margin: 0px 10px 0px 0px;
}
.btn-copy {
float: right;
margin: 8px 0px 0px 6px;
}
.btn-reset {
visibility: hidden;
float: right;
margin: 8px 0px 0px 6px;
}
</style>
<div class="examples">
<h2>CERN Examples</h2>
<div class="row">
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/Examples/feynman_Z_ee.png" alt="z_mass_example.png" title="Z mass example">
<h4>Z mass</h4>
Discover your first boson: While running this example, you can reconstruct the Z boson, the uncharged exchange particle (gauge boson) of the electroweak force. As a result, a plot with a peak at about 90 GeV, the mass of the Z boson, will be shown.
<div class="button-section" data-file="z_mass/z_mass.py" data-copy="/home/public/CERN/examples/z_mass" data-extension="CodeEditor">
<div class="btn btn-primary btn-copy">Open example</div>
<div class="btn btn-primary btn-reset">Reset example</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/Examples/lepton_pt.png" alt="leptop_pt_example.png" title="leptopn pT example">
<h4>Lepton p<sub>T</sub></h4>
One of the simplest and most frequently done steps during a physics analysis is to plot the distribution of kinematic variables. With this script, you can plot the distribution of the transverse momentum p<sub>T</sub> of electrons and muons.<br>
<div class="button-section" data-file="hello_lepton/hello_lepton.py" data-copy="/home/public/CERN/examples/hello_lepton" data-extension="CodeEditor">
<div class="btn btn-primary btn-copy">Open example</div>
<div class="btn btn-primary btn-reset">Reset example</div>
</div>
</div>
</div>
</div>
<br><br><br><br>
<h2>Other Examples</h2>
<div class="row">
<div class="col-md-6">
<div class="example">
<img src="https://vispa.physik.rwth-aachen.de/data/_uploaded/image/1.0/Examples/auger_skymap.png" alt="auger_skymap_example.png" title="auger skymap example">
<h4>Auger example</h4>
In this example, you can use the public data set (1 % of all events) of the Pierre Auger Observatory to study the energy distribution and to plot the arrival directions of cosmic rays.
<div class="button-section" data-file="energy_distribution/auger.py" data-copy="/home/public/auger/examples/energy_distribution" data-extension="CodeEditor">
<div class="btn btn-primary btn-copy">Open example</div>
<div class="btn btn-primary btn-reset">Reset example</div>
</div>
</div>
</div>
<div class="col-md-6">
&nbsp;
</div>
</div>
</div>
\ No newline at end of file
var ExampleExtension = vispa.Extension.extend({
init: function() {
var self = this;
this._super("examples");
this.addViews({
"example": ExampleView,
"documentation": DocumentationView
});
this.addMenuEntry("examples", {
label: "Open Examples",
iconClass: "glyphicon glyphicon-play-circle",
callback: function(workspaceId) {
self.createInstance(workspaceId, ExampleView);
}
});
this.addMenuEntry("documentation", {
label: "Installed Software",
iconClass: "glyphicon glyphicon-book",
callback: function(workspaceId) {
self.createInstance(workspaceId, DocumentationView);
}
});
//show the button
this.getDefaultPreferences(ExampleView).fastMenuEntries.value = [ //??? Why not shown in tab? ??
"copyall"
];
//preferences
this.setDefaultPreferences("example", getDefaultExamplePreferences(), {
title: "Examples"
});
// preferences
this.setDefaultPreferences("documentation", getDefaultDocumentationPreferences(), {
title: "Installed Software"
});
this.setOptions(ExampleView, {
"maxInstances": 1
});
this.setOptions(DocumentationView, {
"maxInstances": 1
});
// add global callbacks
vispa.callbacks.on("showExamples", function(workspaceId) {
self.createInstance(workspaceId, ExampleView);
});
vispa.callbacks.on("showDocs", function(workspaceId) {
self.createInstance(workspaceId, DocumentationView);
});
}
});
var ExampleView = vispa.ExtensionView.Center.extend({
init: function(preferences, shortcuts) {
var self = this;
this._super(preferences, shortcuts);
//init preference variables
this.examplePath = "";
this.examplePaths = [];
this.execute = false;
this.viewSetupCallback = this.setupButton;
this.node = null;
this.workspaceini = null;
//copy all button //TODO!: Button should show up in the tab bar
this.addMenuEntry("copyall", {
label: "Copy all",
id: "copyall",
iconClass: "glyphicon glyphicon-share-alt",
buttonClass: "btn-primary",
callback: function() {
self.copyAll();
}
});
},
setup: function() {
var self = this;
this._super();
this.setLabel("Examples");
this.setIcon("glyphicon glyphicon-play-circle");
},
render: function(node) {
renderDocuExamplesView.call(this, node, "example");
},
//empty function to apply preferences
applyPreferences: function() {
this.examplePath = this.getPreference('CopyPath');
},
//what happens before the instance is maximized
onBeforeShow: function() {
var self = this;
$.each($(".btn-reset"), function(i, elem) {
var filename = self.getfilename($(elem).parent().data("copy"));
self.toggleResetButtonCSS($(elem), filename);
});
},
//empty function in which the events are assigned to the buttons
setupButton: function() {
var self = this;
this.createDestination();
var openButtons = [];
var resetButtons = [];
$.each($(self.node).find('.button-section'), function(i, elem) {
var section = $(elem);
var file = section.data("file");
var copyPath = section.data("copy");
self.examplePaths.push(copyPath);
var extension = section.data("extension");
$.each(section.find(".btn-primary"), function(i, elem2) {
var obj = $(elem2);
if (obj.hasClass("btn-reset")) {
self.toggleResetButtonCSS(obj, file);
$(this).click(function() {
self.confirm("Do you want to overwrite this example?",
function(confirmed) {
if (confirmed) {
self.overwrite(copyPath, self.examplePath);
}
});
});
} else {
obj.click(function() {
self.buttonClicked(extension, file, copyPath);
});
}
});
});
},
toggleResetButtonCSS: function(btn, filename) {
var self = this;
var dfd = self.POST("/ajax/fs/exists", {
path: self.abspath(self.examplePath, filename)
});
dfd.done(function(res) {
if (res == "Failed") {
btn.css("visibility", "hidden");
} else {
btn.css("visibility", "visible");
}
});
},
// Function to setup the action that should happen, if a button is clicked.
// Within this function, the different types of extensions should be distinguished
buttonClicked: function(extension, filename, copyPath) {
var self = this;
// var filename = this.getfilename(filename);
if (extension == 'CodeEditor') {
var dfd = this.POST("/ajax/fs/exists", {
path: this.abspath(self.examplePath, filename)
});
dfd.done(function(res) {
if (res == "Failed") {
self.copy(copyPath, self.examplePath, self.openEditor, filename);
} else {
self.openEditor(self.abspath(self.examplePath, filename));
}
});
} else { //TODO: to be extended with more if statements in further versions
self.alert("No extension to open this file!"); //TODO! (text)
}
},
//empty function to open the selected file in code editor (more specialized version func in comparison to 'open_file')
openEditor: function(path) {
var ce = vispa.extensions.getExtension("codeeditor");
ce.createInstance(this.getWorkspaceId(), "center", path);
},
createDestination: function() {
var self = this;
if (this.examplePath !== "") {
var dfd = self.POST("check_destination", {
path: this.examplePath
});
dfd.done(function(res) {
if (res.success === false) {
self.alert("There was an error: " + res.type +
" The example extension has been closed.");
self.close();
return;
} else {
if (res.type == "f") {
self.alert(
/*jshint multistr: true */
"Examples destination is a file and not a directory. \
Please change the path for the examples in the preferences. \
The example extension has been closed."
);
self.close();
return;
}
if (!res.exist) {
var dfd2 = self.POST("create_folder", {
path: self.examplePath
});
dfd2.fail(function(res2) {
self.alert("Could not create destination path. Reason: " + res2.exception +
" The example extension has been closed.");
self.close();
});
}
}
});
}
},
copy: function(src, dest, callback, cbargs) {
var self = this;
callback = callback === undefined ? null : callback;
var filename = this.getfilename(src);
var dfd = this.POST("/ajax/fs/paste", {
"path": dest,
"paths": JSON.stringify(src),
"cut": false
});
dfd.done(function() {
if (callback !== null) {
callback.call(self, self.abspath(dest, cbargs));
}
});
},
overwrite: function(src, dest) {
var self = this;
var filename = this.getfilename(src);
var dfd = this.POST("/ajax/fs/remove", {
"path": JSON.stringify(self.abspath(dest, filename)),
});
dfd.done(function() {
self.copy(src, dest);
});
},
/*
overwrite: function(src, dest) {
var self = this;
var filename = this.getfilename(src);
var dfd = this.POST("rsync", {
"src": src,
"dest": dest + "/" + filename,
"opt": "-r"
});
},
*/
//empty function to copy each example in the indicated path
copyAll: function() {
var self = this;
var dest = this.examplePath;
this.confirm("Do you want to overwrite all examples in " + self.examplePath + "?",
function(confirmed) {
if (confirmed) {
$.each(self.examplePaths, function(index, elem) {
var dfd = self.POST("/ajax/fs/exists", {
path: self.abspath(self.examplePath, self.getfilename(elem))
});
dfd.done(function(res) {
if (res == "Failed") {
self.copy(elem, dest, null);
} else {
self.overwrite(elem, dest);
}
});
});
}
});
},
getfilename: function(path) {
return path.split('/').pop();
},
abspath: function(path, name) {
var len = this.examplePath.length;
if (name.substr(0, len) == this.examplePath) {