SpeciesFileGroup/taxonworks

View on GitHub
app/views/tasks/collecting_events/spatial_summary/index.html.erb

Summary

Maintainability
Test Coverage
<%= content_for :head do -%>
  <%= javascript_include_tag "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.1/chart.min.js" %>
<% end %>

<h1> Collecting Events Spatial Summary </h1>

Total: <%= t = @collecting_events.all.count %> <%= link_to('re-filter', filter_collecting_events_task_path( @collecting_events.params), method: :post) %>
<br>

<% if t < 100000 %>

  <div class="flexbox flex-wrap-row gap-medium" >

    <div class="panel content item">
      <h2> Assigned Geographic Areas </h2>

      <table>
        <tr> <th> Name </th> <th> total </th> <th> filter subset </th> </tr>

        <% GeographicArea.where(id: @collecting_events.all.select('distinct(geographic_area_id)').pluck(:geographic_area_id).uniq).order(:name).each do |ga| %>
          <tr>
            <td> <%= link_to(ga.name, geographic_area_path(ga)) %> </td>
            <td> <%= @collecting_events.all.where(geographic_area_id: ga.id).count %> </td>
            <td> <%= link_to('filter', filter_collecting_events_task_path( @collecting_events.params.merge(geographic_area_id: [ga.id])), method: :post) %>
          </tr>
        <% end %>

        <tr>
          <td> Without geographic area assigned </td>
          <td> <%= @collecting_events.all.where(geographic_area_id: nil).count %> </td>
          <td> <%= link_to('filter', filter_collecting_events_task_path( @collecting_events.params.merge(geographic_area: false)), method: :post) %>
        </tr>
      </table>

    </div>

    <div class="panel content item">
      <h2> Cached level/adm assignments </h2>

      <% %w{0 1 2}.each do |l| %>
        <% a = "cached_level#{l}_geographic_name".to_sym %>

        <h3> adm/level <%= l %> </h2>

        <table>
          <tr> <th> name </th> <th> total </th> <th> filter subset </th> </tr>
          <% @collecting_events.all.pluck(a).uniq.sort{|d,e| (d || '') <=> (e || '')}.each do |n| %>
            <tr>
              <td> <%= n %> </td>
              <td> <%= @collecting_events.all.where(a => n).count %> </td>

              <% if n.blank? %>
                <td> <%= link_to('filter', filter_collecting_events_task_path( @collecting_events.params.merge(no_value_attribute: a )), method: :post) %>
              <% else %>
                <td> <%= link_to('filter', filter_collecting_events_task_path( @collecting_events.params.merge(a => n)), method: :post) %>
              <% end %>
            </tr>

          <% end %>

        </table>
      <% end %>
    </div>

    <div class="panel content item">
      <h2> Georeferences </h2>

      <% wg = Queries::CollectingEvent::Filter.new( @collecting_events.params.merge(georeferences: false)) %>
      Without: <%= wgc =  wg.all.count %> <%= link_to('filter without', filter_collecting_events_task_path( wg.params ), method: :post) if wgc > 0 %>

    <h3> Scatterplot (lat/long or centroid) </h3>
    <% d = collecting_event_georeference_points(@collecting_events.all) %>
    <%= scatter_chart d, ytitle: 'Latitude', xtitle: 'Longitude' %>

    </div>
  </div>

<% else %>
  <span>More than 100,000 records returned, please try a smaller set.</span>
<% end %>