Commits

Matt Bone committed 8d0e51c

formatting changes. gross lower() calls all over the place

Comments (0)

Files changed (7)

growthrates/inputs/urls.py

     url(r'^$', 'index', name='index'),
     url(r'^growing/at/(?P<rate>\d+)/percent/per/(?P<period>(year)|(month))$', 'growing_at', name='growing_at'),
     url(r'^growing/at/(?P<rate>\d+\.\d+)/percent/per/(?P<period>(year)|(month))$', 'growing_at', name='growing_at'),
+    url(r'^growing/at/(?P<rate>\.\d+)/percent/per/(?P<period>(year)|(month))$', 'growing_at', name='growing_at'),
     url(r'^doubling/every/(?P<rate>\d+)/(?P<period>(years)|(months))$', 'doubling_at', name='doubling_at'),
     url(r'^doubling/every/(?P<rate>\d+\.\d+)/(?P<period>(years)|(months))$', 'doubling_at', name='doubling_at'),
+    url(r'^doubling/every/(?P<rate>\.\d+)/(?P<period>(years)|(months))$', 'doubling_at', name='doubling_at'),
     url(r'^about$', 'about', name='about'),
 )

growthrates/inputs/views.py

         rate_obj = cls()
         rate_obj.growth_rate = growth_rate
         rate_obj.doubling_rate = math.log(2)/math.log1p(growth_rate)
-        rate_obj.period = period
+        rate_obj.set_period(period)
 
         return rate_obj
 
             self.period = "Year"
 
 
-    def get_data_array(self, initial_value=100, num_points=25):
+    def get_data_array(self, initial_value=100, num_points=26):
         data_array = []
         curr = initial_value
         data_array.append([0, initial_value])
             if form.cleaned_data["type"] == "growing":
                 return HttpResponseRedirect(reverse("growing_at",
                                                     args=(floatformat(form.cleaned_data["rate"], "-2"),
-                                                          form.cleaned_data["period"])))
+                                                          form.cleaned_data["period"].lower())))
             elif form.cleaned_data["type"] == "doubling":
                 return HttpResponseRedirect(reverse("doubling_at",
                                                     args=(floatformat(form.cleaned_data["rate"], "-2"),
-                                                    form.cleaned_data["period"]+"s")))
+                                                    (form.cleaned_data["period"]+"s").lower())))
         else:
             print form.errors
             type = request.POST.get("type", "growing")

growthrates/jinja2_for_django.py

 from django.core import urlresolvers
 from django.conf import settings
 from django.template.defaultfilters import floatformat
+from django.contrib.humanize.templatetags.humanize import intcomma
 import jinja2
 
 class Template(jinja2.Template):
     env.globals['url_for'] = urlresolvers.reverse
     env.globals['MEDIA_URL'] = settings.MEDIA_URL
     env.globals['floatformat'] = floatformat
+    env.globals['intcomma'] = intcomma
     #env.globals['STATIC_URL'] = settings.STATIC_URL
 
     def load_template(self, template_name, template_dirs=None):

growthrates/templates/about.html

 {% extends "base.html" %}
 
 {% block content %}
-    <h1>About</h1>
+    <h1>About growth-rates.com</h1>
 
-    <p>Coming soon...</p>
+    <p>
+        Numbers can be confusing and can sometimes obscure reality if we don't think about them carefully.  For example
+        something <a href="{{ url_for("growing_at", args=("7", "year"))}}">growing at 7% per year</a> sounds fairly
+        innocuous, but this is nearly the same thing as <a href="{{ url_for("doubling_at", args=("10", "years")) }}">
+        doubling every 10 years</a> which sounds very different!
+    </p>
 
+    <p>This site hopes to simplify and bring some intuition to these types of numbers.</p>
+
+    <h2>For more information</h2>
+    <ul>
+        <li><a href="http://en.wikipedia.org/wiki/Exponential_growth">http://en.wikipedia.org/wiki/Exponential_growth</a></li>
+        <li><a href="http://en.wikipedia.org/wiki/Doubling_time">http://en.wikipedia.org/wiki/Doubling_time</a></li>
+        <li><a href="http://en.wikipedia.org/wiki/Rule_of_72">http://en.wikipedia.org/wiki/Rule_of_72</a></li>
+    </ul>
 {% endblock %}

growthrates/templates/base.html

 
 
     <footer>
-        <p><a href="{{ url_for("about") }}">about</a> | <a href="http://bitbucket.org/thatmattbone/growthrates">get the code</a> | by <a href="http://thatmattbone.com">Matt Bone</a></p>
+        <p><a href="{{ url_for("index") }}">home</a> | <a href="{{ url_for("about") }}">about</a> | <a href="http://bitbucket.org/thatmattbone/growthrates">get the code</a> | by <a href="http://thatmattbone.com">Matt Bone</a></p>
     </footer>
 
 </div> <!-- /container -->

growthrates/templates/doubling.html

 {% extends "base.html" %}
 
 {% block content %}
-    <h1>Doubling Every {{ rate }} {{ period }}s</h1>
+    <h1>Something doubling every {{ rate }} {{ period.lower() }}s...</h1>
 
-    <p>Is the same as <a href="{{ url_for("growing_at", args=(growth_rate, period.lower())) }}">growing at {{ growth_rate }}% per {{ period.lower() }}.</a></p>
-
-    <h2>If you had $100 doubling every {{ rate }} {{ period.lower() }}s</h2>
-
-    <div id="doubling-graph" style="width:600px;height:300px;"></div>
-
-    <h2 style="padding-top: 25px">Or in table form...</h2>
-    <table class="span5 zebra-striped">
-        <thead>
-        <th>{{ period }}</th>
-        <th>Dollars</th>
-        </thead>
-        {% for n, m in data_array %}
-            <tr>
-                <td>{{ n }}</td>
-                <td>${{ floatformat(m, "-2") }}</td>
-            </tr>
-        {% endfor %}
-    </table>
-
+    <ul>
+        <li>Is the same as <a href="{{ url_for("growing_at", args=(growth_rate, period.lower())) }}">growing at {{ growth_rate }}% per {{ period.lower() }}.</a></li>
+        <li>If you had <strong>$100</strong> doubling every {{ rate }} {{ period.lower() }}s, after <strong>{{ data_array|length - 1 }} {{ (period+"s").lower() }}</strong> you'd have <strong>${{ intcomma(floatformat(data_array[-1][1], "-2")) }}</strong>.
+            <div style="padding: 25px 0px 25px 0px; ">
+                <div id="growth-graph" style="width:400px;height:244px;"></div>
+            </div>
+            <a href="" id="show-value-table">Click to see a table of these values by {{ period.lower() }}...</a>
+            <table class="span5 zebra-striped" style="display: none;" id="value-table">
+                <thead>
+                <th>{{ period }}</th>
+                <th>Dollars</th>
+                </thead>
+                {% for n, m in data_array %}
+                    <tr>
+                        <td>{{ n }}</td>
+                        <td>${{ intcomma(floatformat(m, "-2")) }}</td>
+                    </tr>
+                {% endfor %}
+            </table>
+        </li>
+    </ul>
     <script type="text/javascript">
         $(function () {
-            $.plot($("#doubling-graph"), [{{ json_data_array }}]);
+            $("#show-value-table").click(function() {$("#value-table").show(200); return false; });
+            $.plot($("#growth-graph"), [{{ json_data_array }}]);
         });
     </script>
-{% endblock %}
+    <hr/>
+    <p><a href="{{ url_for("index") }}">Go back and find more growth rates.</a></p>
+{% endblock %}

growthrates/templates/growing.html

 {% extends "base.html" %}
 
 {% block content %}
-    <h1>Growing at {{ rate }}% per {{ period }}</h1>
-    
-    <p>Is the same as <a href="{{ url_for("doubling_at", args=(doubling_rate, period+"s")) }}">doubling every {{ doubling_rate }} {{ period }}s.</a></p>
+    <h1>Something growing at {{ rate }}% per {{ period.lower() }}...</h1>
 
-    <h2>If you had $100 growing at {{ rate }}% per {{ period }}...</h2>
-
-    <div id="growth-graph" style="width:600px;height:300px;"></div>
-
-    <h2 style="padding-top: 25px">Or in table form...</h2>
-    <table class="span5 zebra-striped">
-        <thead>
-            <th>{{ period }}</th>
-            <th>Dollars</th>
-        </thead>
-    {% for n, m in data_array %}
-    <tr>
-        <td>{{ n }}</td>
-        <td>${{ floatformat(m, "-2") }}</td>
-    </tr>
-    {% endfor %}
-    </table>
-
+    <ul>
+        <li>Is the same as <a href="{{ url_for("doubling_at", args=(doubling_rate, (period+"s").lower())) }}">doubling every {{ doubling_rate }} {{ period.lower() }}s.</a></li>
+        <li>If you had <strong>$100</strong> growing at {{ rate }}% per {{ period.lower() }} after <strong>{{ data_array|length - 1 }} {{ (period+"s").lower() }}</strong> you'd have <strong>${{ intcomma(floatformat(data_array[-1][1], "-2")) }}</strong>.
+            <div style="padding: 25px 0px 25px 0px; ">
+            <div id="growth-graph" style="width:400px;height:244px;"></div>
+            </div>
+            <a href="" id="show-value-table">Click to see a table of these values by {{ period.lower() }}...</a>
+            <table class="span5 zebra-striped" style="display: none;" id="value-table">
+                <thead>
+                <th>{{ period }}</th>
+                <th>Dollars</th>
+                </thead>
+                {% for n, m in data_array %}
+                    <tr>
+                        <td>{{ n }}</td>
+                        <td>${{ intcomma(floatformat(m, "-2")) }}</td>
+                    </tr>
+                {% endfor %}
+            </table>
+        </li>
+    </ul>
     <script type="text/javascript">
         $(function () {
+            $("#show-value-table").click(function() {$("#value-table").show(200); return false; });
             $.plot($("#growth-graph"), [{{ json_data_array }}]);
         });
     </script>
+    <hr/>
+    <p><a href="{{ url_for("index") }}">Go back and find more growth rates.</a></p>
 {% endblock %}