BathHacked/energy-sparks

View on GitHub
app/views/schools/solar_edge_installations/show.html.erb

Summary

Maintainability
Test Coverage
<div class="d-flex justify-content-between align-items-center">
  <h1>SolarEdge Site <%= @solar_edge_installation.site_id %></h1>
  <div class="h5">
    <%= link_to "All Solar API feeds",  school_solar_feeds_configuration_index_path(@school), class: 'btn btn-outline-dark round-pill' %>
  </div>
</div>

<% if @solar_edge_installation.cached_api_information? %>
  <h2>Cached site information</h2>

  <p>
  The following is a summary of the site description. It was last refreshed on <%= nice_date_times(@solar_edge_installation.updated_at) %>. Edit and then save the site to update this cached copy. Or click the links below to view live (raw) data.
  </p>

  <table class="table">
    <thead>
      <tr>
        <th>Field</th>
        <th>Value</th>
      </tr>
    </thead>
    <tbody>
      <% @solar_edge_installation.information.each do |key, value| %>
        <tr>
          <th><%= key %></th>
          <td><%= value %></td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% else %>
  <p>There is no cached copy of the site metadata</p>
<% end %>

<h2>Developer Debug links</h2>

<p>
  The following URLs provide direct access to some of the data from the Solar Edge API. We only currently load the metered data. The other links are useful for debugging and helping with setup.
</p>

<ul>
 <li><%= link_to 'Site Details', "#{SolarEdgeAPI::BASE_URL}/sites/list?#{@api_params.to_query}" %> - live version of the above <code>site_details</code> data. Summarises all sites for which this API key has access</li>
 <li><%= link_to 'Data Period', "#{SolarEdgeAPI::BASE_URL}/site/#{@solar_edge_installation.site_id}/dataPeriod?#{@api_params.to_query}" %> - live version of the above <code>dates</code>. Returns the dates of earliest and latest readings</li>
 <li><%= link_to 'Site Overview', "#{SolarEdgeAPI::BASE_URL}/site/#{@solar_edge_installation.site_id}/overview?#{@api_params.to_query}" %> - The current power and daily, monthly, yearly and life time energy production for this specific site id</li>
 <li><%= link_to 'Components List', "#{SolarEdgeAPI::BASE_URL}/equipment/#{@solar_edge_installation.site_id}/list?#{@api_params.to_query}" %> - return a list of the inverters/SMIs for this site</li>

 <li><%= link_to 'Inventory', "#{SolarEdgeAPI::BASE_URL}/site/#{@solar_edge_installation.site_id}/inventory?#{@api_params.to_query}" %> - return the inventory of SolarEdge equipment for this site id, including inverters/SMIs, batteries, meters, gateways and sensors. Indicates whether meters are real or virtual (calculated from other meters)</li>

 <% if @reading_params.present? %>
   <li><%= link_to 'Readings', "#{SolarEdgeAPI::BASE_URL}/site/#{@solar_edge_installation.site_id}/energyDetails?#{@reading_params.to_query}" %> - return the readings for the latest date (based on cached date)</li>
   <li><%= link_to 'Meter data', "#{SolarEdgeAPI::BASE_URL}/site/#{@solar_edge_installation.site_id}/meters?#{@reading_params.merge({timeUnit: 'DAY'}).to_query}" %> - lifetime energy reading for each meter and the device its connected to</li>
 <% end %>

 <li><%= link_to 'Environmental Benefits', "#{SolarEdgeAPI::BASE_URL}/site/#{@solar_edge_installation.site_id}/envBenefits?#{@api_params.to_query}" %> - returns all environmental benefits for this site id, e.g. CO2 emissions saved, equivalent trees planted, and light bulbs powered for a day.</li>
 <li><%= link_to 'Current Power Flow', "#{SolarEdgeAPI::BASE_URL}/site/#{@solar_edge_installation.site_id}/currentPowerFlow?#{@api_params.to_query}" %> - retrieves the current power flow between all elements of the site including PV array, storage (battery), loads (consumption) and grid.</li>
</ul>

<p><%= link_to 'Delete', school_solar_edge_installation_path(@school, @solar_edge_installation), method: :delete, data: { confirm: 'Are you sure? This will delete the meters' }, class: 'btn' %>