---
  name: sqmlocation
  decscription: For each location min, mean, max for each date
  in_parameters:
    - year
      type: integer
    - month
      type: integer

  out_parameters:
    - location
      type: string
    - lat
      type: string
    - long
      type: string
    - mmin
      type: float
    - mmean 
      type: float
    - mmax
      type: float
  
  dataservice:
    type: service
    name: RunPostgresQuery
    sql: "SELECT l.name as location, l.latitude as lat, l.longitude as long, min(value) as mmin, avg(value) as mmean, max(value) as mmax from (
SELECT location, mdate, mpsas_1 as value from clearsky.mobilesqmreading
union all
SELECT location, mdate, mpsas_2 as value from clearsky.mobilesqmreading
union all
SELECT location, mdate, mpsas_3 as value from clearsky.mobilesqmreading
union all
SELECT location, mdate, mpsas_4 as value from clearsky.mobilesqmreading
union all
SELECT location, mdate, mpsas_5 as value from clearsky.mobilesqmreading) s right outer join
clearsky.location l on s.location = l.lid
where date_part('year', s.mdate) = ? and date_part('month', s.mdate) = ?
group by l.name, l.latitude, l.longitude"

  renderservice:
    type: embedded
    html: "<div id="map" style="width: 800px; height: 600px"></div>
    <script>
      var map = L.map('map').setView([51.411, -1.69], 10);

      L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
          maxZoom: 19,
        attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
        }).addTo(map);

      {points}
    </script>"

