def buildStatTable(stats_info): return TableView(hover=True, column_names=('Gage', 'Parameter', '25th %', '50th %', '75th %'), rows=stats_info['stats'], bordered=True, condensed=True)
def test(request): parcel_button = Button(display_text='Update Parcel', name='parcel_button', style='', icon='', href='', submit=False, disabled=False, attributes={"onclick": "dimensionmodal()"}, classes='') select_district = SelectInput( display_text='Select an Irrigation District:', name='select1', multiple=False, original=True, options=[('Yaque Del Sur', '1'), ('San Juan', '2'), ('Sabaneta', '3')], initial=['']) update_button = Button(display_text='Update Parcel', name='update_parcels', style='success', icon='glyphicon glyphicon-plus', href='', submit=False, disabled=False, attributes={"onclick": "hidedimmodal()"}, classes='') parcel_data_edit = TableView(column_names=('Attribute', 'Value (ft)'), rows=[ ('Parcel ID', 012345), ('Owner First Name', 'First Name'), ('Owner Last Name', 'Last Name'), ('Age (years)', 30), ('Gender (M/F)', 'M'), ('Area (ac)', 540), ('Purcahse Date', 'MM/DD/YYYY'), ('Area Planted (ac)', 450), ], hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, 'Value (ft)'), row_ids=[21, 25, 31]) context = { 'parcel_button': parcel_button, 'parcel_data_edit': parcel_data_edit, 'update_button': update_button, 'select_district': select_district } return render(request, 'cultivar/test.html', context)
def results(request): """ Controller for the results page. """ if request.POST and 'submit' in request.POST: session = SessionMaker() flowlist = results plotData = [] for i in flowlist: value = list(i) plotData.append(value) fdc_tbv = TableView(column_names=('Percent (%)', unicode('Flow (M' + u'\u00b2' + ' /S)')), rows=flowlist, hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, False, False), row_ids=[range(0, len(flowlist))]) plot_view = LinePlot(height='100%', width='100%', engine='highcharts', title='Flow-Duration Curve', spline=True, x_axis_title='Percent (%)', y_axis_title='Flow', y_axis_units='m^3/s', series=[{ 'name': 'Flow', 'color': '#277554', 'marker': { 'enabled': False }, 'data': plotData }]) session.close() context = {'fdc_tbv': fdc_tbv, 'plot_view': plot_view} #else: #raise Http404("No request submitted.") return render(request, 'fdc/results.html', context)
def get_metadata_table_html(request, title, metadata, boarders=False): """ Create HTML table for metadata property and value pairs. Any values that are dictionaries will (recursively) be converted into sub-tables. """ sub_tables = dict() rows = list() for k, v in metadata.items(): value = v if isinstance(v, dict): try: # convert keys that can be integers to get around limitation in string formatting syntax k = int(k) except ValueError: # if key cannot be cast as an integer then just use the original key pass value = '{{sub_tables[{0}]}}'.format(k) sub_tables[k] = get_metadata_table_html(request, None, v, True) if isinstance(v, str): # this is required so the '{}' characters render correctly after string formatting value = v.replace('{', '{{').replace('}', '}}') rows.append((k, value)) column_names = ('Property', 'Value') table_view_options = TableView(column_names=column_names, rows=rows, hover=True, striped=True, bordered=boarders, condensed=False) context = { 'title': title, 'table_view_options': table_view_options, } html = render(request, 'quest/metadata.html', context).content.decode('utf-8') html = html.format(sub_tables=sub_tables) return html
def demand_calculator(request): months = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ] k_value_options = [('Maiz(Iniciales)', 0.4), ('Maiz(Desarollo)', 0.8), ('Maiz(Mediados)', 1.125), ('Maiz(Finales)', 1.075), ('Maiz(Recoleccion)', 0.875), ('Platano(Iniciales)', 0.45), ('Platano(Desarollo)', 0.775), ('Platano(Mediados)', 1.05), ('Platano(Finales)', 0.95), ('Platano(Recoleccion)', 0.8), ('Cana(Iniciales)', 0.6), ('Cana(Desarollo)', 0.8), ('Cana(Mediados)', 1), ('Cana(Finales)', 0.85), ('Cana(Recoleccion)', 0.75), ('Arroz(Iniciales)', 1.125), ('Arroz(Desarollo)', 1.3), ('Arroz(Mediados)', 1.2), ('Arroz(Finales)', 1), ('Arroz(Recoleccion)', 1), ('Other...(Specify)', 999)] select_district = SelectInput( display_text='Select an Irrigation District:', name='select1', multiple=False, original=True, options=[ ('Yaque Del Sur', '219114'), ('Valle de San Juan', '609024'), ('Lago Enriquillo', '413236'), ('Azua', '871546'), ('Laguna de Cabral', '700'), ], initial=['']) select_crop_number = SelectInput( display_text='Number of Crop Types Planted:', name='select_crop_number', multiple=False, original=True, options=[('1', 1), ('2', 2), ('3', 3), ('4', 4)], initial=['1'], attributes={'onchange': "cropnumber()"}) select_crop_type = SelectInput( display_text='Crop Type(Growth Stage):', name='kValue1', multiple=False, original=True, options=k_value_options, attributes={ 'onchange': "$('.user-k-value').toggleClass('hidden', this.value != 999)" }) input_k_value = TextInput(display_text='Crop K Value', name='kValue2') input_crop_name = TextInput(display_text='Crop Type', name='cropName') select_crop_2_type = SelectInput( display_text='Crop Type(Growth Stage):', name='k2Value1', multiple=False, original=True, options=k_value_options, attributes={ 'onchange': "$('.user-k-value').toggleClass('hidden', this.value != 999)" }) input_k_2_value = TextInput(display_text='Crop K Value', name='k2Value2') input_crop_2_name = TextInput(display_text='Crop Type', name='crop2Name') select_crop_3_type = SelectInput( display_text='Crop Type(Growth Stage):', name='k3Value1', multiple=False, original=True, options=k_value_options, attributes={ 'onchange': "$('.user-k-value').toggleClass('hidden', this.value != 999)" }) input_k_3_value = TextInput(display_text='Crop K Value', name='k3Value2') input_crop_3_name = TextInput(display_text='Crop Type', name='crop3Name') select_crop_4_type = SelectInput( display_text='Crop Type(Growth Stage):', name='k4Value1', multiple=False, original=True, options=k_value_options, attributes={ 'onchange': "$('.user-k-value').toggleClass('hidden', this.value != 999)" }) input_k_4_value = TextInput(display_text='Crop K Value', name='k4Value2') input_crop_4_name = TextInput(display_text='Crop Type', name='crop4Name') input_parameters_button = Button(display_text='Input Parameters', name='input-parameters-button', icon='', style='', submit=False, disabled=False, attributes={"onclick": "watermodal()"}, classes='') calculate_button = Button(display_text='Calculate Demand', name='calculate_demand', style='success', icon='glyphicon', href='', submit=False, disabled=False, attributes={"onclick": "calculate_demand()"}, classes='') area_seeded_1 = TextInput(display_text='Area Seeded(tareas)', name='area_seeded_1', placeholder='e.g.: 10.00', prepend='*') area_seeded_2 = TextInput(display_text='Area Seeded(tareas)', name='area_seeded_2', placeholder='e.g.: 10.00', prepend='*') area_seeded_3 = TextInput(display_text='Area Seeded(tareas)', name='area_seeded_3', placeholder='e.g.: 10.00', prepend='*') area_seeded_4 = TextInput(display_text='Area Seeded(tareas)', name='area_seeded_4', placeholder='e.g.: 10.00', prepend='*') close_button = Button(display_text='Close', name='close_button', style='', icon='', href='', submit=False, disabled=False, attributes={"onclick": "hideresultmodal()"}, classes='') water_results = TableView( column_names=('Crop Type', 'Area of Planted Crop (ac)', 'Total Demand for specified time period (ac-ft)'), rows=[ ('Corn', 150, 47), ('Cocoa', 200, 58), ('Rice', 75, 35), ('Total', 425, 140), ], hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, False), row_ids=[21, 25, 31]) context = { 'input_crop_name': input_crop_name, 'input_k_value': input_k_value, 'input_crop_2_name': input_crop_2_name, 'input_k_2_value': input_k_2_value, 'input_crop_3_name': input_crop_3_name, 'input_k_3_value': input_k_3_value, 'input_crop_4_name': input_crop_4_name, 'input_k_4_value': input_k_4_value, 'k_value_options': k_value_options, 'area_seeded_1': area_seeded_1, 'area_seeded_2': area_seeded_2, 'area_seeded_3': area_seeded_3, 'area_seeded_4': area_seeded_4, 'months': months, 'water_results': water_results, 'close_button': close_button, 'calculate_button': calculate_button, 'select_crop_type': select_crop_type, 'select_crop_2_type': select_crop_2_type, 'select_crop_3_type': select_crop_3_type, 'select_crop_4_type': select_crop_4_type, 'select_crop_number': select_crop_number, 'input_parameters_button': input_parameters_button, 'select_district': select_district, } return render(request, 'cultivar/demand_calculator.html', context)
def resultspage(request): """ Controller for the app results page. """ #Get fdc data from main.js file through GET function data = request.GET flowlist = data['key1'] print flowlist #format flowlist, and split by , flowlist = flowlist[1:-1] flowlist_list = flowlist.split(",") flow_float = [float(s.encode('ascii')) for s in flowlist_list] flow_format = ['%.2f' % elem for elem in flow_float] #define percentages plist = [99, 95, 90, 85, 75, 70, 60, 50, 40, 30, 20] #zip lists together paired_lists = zip(plist, flow_format) print paired_lists #format for LinePlot plot_data = [[float(s) for s in list] for list in paired_lists] fdc_tbv = TableView(column_names=('Percent (%)', unicode('Flow (m' + u'\u00b3' + '/s)')), rows=paired_lists, hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, False, False), row_ids=[range(0, 10)]) plot_view = LinePlot(height='100%', width='200px', engine='highcharts', title='Flow-Duration Curve', subtitle=' ', spline=True, x_axis_title='Percent', x_axis_units='%', y_axis_title='Flow', y_axis_units='m^3/s', series=[{ 'name': 'Flow', 'color': '#0066ff', 'marker': { 'enabled': False }, 'data': plot_data }]) if request.POST and 'submit' in request.POST: session = SessionMaker() capacityList = [] for row in paired_lists: flow = row.flow pipeMaterial = float(request.POST['materialDropdown']) length = float(request.POST['valueInput0']) diameter = float(request.POST['valueInput1']) elevHead = float(request.POST['valueInput2']) density = 998 kinViscosity = 0.00000112 turbineEfficiency = 0.53 gravity = 9.81 RDRatio = pipeMaterial / diameter XSArea = pi * (diameter / 2.0)**2 aveVelocity = flow / XSArea reynolsN = (aveVelocity * diameter) / kinViscosity flowType = 'Laminar' if reynolsN < 2000 else 'Turbulent' massFR = density * flow frictionFactor = 64 / reynolsN if flowType == 'Laminar' else ( 1 / (-1.8 * log10((RDRatio / 3.7)**1.11 + (6.9 / reynolsN))))**2 smooth90F = 0.3 * float(request.POST['BCountInput0']) smooth90T = 0.9 * float(request.POST['BCountInput1']) miter90 = 1.1 * float(request.POST['BCountInput2']) elbow45T = 0.4 * float(request.POST['BCountInput3']) unionT = 0.08 * float(request.POST['BCountInput4']) reentrant = 0.8 * float(request.POST['ICountInput0']) sharpeEdge = 0.5 * float(request.POST['ICountInput1']) wellRounded = 0.03 * float(request.POST['ICountInput2']) slightlyRounded = 0.12 * float(request.POST['ICountInput3']) reentrantT = 1.05 * float(request.POST['ECountInput0']) sharpeEdgeT = 1.05 * float(request.POST['ECountInput1']) roundedT = 1.05 * float(request.POST['ECountInput2']) degree30 = 0.02 * float(request.POST['GCountInput0']) degree45 = 0.04 * float(request.POST['GCountInput1']) degree60 = 0.07 * float(request.POST['GCountInput2']) totalK = smooth90F + smooth90T + miter90 + elbow45T + unionT + reentrant + sharpeEdge + wellRounded +\ slightlyRounded + reentrantT + sharpeEdgeT + roundedT + degree30 + degree45 + degree60 minorLosses = totalK * (aveVelocity**2 / (2 * gravity)) frictionLoss = (frictionFactor * length * aveVelocity**2) / (diameter * 2 * gravity) totalHeadLoss = minorLosses + frictionLoss turbineHead = elevHead - totalHeadLoss capacity = (turbineHead * density * flow * turbineEfficiency * gravity) / 1000 apacityList.append( (int(row.percent), round(float(flow), 2), round(float(capacity), 2))) sortedCapList = sorted(capacityList, key=lambda x: x[0]) context = {'fdc_tbv': fdc_tbv, 'plot_view': plot_view} return render(request, 'storage_capacity/resultspage.html', context)
def home(request): """ Controller for the app home page. """ session = SessionMaker() pipeRoughness = { 'Riveted Steel': 0.0009, 'Concrete': 0.0003, 'Wood Stave': 0.00018, 'Cast Iron': 0.00026, 'Galvanized Iron': 0.00015, 'Commercial Steel': 0.000045, 'Drawn Turbing': 0.0000015, 'Plastic': 0, 'Glass': 0 } materialSelectInput = [] for v, k in pipeRoughness.iteritems(): materialSelectInput.append((v, float(k))) materialDropdown = SelectInput(display_text='Select Pipe Material', name='materialDropdown', multiple=False, options=materialSelectInput, initial=['Commercial Steel'], original=False) text_input = TextInput(display_text='Enter Water Temperature', name='inputAmount', placeholder='20.00', append=unicode(u'\u00b0' + 'C')) input_tbv = TableView(column_names=('Input', 'Value', 'Units'), rows=[('Length', 739, '[ M ]'), ('Diameter', 1.5, '[ M ]'), ('Elevation Head', 135, '[ M ]')], hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, 'valueInput'), row_ids=[0, 1, 2]) bends_tbv = TableView(column_names=('Bends', 'Count'), rows=[('90 Smooth (Flanged)', 0), ('90 Smooth (Threaded)', 0), ('90 Miter', 0), ('45 Threaded Elbow', 1), ('Threaded Union', 121)], hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, 'BCountInput'), row_ids=[0, 1, 2, 3, 4]) inlets_tbv = TableView(column_names=('Inlets', 'Count'), rows=[('Reentrant', 0), ('Sharp Edge', 1), ('Well-Rounded', 0), ('Slightly-Rounded', 0)], hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, 'ICountInput'), row_ids=[0, 1, 2, 3]) exits_tbv = TableView(column_names=('Exit', 'Count'), rows=[('Reentrant (Turb)', 0), ('Sharp Edge (Turb)', 1), ('Rounded (Turb)', 0)], hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, 'ECountInput'), row_ids=[0, 1, 2]) gradContraction_tbv = TableView(column_names=('Contraction', 'Count'), rows=[('30 Degree', 0), ('45 Degree', 0), ('60 Degree', 0)], hover=True, striped=True, bordered=True, condensed=True, editable_columns=(False, 'GCountInput'), row_ids=[0, 1, 2]) submit_button = Button(display_text='Calculate Capacity', name='submit', attributes='form=parameters-form', submit=True) session.close() context = { 'materialDropdown': materialDropdown, 'text_input': text_input, 'input_tbv': input_tbv, 'bends_tbv': bends_tbv, 'inlets_tbv': inlets_tbv, 'exits_tbv': exits_tbv, 'gradContraction_tbv': gradContraction_tbv, 'submit_button': submit_button } return render(request, 'storage_capacity/home.html', context)