def list_projects(request):
    """
    Show all projects in a table view.
    """
    projects = get_all_projects()
    table_rows = []

    for project in projects:

        table_rows.append(
            (
                project.facility_id, project.category,
                project.project, project.description, project.priority,
                project.est_year, "$"+"{:,}".format(int(project.est_cost)),
                project.const_year, "$"+"{:,}".format(int(project.const_cost[0])),
                project.debt_checkbox_val, project.recur_checkbox_val,
            )
        )

    projects_table = DataTableView(
        column_names=('Facility ID', 'Category', 'Project', 'Description', 'Priority', 'Estimate Year', 'Estimated Cost', 'Construction Year', 'Construction Cost', 'Debt', 'Recurring'),
        rows=table_rows,
        searching=True,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {
        'projects_table': projects_table,
        # 'can_add_projects': has_permission(request, 'add_projects')
    }

    return render(request, 'project_inventory/list_projects.html', context)
def list_revenue(request):
    """
    Show all projects in a table view.
    """
    revenues = get_all_revenue()
    table_rows = []

    for revenue in revenues:

        table_rows.append((
            revenue.scenario,
            revenue.year,
            revenue.revenue_source,
            "$" + "{:,}".format(round(float(revenue.monetary_Value))),
        ))

    revenue_table = DataTableView(
        column_names=('Scenario', 'Year', 'Revenue Source', 'Monetary Value'),
        rows=table_rows,
        searching=True,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {
        'revenue_table': revenue_table,
    }

    return render(request, 'project_inventory/list_revenue.html', context)
Пример #3
0
def Data(request, app_workspace):
    """
    Controller for the background page.
    """
    waters = get_all_water(app_workspace.path)
    table_rows = []

    for water in waters:
        table_rows.append(
            (water['sampleid'], water['river'], water['datecol'],
             water['timecol'], water['note'], water['pH'], water['temper'],
             water['cond'], water['ca'], water['mg'], water['na'], water['k'],
             water['hco'], water['cl'], water['so'], water['sio']))

    water_table = DataTableView(
        column_names=('Sample ID', 'River', 'Date Collected', 'Time Collected',
                      'Notes', 'pH', 'Temperature (C)', 'Conductivity',
                      'Ca2+ (mg/L)', 'Mg2+ (mg/L)', 'Na+ (mg/L)', 'K+ (mg/L)',
                      'HCO3- (mg/L)', 'Cl- (mg/L)', 'SO42- (mg/L)',
                      'SiO2 (mg/L)'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {'water_table': water_table}

    return render(request, 'waimea_flux/Data.html', context)
Пример #4
0
def list_dams(request):
    """
    Show all dams in a table view.
    """
    dams = get_all_dams()
    table_rows = []

    for dam in dams:
        table_rows.append(
            (
                dam.name, dam.owner,
                dam.river, dam.date_built
            )
        )

    dams_table = DataTableView(
        column_names=('Name', 'Owner', 'River', 'Date Built'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[ [10, 25, 50, -1], [10, 25, 50, "All"] ],
    )

    context = {
        'dams_table': dams_table
    }

    return render(request, 'dam_inventory/list_dams.html', context)
Пример #5
0
def list_wells(request):
    """
    Show all wells in a table view.
    """
    wells = get_all_wells()
    table_rows = []

    for well in wells:
        hydrograph_id = get_hydrograph(well.id)
        well_id = well.id
        if hydrograph_id:
            url = reverse('well_inventory:hydrograph',
                          kwargs={'hydrograph_id': hydrograph_id})
            well_hydrograph = format_html(
                '<a class="btn btn-primary" href="{}">Hydrograph Plot</a>'.
                format(url))
        else:
            well_hydrograph = format_html(
                '<a class="btn btn-primary disabled" title="No hydrograph assigned" '
                'style="pointer-events: auto;">Hydrograph Plot</a>')

        if well_id == request.user.id:
            url = reverse('well_inventory:delete_well',
                          kwargs={'well_id': well.id})
            well_delete = format_html(
                '<a class="btn btn-danger" href="{}">Delete Well</a>'.format(
                    url))
        else:
            url = reverse('well_inventory:delete_well',
                          kwargs={'well_id': well.id})
            well_delete = format_html(
                '<a class="btn btn-danger" href="{}">Delete Well</a>'.format(
                    url))

        table_rows.append((well.name, well.owner, well.river, well.date_built,
                           well_hydrograph, well_delete))

    wells_table = DataTableView(
        column_names=('Well Number', 'Owner', 'Aquifer', 'Date Built',
                      'Depth to GW Hydrograph', 'Manage'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {
        'wells_table': wells_table,
        'can_add_wells': has_permission(request, 'add_wells')
    }

    return render(request, 'well_inventory/list_wells.html', context)
Пример #6
0
def list_dams(request):
    """
    Show all dams in a table view.
    """
    dams = get_all_dams()
    table_rows = []

    for dam in dams:
        hydrograph_id = get_hydrograph(dam.id)
        if hydrograph_id:
            url = reverse('dam_inventory:hydrograph',
                          kwargs={'hydrograph_id': hydrograph_id})
            dam_hydrograph = format_html(
                '<a class="btn btn-primary" href="{}">Hydrograph Plot</a>'.
                format(url))
        else:
            dam_hydrograph = format_html(
                '<a class="btn btn-primary disabled" title="No hydrograph assigned" '
                'style="pointer-events: auto;">Hydrograph Plot</a>')

        if dam.user_id == request.user.id:
            url = reverse('dam_inventory:delete_dam',
                          kwargs={'dam_id': dam.id})
            dam_delete = format_html(
                '<a class="btn btn-danger" href="{}">Delete Dam</a>'.format(
                    url))
        else:
            dam_delete = format_html(
                '<a class="btn btn-danger disabled" title="You are not the creator of the dam" '
                'style="pointer-events: auto;">Delete Dam</a>')

        table_rows.append((dam.name, dam.owner, dam.river, dam.date_built,
                           dam_hydrograph, dam_delete))

    dams_table = DataTableView(
        column_names=('Name', 'Owner', 'River', 'Date Built', 'Hydrograph',
                      'Manage'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {
        'dams_table': dams_table,
        'can_add_dams': has_permission(request, 'add_dams')
    }

    return render(request, 'dam_inventory/list_dams.html', context)
Пример #7
0
def list_places(request, app_workspace):
    """
    Show all places in a table view.
    """
    places = get_all_places(app_workspace.path)
    table_rows = []

    for place in places:
        table_rows.append((place['name'], place['type'], place['description']))

    places_table = DataTableView(
        column_names=('Name', 'Type', 'Description'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {'places_table': places_table}

    return render(request, 'vacationeer/list_places.html', context)
def list_sensors(request):
    """
    Show all Sensors in a table
    """
    sensors = get_all_sensors()
    table_rows = []

    if sensors is not None:
        for sensor in sensors:
            table_rows.append((sensor.id, sensor.longitude, sensor.latitude))

    sensor_table = DataTableView(column_names=('id', 'latitude', 'longitude'),
                                 rows=table_rows,
                                 searching=False,
                                 orderClasses=False,
                                 lengthMenu=[[10, 25, 50, -1],
                                             [10, 25, 50, "All"]])

    context = {'sensor_table': sensor_table}

    return render(request, 'open_air/list_sensors.html', context)
Пример #9
0
def results(request):

    back_button = Button(
        display_text='Atras',
        name='back-button',
        href=reverse('dr_water_allocation:home'),
    )
    diversion_points_list = get_all_diversions()
    points_in_table = []
    for item in diversion_points_list:
        if item.priority == 1:
            priority = 'High'
        elif item.priority == 2:
            priority = 'Medium'
        else:
            priority = 'Low'

        if item.water_diverted > 0:
            percent_demand = int((item.demand / item.water_diverted) * 100)
        else:
            percent_demand = 0

        table_entry = (item.name, item.demand, priority, item.efficiency,
                       item.water_diverted, percent_demand)
        points_in_table.append(table_entry)

    datatable_results = DataTableView(
        column_names=('Nombre', 'Demanda', 'Prioridad', 'Eficiencia',
                      'Agua Recibida', 'Por Ciento'),
        rows=points_in_table,
        searching=False,
        orderClasses=False,
    )

    context = {
        'back_button': back_button,
        'datatable_results': datatable_results,
    }
    return render(request, 'dr_water_allocation/results.html', context)
Пример #10
0
def list_blooms(request, app_workspace):
    """
    Show all blooms in a table view.
    """
    blooms = get_all_blooms(app_workspace.path)
    table_rows = []

    for blooms in blooms:
        table_rows.append((blooms['location'], blooms['type'],
                           blooms['severity'], blooms['date']))

    blooms_table = DataTableView(
        column_names=('Location', 'Type', 'Severity', 'Date of Appearance'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {'blooms_table': blooms_table}

    return render(request, 'utah_algal_blooms/list_blooms.html', context)
def list_sites(request, app_workspace):
    """
    Show all sites in a table view.
    """
    sites = get_all_sites(app_workspace.path)
    table_rows = []

    for site in sites:
        table_rows.append((site['country'], site['city'], site['lat'],
                           site['long'], site['date_eq']))

    sites_table = DataTableView(
        column_names=('Country', 'City', 'Lattitude', 'Longitude',
                      'Date of Earthquake'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    context = {'sites_table': sites_table}

    return render(request, 'liq_inventory/list_sites.html', context)
Пример #12
0
def visualize_events(request,event_id,sub_event):
    event_id = int(event_id)
    sub_event = int(sub_event)
    event_number = sub_event+1
    
    if event_number < 1:
        event_number = 1
    metrics = retrieve_metrics(int(event_id),int(sub_event))
    #update metrics 
    
    if len(metrics)<1:
        try: 
            
            success = update_segmentation(int(event_id))
            metrics = retrieve_metrics(int(event_id),int(sub_event))
        except Exception as e:
            # Careful not to hide error. At the very least log it to the console
            print(e)
            
            return False
    
    
    if metrics[0]['Event Duration (hours)'] == '-1':
        try: 
            
            success = update_segmentation(int(event_id))
            metrics = retrieve_metrics(int(event_id),int(sub_event))
        except Exception as e:
            # Careful not to hide error. At the very least log it to the console
            print(e)
            
            return False
        
     
    
    
    
    time,flow,concentration,segments=get_conc_flow_seg(event_id)
    start_seg = 0
    end_seg = len(segments)-1
    
    if int(sub_event) > int(end_seg):
        sub_event = int(sub_event) - 1 
        event_number = sub_event + 1
        messages.info(request, 'Event '+str(end_seg+1)+' is the last event.')
     
    if int(sub_event) < 0:
        sub_event = int(sub_event) + 1 
        event_number = sub_event + 1
        messages.info(request, 'Event 1 is the first event.')   
        
        
    if request.POST and 'download-button' in request.POST:
        # Get Values
        has_errors = False
        

        if not has_errors:
            # create and write file here
            #print('no errors')
            
            success = 1
            # Provide feedback to user
            if success:
                
               
                
                fileDir = os.path.dirname(__file__)
                fname = fileDir+'/public/files/'+str(event_id)+'_file_metrics_temp.csv'
                fout = open(fname, 'w')
                fieldnames = metrics[0].keys()
                csvw = csv.DictWriter(fout, fieldnames = fieldnames)
                csvw.writeheader()
                csvw.writerows(metrics)
                fout.close()
                
                
                #remove old files
                if int(event_id) > 40:
                    fname2 = 'tethysdev/tethysapp-heda/tethysapp/heda/public/files/'+str(int(event_id)-30)+'_file_metrics_temp.csv'
                    if os.path.exists(fname2):
                        os.remove(fname2)
        
            
            
                filename = fname    
                fname = 'HEDA_download'
                content = FileWrapper(open(filename))
                response = HttpResponse(content, content_type='text/csv')
                response['Content-Disposition'] = 'attachment; filename=%s' % fname
                
                
                return response
                
                   
            else:
                messages.info(request, 'Unable to download data file.')
            
            return redirect(reverse('heda:add_data', kwargs={"event_id": event_id}))

        messages.error(request, "Unknown problem.")
        
    
    
    download_button = Button(
        display_text='Download metrics',
        name='download-button',
        submit=True,
        icon='glyphicon glyphicon-download',
        style='success',
        attributes={'form': 'slider-data-form'},
        
        
    )
    
    
    
    
    cancel_button = Button(
        display_text='Cancel',
        name='cancel-button',
        href=reverse('heda:home')
    )
    
    previous_button = Button(
        display_text='Previous',
        name='previous-button',
        icon='glyphicon glyphicon-step-backward',
        href=reverse('heda:visualize_events', kwargs={"event_id": event_id,"sub_event": str(int(sub_event)-1)}),
        style='success',
    )
        
    
    
    next_button = Button(
    display_text='Next',
        name='next-button',
        icon='glyphicon glyphicon-step-forward',
        href=reverse('heda:visualize_events', kwargs={"event_id": event_id,"sub_event": str(int(sub_event)+1)}),
        style='success',
    )
    
    cqt_cq_plot = cqt_cq_event_plot(int(event_id),int(sub_event))
    
    table_rows = []
    
    metrics_dict = OrderedDict()
    if len(metrics)>0:
        metrics_dict = metrics[int(sub_event)]
        
        for k in metrics_dict.keys():
            table_rows.append((k,metrics_dict[k]))
        
    
    
    
    
    if request.POST and 'event-number' in request.POST:
        sub_event = request.POST.get('event-number', None)
        sub_event = int(sub_event) - 1
        sub_event = str(sub_event)
        return redirect(reverse('heda:visualize_events', kwargs={"event_id": event_id,"sub_event": sub_event}))
            
    metric_table = DataTableView(
        column_names=('Name', 'Value'),
        rows=table_rows,
        searching=False,
        orderClasses=False,
        lengthMenu=[ [10, 25, 50, -1], [10, 25, 50, "All"] ],
        DisplayLength = -1,
        ordering = False,
    )
    
    
    
    event_number_slider = RangeSlider(display_text='',
                      name='event-number',
                      min=start_seg+1,
                      max=end_seg+1,
                      initial=event_number,
                      step=1,
                      attributes={'form': 'slider-data-form'},
                      )
                      
                      
    jump_button = Button(
        display_text='Jump using slider',
        name='jump-button',
        icon='',
        style='success',
        attributes={'form': 'slider-data-form'},
        #href=reverse('heda:add_data', kwargs={"event_id": event_id}),
        #disabled=segment_button_disable,
        submit=True
    )

    
    context = {

        'cq_plot':cqt_cq_plot, 
        'cancel_button': cancel_button,
        'previous_button': previous_button,
        'download_button':download_button,
        'next_button':next_button,
        'metric_table':metric_table,
        'event_number_slider':event_number_slider,
        'sub_event': sub_event,
        'jump_button':jump_button,
        'event_number':event_number,

    }
    
    
    return render(request, 'heda/visualize_events.html', context)
Пример #13
0
def home(request):
    """
    Controller for the app home page.
    """

    datatable_default = DataTableView(
        column_names=('Name', 'Age', 'Job'),
        rows=[('Bill', 30, 'contractor'), ('Fred', 18, 'programmer'),
              ('Bob', 26, 'boss')],
        searching=False,
        orderClasses=False,
        lengthMenu=[[10, 25, 50, -1], [10, 25, 50, "All"]],
    )

    save_button = Button(display_text='',
                         name='save-button',
                         icon='glyphicon glyphicon-floppy-disk',
                         style='success',
                         attributes={
                             'data-toggle': 'tooltip',
                             'data-placement': 'top',
                             'title': 'Save'
                         })

    edit_button = Button(display_text='',
                         name='edit-button',
                         icon='glyphicon glyphicon-edit',
                         style='warning',
                         attributes={
                             'data-toggle': 'tooltip',
                             'data-placement': 'top',
                             'title': 'Edit'
                         })

    remove_button = Button(display_text='',
                           name='remove-button',
                           icon='glyphicon glyphicon-remove',
                           style='danger',
                           attributes={
                               'data-toggle': 'tooltip',
                               'data-placement': 'top',
                               'title': 'Remove'
                           })

    previous_button = Button(display_text='Previous',
                             name='previous-button',
                             attributes={
                                 'data-toggle': 'tooltip',
                                 'data-placement': 'top',
                                 'title': 'Previous'
                             })

    next_button = Button(display_text='Next',
                         name='next-button',
                         attributes={
                             'data-toggle': 'tooltip',
                             'data-placement': 'top',
                             'title': 'Next'
                         })

    context = {
        'save_button': save_button,
        'edit_button': edit_button,
        'remove_button': remove_button,
        'previous_button': previous_button,
        'next_button': next_button,
        'datatable_view': datatable_default
    }

    return render(request, 'catalogo_de_sequia_rd/home.html', context)