Source

tkf.bitbucket.org / rstspreadsheet-doc / spreadsheet.html

Full commit


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>The spreadsheet directive &mdash; rstSpreadsheet v0.1.2 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '',
        VERSION:     '0.1.2',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="rstSpreadsheet v0.1.2 documentation" href="index.html" />
    <link rel="prev" title="Example usages of the spreadsheet directive" href="sample.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-22829655-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="sample.html" title="Example usages of the spreadsheet directive"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">rstSpreadsheet v0.1.2 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            

  <div class="section" id="the-spreadsheet-directive">
<h1>The <a class="reference internal" href="#directive-spreadsheet" title="spreadsheet directive"><tt class="xref rst rst-dir docutils literal"><span class="pre">spreadsheet</span></tt></a> directive<a class="headerlink" href="#the-spreadsheet-directive" title="Permalink to this headline"></a></h1>
<dl class="directive">
<dt id="directive-spreadsheet">
<tt class="descname">.. spreadsheet::</tt><tt class="descclassname"> [title]</tt><a class="headerlink" href="#directive-spreadsheet" title="Permalink to this definition"></a></dt>
<dd><dl class="docutils">
<dt>eq <span class="classifier-delimiter">:</span> <span class="classifier">cell equations</span></dt>
<dd>A <a class="reference internal" href="#cell-eq"><em>Cell equation</em></a> per each line.</dd>
<dt>setup <span class="classifier-delimiter">:</span> <span class="classifier">python code (optional)</span></dt>
<dd>Python code to be executed before evaluation cell equations.</dd>
<dt>format <span class="classifier-delimiter">:</span> <span class="classifier">number: fmt [, number: fmt, ...] (optional)</span></dt>
<dd>Comma separated list of the pair of <cite>number</cite> and <cite>format</cite>
for showing the result of the cell equation.</dd>
</dl>
</dd></dl>

</div>
<div class="section" id="cell-equation">
<span id="cell-eq"></span><h1>Cell equation<a class="headerlink" href="#cell-equation" title="Permalink to this headline"></a></h1>
<p>Cell equation has the shape like this:</p>
<div class="highlight-rst"><div class="highlight"><pre>{NUM} = STATEMENT
</pre></div>
</div>
<p>or:</p>
<div class="highlight-rst"><div class="highlight"><pre>{NUM:CONDITION} = STATEMENT
</pre></div>
</div>
<p>More precisely, the syntax of the cell equation is the following:</p>
<pre>
<strong id="grammar-token-eq">eq                    </strong> ::=  <a class="reference internal" href="#grammar-token-lhs"><tt class="xref docutils literal"><span class="pre">lhs</span></tt></a> &quot;=&quot; <a class="reference internal" href="#grammar-token-rhs"><tt class="xref docutils literal"><span class="pre">rhs</span></tt></a>
<strong id="grammar-token-lhs">lhs                   </strong> ::=  &quot;{&quot; <a class="reference internal" href="#grammar-token-integer"><tt class="xref docutils literal"><span class="pre">integer</span></tt></a> [ &quot;:&quot; <a class="reference internal" href="#grammar-token-condition"><tt class="xref docutils literal"><span class="pre">condition</span></tt></a> ] &quot;}&quot;
<strong id="grammar-token-rhs">rhs                   </strong> ::=  <a class="reference internal" href="#grammar-token-expression_stmt_format"><tt class="xref docutils literal"><span class="pre">expression_stmt_format</span></tt></a>
<strong id="grammar-token-condition">condition             </strong> ::=  <a class="reference internal" href="#grammar-token-expression_stmt"><tt class="xref docutils literal"><span class="pre">expression_stmt</span></tt></a>
<strong id="grammar-token-integer">integer               </strong> ::=  &lt;see python document&gt;
<strong id="grammar-token-expression_stmt">expression_stmt       </strong> ::=  &lt;see python document&gt;
<strong id="grammar-token-expression_stmt_format">expression_stmt_format</strong> ::=  &lt;expression_stmt with the format string&gt;
</pre>
<p><a class="reference internal" href="#grammar-token-expression_stmt_format"><tt class="xref std std-token docutils literal"><span class="pre">expression_stmt_format</span></tt></a> is as same as <a class="reference internal" href="#grammar-token-expression_stmt"><tt class="xref std std-token docutils literal"><span class="pre">expression_stmt</span></tt></a>
except for that it will be formatted by the python&#8217;s <cite>str.format</cite>
function and then used as a python expression.  Defined fields are the
integers which represent the index of the columns.  For example,
<tt class="docutils literal"><span class="pre">{0}</span></tt> will be replaced by the 0-th cell of the current row.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Current version of rstSpreadsheet cannot parse the
<a class="reference internal" href="#grammar-token-condition"><tt class="xref std std-token docutils literal"><span class="pre">condition</span></tt></a> which has <tt class="docutils literal"><span class="pre">{</span></tt> or <tt class="docutils literal"><span class="pre">}</span></tt> in it.</p>
</div>
</div>
<div class="section" id="special-variables">
<h1>Special variables<a class="headerlink" href="#special-variables" title="Permalink to this headline"></a></h1>
<p>rstSpreadsheet provides the following special variables.
You can use these in the cell equation.
Note that you can override these variables by variables in <cite>:setup:</cite>.</p>
<dl class="data">
<dt id="col">
<tt class="descname">col</tt><a class="headerlink" href="#col" title="Permalink to this definition"></a></dt>
<dd><p>This stores the <em>above</em> cells of the current column.
Thus, <cite>col[-1]</cite> means the previous cell.</p>
<dl class="class">
<dt id="rstspreadsheet.ListLike">
<em class="property">class </em><tt class="descclassname">rstspreadsheet.</tt><tt class="descname">ListLike</tt><big>(</big><em>data=None</em><big>)</big><a class="headerlink" href="#rstspreadsheet.ListLike" title="Permalink to this definition"></a></dt>
<dd><p>An iterative class with convenient cast functions</p>
<div class="highlight-rst"><div class="highlight"><pre>&gt;&gt;&gt; col = ListLike([&#39;1&#39;, &#39;2&#39;, &#39;3&#39;])
&gt;&gt;&gt; col
ListLike([&#39;1&#39;, &#39;2&#39;, &#39;3&#39;])
&gt;&gt;&gt; &#39;, &#39;.join(col)
&#39;1, 2, 3&#39;
&gt;&gt;&gt; col.str
[&#39;1&#39;, &#39;2&#39;, &#39;3&#39;]
&gt;&gt;&gt; col.int
[1, 2, 3]
&gt;&gt;&gt; col.float
[1.0, 2.0, 3.0]
</pre></div>
</div>
<dl class="attribute">
<dt id="rstspreadsheet.ListLike.str">
<tt class="descname">str</tt><a class="headerlink" href="#rstspreadsheet.ListLike.str" title="Permalink to this definition"></a></dt>
<dd><p>Access the stored data as a list of strings (original data)</p>
</dd></dl>

<dl class="attribute">
<dt id="rstspreadsheet.ListLike.int">
<tt class="descname">int</tt><a class="headerlink" href="#rstspreadsheet.ListLike.int" title="Permalink to this definition"></a></dt>
<dd><p>Access the stored data as a list of ints</p>
</dd></dl>

<dl class="attribute">
<dt id="rstspreadsheet.ListLike.float">
<tt class="descname">float</tt><a class="headerlink" href="#rstspreadsheet.ListLike.float" title="Permalink to this definition"></a></dt>
<dd><p>Access the stored data as a list of floats</p>
</dd></dl>

<dl class="method">
<dt id="rstspreadsheet.ListLike.sum">
<tt class="descname">sum</tt><big>(</big><em>type='float'</em><big>)</big><a class="headerlink" href="#rstspreadsheet.ListLike.sum" title="Permalink to this definition"></a></dt>
<dd><p>Get the sum of the stored data</p>
<div class="highlight-rst"><div class="highlight"><pre>&gt;&gt;&gt; col = ListLike([&#39;1&#39;, &#39;2&#39;, &#39;3&#39;])
&gt;&gt;&gt; col.sum(&#39;int&#39;)
6
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="rstspreadsheet.ListLike.mean">
<tt class="descname">mean</tt><big>(</big><big>)</big><a class="headerlink" href="#rstspreadsheet.ListLike.mean" title="Permalink to this definition"></a></dt>
<dd><p>Get the mean of the stored data</p>
<div class="highlight-rst"><div class="highlight"><pre>&gt;&gt;&gt; col = ListLike([&#39;1&#39;, &#39;2&#39;, &#39;3&#39;])
&gt;&gt;&gt; col.mean()
2.0
</pre></div>
</div>
</dd></dl>

</dd></dl>

</dd></dl>

<dl class="data">
<dt id="cols">
<tt class="descname">cols</tt><a class="headerlink" href="#cols" title="Permalink to this definition"></a></dt>
<dd><p>A variable to access all :py:data`col`.
If the current column is 1, <cite>col</cite> is as same as <cite>cols[1]</cite>.</p>
</dd></dl>

<dl class="data">
<dt id="i">
<tt class="descname">i</tt><a class="headerlink" href="#i" title="Permalink to this definition"></a></dt>
<dd><p>Index of the current row.</p>
</dd></dl>

<dl class="data">
<dt id="last">
<tt class="descname">last</tt><a class="headerlink" href="#last" title="Permalink to this definition"></a></dt>
<dd><p>Index of the last row.  This is useful in the <a class="reference internal" href="#grammar-token-condition"><tt class="xref std std-token docutils literal"><span class="pre">condition</span></tt></a>.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">{</span><span class="mi">1</span><span class="p">:</span><span class="n">i</span><span class="o">&lt;</span><span class="n">last</span><span class="p">}</span> <span class="o">=</span> <span class="n">i</span>
<span class="p">{</span><span class="mi">1</span><span class="p">:</span><span class="n">i</span><span class="o">==</span><span class="n">last</span><span class="p">}</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">col</span><span class="o">.</span><span class="n">int</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

</div>


<h1>Comments</h1>
<div id="disqus_thread"></div>
<script type="text/javascript">
    var disqus_shortname = 'tkfdocs'; // required
    // highly recommended additional parameters
    var disqus_identifier = 'rstSpreadsheet/spreadsheet';
    // var disqus_url = 'http://example.com/permalink-to-page.html';

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">The <tt class="docutils literal"><span class="pre">spreadsheet</span></tt> directive</a></li>
<li><a class="reference internal" href="#cell-equation">Cell equation</a></li>
<li><a class="reference internal" href="#special-variables">Special variables</a></li>
</ul>

<h3><a href="#disqus_thread">Add New Comment ✎</a></h3>
<ul><li>
    <a class="reference internal" href="#disqus_thread">
      Go to the bottom!
    </a>
</li></ul>
  <h4>Previous topic</h4>
  <p class="topless"><a href="sample.html"
                        title="previous chapter">Example usages of the <cite>spreadsheet</cite> directive</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/spreadsheet.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="sample.html" title="Example usages of the spreadsheet directive"
             >previous</a> |</li>
        <li><a href="index.html">rstSpreadsheet v0.1.2 documentation</a> &raquo;</li> 
      </ul>
    </div>

    <div class="footer">
        &copy; Copyright 2011, Takafumi Arakaki.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>