Permalink
Browse files

Merge pull request #125 from pwaller/121-fix-todos

Improvements to old TODOs
  • Loading branch information...
2 parents 48cbf14 + b63cb71 commit 6d0355bb2567438f9d365b26b2cfe9f77b2b7180 @cdeil cdeil committed Apr 7, 2013
@@ -139,11 +139,21 @@ def p(self, parent, key, param, value):
"""
Store a parameter
- (BUG)
- Note: This does not cause the action to enter the traversal hierarchy
+ TODO(pwaller)
+
+ We want to support /!p/logy/1/, for example, to set options through the
+ URL. This could allow /!p/logy/0,1/ to create a multitraverser
+ with both types of plots.
+
+ The current technique doesn't work, because:
+
+ This does not cause the action to enter the traversal hierarchy
because `from_parent` isn't used. What is needed is a way to create
a copy of `self` which can be placed correctly into the hierarchy.
(pwaller) doesn't currently know how to achieve this reliably.
+
+ It's possible we can achieve this by making a special resource which
+ wraps `self` but knows its place in the heirarchy.
"""
self.request.params.multi.dicts += ({param: value},)
return self
@@ -229,7 +239,10 @@ def content(self):
class CodeDefinition(Renderer):
"""
Represents the source code of a function object
- TODO(pwaller): Support for classes, link to online viewer
+
+ TODO(pwaller)
+
+ It would be nice to support classes and provide links to github.
"""
def __init__(self, request, function):
super(CodeDefinition, self).__init__(request, self, None)
@@ -250,20 +250,6 @@ def line(x, yrange):
legend = get_legend(mc=objs)
legend.Draw()
- return
-
- if "unit_fixup" in params:
- h = fixup_hist_units(h)
-
- if "nostat" in params:
- h.SetStats(False)
-
- if "notitle" in params:
- h.SetTitle("")
-
- # TODO(pwaller): bring back draw options
- h.Draw()
-
class EbkeCombinationStackRenderer(RootRenderer):
@@ -435,20 +421,6 @@ def line(x):
p = preliminary()
p.Draw("hist e0x0")
- return
-
- if "unit_fixup" in params:
- h = fixup_hist_units(h)
-
- if "nostat" in params:
- h.SetStats(False)
-
- if "notitle" in params:
- h.SetTitle("")
-
- # TODO(pwaller): bring back draw options
- h.Draw("hist e0x0")
-
class CombinationDualRenderer(RootRenderer):
def render(self, canvas):
@@ -1,83 +0,0 @@
-from os import listdir
-from os.path import basename, exists, isfile, isdir, join as pjoin
-
-import fnmatch
-import re
-
-from pyramid.traversal import traverse
-from pyramid.url import static_url
-from pyramid.httpexceptions import HTTPNotFound
-
-import ROOT as R
-
-from .locationaware import LocationAware
-from .multitraverser import MultipleTraverser
-from .root.file import RootFileTraverser
-from ._markdown import MarkdownResource
-
-
-class FilesystemTraverser(LocationAware):
- section = "directory"
-
- def __init__(self, request, path=None):
- self.request = request
- self.path = path or request.registry.settings["results_path"]
-
- @property
- def name(self):
- return basename(self.path)
-
- @property
- def icon_url(self):
- if isdir(self.path):
- return static_url('weboot:static/folder_32.png', self.request)
-
- if exists(self.path) and isfile(self.path):
- if self.name.endswith(".root"):
- return static_url('weboot:static/folder_chart_32.png', self.request)
-
- return static_url('weboot:static/close_32.png', self.request)
-
- @property
- def content(self):
- def link(p):
- url = self.request.resource_url(self, p)
- return '<p><a href="{0}">{1}</a></p>'.format(url, p)
- return "".join(link(p) for p in self.ls)
-
- @property
- def items(self):
- items = [self[i] for i in self]
- items = [i for i in items if i]
- items.sort(key=lambda o: o.name)
- return items
-
- def keys(self):
- try:
- return sorted(listdir(self.path))
- except OSError as err:
- raise HTTPNotFound("Failed to open {0}: {1}".format(self.path, err))
-
- def __iter__(self):
- return iter(self.keys())
-
- def __getitem__(self, key):
- path = pjoin(self.path, key)
- if isfile(path) and path.endswith(".markdown"):
- return MarkdownResource.from_parent(self, key, path)
-
- if isfile(path) and path.endswith(".root"):
- # TODO(pwaller): This belongs inside the RootFileTraverser
- # constructor
- # File
- f = R.TFile(path)
- if f.IsZombie() or not f.IsOpen():
- raise HTTPNotFound("Failed to open {0}".format(path))
- return RootFileTraverser.from_parent(self, key, f)
-
- elif isdir(path):
- # Subdirectory
- return FilesystemTraverser.from_parent(self, key, path)
-
- elif MultipleTraverser.should_multitraverse(key):
- return MultipleTraverser.from_listable(self, key)
@@ -24,13 +24,6 @@ def icon(self):
"""
return None
- @property
- def forward_url(self):
- """
- TODO(pwaller): Fix or eliminate this
- """
- pass
-
def sub_url(self, *args, **kwargs):
return self.request.resource_url(self, *args, **kwargs)
@@ -192,10 +192,6 @@ class UserThrow(RuntimeError):
self.configure_canvas(params, canvas)
self.render(canvas)
- if self.format == "xml":
- # TODO(pwaller): special case
- raise NotImplementedError()
-
canvas.Update()
try:
canvas.SaveAs(tmpfile.name)
@@ -206,11 +202,6 @@ class UserThrow(RuntimeError):
else:
raise
- # TODO(pwaller): figure out why these two lines are preventing
- # blank images. (wtf?)
- # Response(pwaller): global canvas lock seems to have fixed the
- # problem, but it's still a black box.
- # with open(tmpfile.name) as eps_fd: epsdata = eps_fd.read()
log.info("RENDERING {0} -- {1}".format(self.format, rootformat))
if self.format == rootformat:
# No conversion necessary, ROOT did it directly.
@@ -19,8 +19,11 @@
class HistogramTable(RootObject):
"""
- TODO(pwaller): Fixme
+ Display the histogram as a table.
+
+ Currently only works for 1D histograms with labelled bins.
"""
+
@property
def content(self):
if "cut" not in self.name:
@@ -106,7 +109,6 @@ def render(self, canvas):
if "notitle" in params:
h.SetTitle("")
- # TODO(pwaller): bring back draw options
h.Draw(build_draw_params(h, params))
keepalive(canvas, h)
@@ -363,6 +365,11 @@ def table(self, parent, key):
class FreqHist(Histogram):
+ """
+ If the x-axis bin labels are pdgids, replace them with ROOT latex for that
+ pdgid and show the y axis in percentage.
+ """
+
def __init__(self, request, root_object):
from cPickle import loads
freqs = loads(root_object.ReadObj().GetString().Data())
@@ -371,9 +378,9 @@ def __init__(self, request, root_object):
root_object = R.TH1D("frequencies", "frequencies;frequencies;%", n, 0, n)
+ from pkg_resources import resource_string
from yaml import load
- # TODO(pwaller): use resource string
- pdgs = load(open("pdg.yaml"))
+ pdgs = load(resource_string("weboot.utils", "pdg.yaml"))
sorted_freqs = sorted(freqs.iteritems(), key=lambda (k, v): v, reverse=True)
for i, (pdgid, value) in enumerate(sorted_freqs, 1):
@@ -56,11 +56,12 @@ def draw(self, parent, key, arg):
@log.trace()
def draw(t):
+ # TODO(pwaller): Move this to use rootpy's Tree.draw instead which
+ # solves some of the problems for us.
if self.binning:
- # TODO(pwaller): gDirectory needs to be thread-unique. Otherwise:
- # bad bad, sad sad.
- # TODO(pwaller): Parse self.binning, call appropriate h.
+ # TODO(pwaller): gDirectory needs to be thread-unique.
+ # Otherwise: bad bad, sad sad.
def mkbin(b):
n, low, hi = b.split(",")
@@ -74,7 +75,7 @@ def mkbin(b):
else:
raise NotImplementedError("Not implemented yet for {0} dims".format(len(dims)))
h.SetDirectory(R.gDirectory)
- # BUG: TODO(pwaller): Memory leak
+ # TODO(pwaller): BUG: Memory leak
R.SetOwnership(h, False)
nvar = len(arg.split(":"))
View
@@ -18,8 +18,6 @@
def view_root_object(context, request):
- if context.forward_url:
- return HTTPFound(location=context.forward_url)
return dict(path=build_breadcrumbs(context),
content="\n".join(context.content),
sidebar="<!-- Hello world -->")
@@ -105,9 +105,6 @@ def view_multitraverse(multitravese_context, request):
str_index_tuple[0], multitravese_context.fill_slot(0, this_idx)))
prev_idx = index_tuple[0]
if not context.icon:
- # TODO(pwaller): If a context doesn't have an icon, we should
- # show something else, but I haven't decided what
- # yet
if isinstance(context, MultipleTraverser):
for i, c in context.indexed_contexts:
content.append('<a href="{1.url}?{2}">{0}</a>'.format(
@@ -124,6 +121,11 @@ def view_multitraverse(multitravese_context, request):
request.environ.get("QUERY_STRING", ""))
content.append(fmt.format(values))
continue
+ else:
+ # TODO(pwaller): If a context doesn't have an icon, we should
+ # show something else, but I haven't decided what
+ # yet
+ pass
fmt = '<a href="{1.url}"><img class="plot" src="{1.icon_url}?{2}" title="{0}" /></a>'
values = (" / ".join(str_index_tuple), context, request.environ.get("QUERY_STRING", ""))
content.append(fmt.format(values))
@@ -1,28 +0,0 @@
-from .. import log
-log = log[__name__]
-
-import ROOT as R
-
-from pyramid.httpexceptions import HTTPFound
-from pyramid.response import Response
-from pyramid.url import static_url
-
-from ...utils.timer import timer
-
-
-@log.trace()
-def view_root_object_render(context, request):
- """
- Only called if the object doesn't inherit from Renderable
- """
-
- if request.params.get("render", "") == "xml":
- o = context.obj
- xmlfile = R.TXMLFile("test.xml", "recreate")
- o.Write()
- xmlfile.Close()
- with open("test.xml") as fd:
- content = fd.read()
- return Response(content, content_type="text/plain")
-
- return HTTPFound(location=static_url('weboot:static/close_32.png', request))

0 comments on commit 6d0355b

Please sign in to comment.