<commit_before>class CarbonQuery
  def self.total(the_geom, table_name)

      <<-SQL
      SELECT SUM(carbon) as carbon FROM
        (SELECT ST_AREA(ST_Transform(ST_SetSRID(ST_INTERSECTION(b.the_geom, a.the_geom), 4326),27040))/10000*c_mg_ha as carbon 
        FROM #{table_name} a 
        INNER JOIN 
          (SELECT #{the_geom} as the_geom) b 
        ON ST_Intersects(a.the_geom, b.the_geom)) c;
      SQL
  end

  def self.habitat(the_geom, table_name)

      <<-SQL
      SELECT habitat, SUM(carbon) as carbon FROM
        (SELECT ST_AREA(ST_Transform(ST_SetSRID(ST_INTERSECTION(b.the_geom, a.the_geom), 4326),27040))/10000*c_mg_ha as carbon, habitat 
        FROM #{table_name} a 
        INNER JOIN 
          (SELECT #{the_geom} as the_geom) b 
        ON ST_Intersects(a.the_geom, b.the_geom)) c
        GROUP BY habitat;
      SQL
  end

  def self.global_percent_area(the_geom, table_name)

    <<-SQL
    
    SELECT a.habitat, a.area/SUM(ST_Area(
      ST_Transform(ST_SetSRID(b.the_geom, 4326), 27040)))*100 as percentage 
      FROM 
        (SELECT SUM (area) as area, habitat FROM 
        (SELECT ST_AREA(ST_Transform(ST_SetSRID(ST_INTERSECTION(b.the_geom, a.the_geom), 4326),27040)) as area, habitat 
        FROM (
          SELECT the_geom, habitat FROM bc_mangrove
          UNION ALL
          SELECT the_geom, habitat FROM bc_seagrass WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_saltmarsh WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_algal_mat WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_other WHERE action <> 'delete' AND toggle = true
          )
          a 
          INNER JOIN 
          (SELECT #{the_geom}) b 
          ON ST_Intersects(a.the_geom, b.the_geom)) a
          GROUP BY habitat) a INNER JOIN (
          SELECT the_geom, habitat FROM bc_mangrove
          UNION ALL
          SELECT the_geom, habitat FROM bc_seagrass WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_saltmarsh WHERE action <> 'delete' AND toggle = true<commit_msg>Added the_geom to the query column<commit_after>class CarbonQuery
  def self.total(the_geom, table_name)

      <<-SQL
      SELECT SUM(carbon) as carbon FROM
        (SELECT ST_AREA(ST_Transform(ST_SetSRID(ST_INTERSECTION(b.the_geom, a.the_geom), 4326),27040))/10000*c_mg_ha as carbon 
        FROM #{table_name} a 
        INNER JOIN 
          (SELECT #{the_geom} as the_geom) b 
        ON ST_Intersects(a.the_geom, b.the_geom)) c;
      SQL
  end

  def self.habitat(the_geom, table_name)

      <<-SQL
      SELECT habitat, SUM(carbon) as carbon FROM
        (SELECT ST_AREA(ST_Transform(ST_SetSRID(ST_INTERSECTION(b.the_geom, a.the_geom), 4326),27040))/10000*c_mg_ha as carbon, habitat 
        FROM #{table_name} a 
        INNER JOIN 
          (SELECT #{the_geom} as the_geom) b 
        ON ST_Intersects(a.the_geom, b.the_geom)) c
        GROUP BY habitat;
      SQL
  end

  def self.global_percent_area(the_geom, table_name)

    <<-SQL
    
    SELECT a.habitat, a.area/SUM(ST_Area(
      ST_Transform(ST_SetSRID(b.the_geom, 4326), 27040)))*100 as percentage 
      FROM 
        (SELECT SUM (area) as area, habitat FROM 
        (SELECT ST_AREA(ST_Transform(ST_SetSRID(ST_INTERSECTION(b.the_geom, a.the_geom), 4326),27040)) as area, habitat 
        FROM (
          SELECT the_geom, habitat FROM bc_mangrove
          UNION ALL
          SELECT the_geom, habitat FROM bc_seagrass WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_saltmarsh WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_algal_mat WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_other WHERE action <> 'delete' AND toggle = true
          )
          a 
          INNER JOIN 
          (SELECT #{the_geom} as the_geom) b 
          ON ST_Intersects(a.the_geom, b.the_geom)) a
          GROUP BY habitat) a INNER JOIN (
          SELECT the_geom, habitat FROM bc_mangrove
          UNION ALL
          SELECT the_geom, habitat FROM bc_seagrass WHERE action <> 'delete' AND toggle = true
          UNION ALL
          SELECT the_geom, habitat FROM bc_saltmarsh WHERE action <> 'delete' AND toggle = true
{'fraction_non_alphanumeric': 0.0804109895018986, 'fraction_numerical': 0.021889658253294617, 'mean_word_length': 2.4446153846153846, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '765880', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1456, 'n_words': 408}