from qp.sites.extreme.lib.config import image_dir, homeurl __version__ = "0.0.1 2011.01.28" __date__ = "2011.01.28" __catalog__ = "UNITS-CONV-001" __author__ = "ernesto.adorio@gmail.com" __url__ = homeurl + "solvers/units/" __title__ = "Fundamental Units Conversion Page" from qp.pub.common import get_session from qp.fill.css import BASIC_FORM_CSS from qp.fill.directory import Directory from quixote.errors import PublishError from quixote.util import dump_request from qp.fill.form import Form from qp.fill.widget import CheckboxWidget,StringWidget,SingleSelectWidget, StringWidget, TextWidget from qp.pub.common import header, footer, page, redirect from qp.sites.extreme.lib.uicommon import renderheader, renderfooter, processheader, processfooter import time import urllib from unitslib import Length, Mass, Time, convert import urllib, urllib2, os from qp.sites.extreme.lib.webutils import before, after from qp.sites.extreme.lib import config def getstatusoutput(command): """ Fredrick Lundh http://mail.python.org/pipermail/python-list/2006-October/406444.html """ from subprocess import Popen, PIPE, STDOUT p = Popen(command, stdout=PIPE, stderr=STDOUT, shell=True) s = p.stdout.read().split("\n") return p.wait(), s class UnitsDirectory(Directory): def get_exports(self): yield '', 'index', 'NetTools server', None def index (self): form = Form(enctype = "multipart/form-data") # enctype for file upload form.add(StringWidget, name = "qty_length", value = "1.0", size = 30) length_options = [] for key in Length: length_options.append(key) form.add(SingleSelectWidget, name = "unit_length", value = "meter", options=length_options ) form.add(StringWidget, name = "qty_mass", value = "1.0", size = 30) mass_options = [] for key in Mass: mass_options.append(key) form.add(SingleSelectWidget, name = "unit_mass", value = "kilogram", options=mass_options ) form.add(StringWidget, name = "qty_time", value = "1.0", size = 30) time_options = [] for key in Time: time_options.append(key) form.add(SingleSelectWidget, name = "unit_time", value = "second", options=time_options ) form.add_hidden("time", value = time.time()) form.add_submit("submit", "submit") def render [html] (): renderheader(__title__) if 1: """Length Unit
%s | %s |
Mass Unit
%s | %s |
Time Unit
%s | %s |
" qty = float(form.get("qty_length")) unit = form.get("unit_length") " Length Conversion"'
" | " "" qty = float(form.get("qty_mass")) unit = form.get("unit_mass") " Mass Conversion"'
" | " "" qty = float(form.get("qty_time")) unit = form.get("unit_time") " Time Conversion"'
" | " "
Yuck! the html output code is being translated by a browser! Use your browswerĊ View Source facility to recover the original contents.
Codes are provided for educational use. Please make the proper attribution.
Only the fundamental units for Length, Mass and Time are considered here, we will add unit conversions for other quantities such as Area, Volume/Capacity, Work/Energy, Pressure and others.
The solver page may be accessed at http://extreme.adorio-research.org/solvers/units/.
The Python code units.py which is called by the above QP interface code above is at http://adorio-research.org/wordpress/?p=10377.
Our reference to conversion values is http://physics.nist.gov/Pubs/SP811/appenB9.html#LENGTH
for length units. The Mass and Time units are similarly obtained from NIST.
Thank you
ReplyDeleteNice web online tool in below web site
http://www.nicewebtools.com/UnitConversion/LengthConversion.aspx for Length Conversion