Commit c949ca7b authored by Andrzej Obracaj's avatar Andrzej Obracaj
Browse files

left join

parent 9138606e
......@@ -7,11 +7,10 @@ class AssessmentRegimesHandler:
sql="""
SELECT ar.id, ar.name, ar.zoneid, z.name as zone_name, ar.pollutant, po.label as pollutant_name, ar.objecttype, ar.reportingmetric, ar.protectiontarget,
ar.assessmentthresholdexceedance, ar.include, ar.thresholdclassificationyear, ar.thresholdclassificationreport
FROM assessmentregimes ar,
zones z,
eea_pollutants po
WHERE ar.zoneid = z.id
and ar.pollutant = po.uri
FROM assessmentregimes ar
LEFT OUTER JOIN eea_pollutants po ON ar.pollutant = po.uri,
zones z
WHERE ar.zoneid = z.id
"""
ar = Db.fetchall(sql)
......
......@@ -22,7 +22,7 @@ class ExceedanceDescriptionsHandler:
ed.other_exceedance_reason
FROM
(
SELECT ed.id,
SELECT ed.id,
at.id as attainment_id,
ed.exceedances,
et.id::INTEGER as excedance_type,
......@@ -39,14 +39,11 @@ class ExceedanceDescriptionsHandler:
ed.exceedance_reason,
ed.other_exceedance_reason
FROM
exceedancedescriptions ed,
eea_exceedancetype et,
attainments at,
eea_exceedancedescription ee
WHERE 1=1
AND ed.excedance_type = et.id
AND ed.attainment_id = at.id
AND ed.exceedancedescription_element = ee.id
exceedancedescriptions ed
LEFT OUTER JOIN eea_exceedancetype et ON ed.excedance_type = et.id
LEFT OUTER JOIN eea_exceedancedescription ee ON ed.exceedancedescription_element = ee.id,
attainments at
WHERE ed.attainment_id = at.id
) as ed
LEFT OUTER JOIN (SELECT id,label from eea_adjustmenttypes) as at ON at.id = ed.adjustment_type
......
......@@ -6,12 +6,14 @@ class NetworksHandler:
@staticmethod
def handle():
sql = """
select n.*, r.name as responsible_authority_name, tz.label as aggregation_timezone_name, ol.label as organisational_name, mv.label as media_monitored_name
from networks n, responsible_authorities r, eea_timezones tz, eea_organisationallevels ol, eea_mediavalues mv
where n.responsible_authority_id = r.id
and lower(n.aggregation_timezone) = lower(tz.id)
and lower(n.media_monitored) = lower(mv.id)
and lower(n.organisational) = lower(ol.id)
SELECT n.*, r.name as responsible_authority_name, tz.label as aggregation_timezone_name, ol.label as organisational_name, mv.label as media_monitored_name
FROM
networks n
LEFT OUTER JOIN eea_timezones tz ON lower(n.aggregation_timezone) = lower(tz.id)
LEFT OUTER JOIN eea_organisationallevels ol ON lower(n.organisational) = lower(ol.id)
LEFT OUTER JOIN eea_mediavalues mv ON lower(n.media_monitored) = lower(mv.id),
responsible_authorities r
WHERE n.responsible_authority_id = r.id
"""
sql = sql + Db.add_network_ids_requirement()
......
......@@ -6,9 +6,9 @@ class ObservationsHandler:
def handle():
sql = """
SELECT id, sampling_point_id, begin_position,
end_position, value::DOUBLE PRECISION,
verification_flag, validation_flag,
touched, from_time, to_time
end_position, value::DOUBLE PRECISION,
verification_flag, validation_flag,
touched, from_time, to_time
FROM observations
limit 1000
"""
......
......@@ -6,27 +6,20 @@ class ObservingCapabilitiesHandler:
def handle():
sql = """
SELECT oc.*,
ptv.label as process_type_name,
rnv.label as result_nature_name,
po.label as pollutant_name,
c.label as concentration_name,
t.label as timestep_name
ptv.label as process_type_name,
rnv.label as result_nature_name,
po.label as pollutant_name,
c.label as concentration_name,
t.label as timestep_name
FROM observing_capabilities oc
left join sampling_points sp on oc.sampling_point_id = sp."id"
left join stations s on sp.station_id = s."id"
left join networks n on s.network_id = n."id",
eea_processtypevalues ptv,
eea_resultnaturevalues rnv,
eea_pollutants po,
eea_concentrations c,
eea_times t
WHERE lower(oc.process_type) = lower(ptv.id)
and lower(oc.result_nature) = lower(rnv.id)
and lower(oc.pollutant) = lower(po.uri)
and lower(oc.concentration) = lower(c.id)
and lower(oc.timestep) = lower(t.id)
left join sampling_points sp on oc.sampling_point_id = sp.id
left join stations s on sp.station_id = s.id
left join networks n on s.network_id = n.id
left join eea_processtypevalues ptv on lower(oc.process_type) = lower(ptv.id)
left join eea_resultnaturevalues rnv on lower(oc.result_nature) = lower(rnv.id)
left join eea_pollutants po on lower(oc.pollutant) = lower(po.uri)
left join eea_concentrations c on lower(oc.concentration) = lower(c.id)
left join eea_times t on lower(oc.timestep) = lower(t.id)
"""
sql = sql + Db.add_network_ids_requirement()
......
......@@ -6,53 +6,51 @@ class ProcessesHandler:
@staticmethod
def handle():
sql = """
SELECT
pr.id,
pr.measurement_type,
pr.measurement_method,
pr.other_measurement_method,
pr.sampling_method,
pr.other_sampling_method,
pr.analytical_tech,
pr.other_analytical_tech,
pr.sampling_equipment,
pr.measurement_equipment,
pr.equiv_demonstration,
pr.equiv_demonstration_report,
pr.detection_limit::DOUBLE PRECISION,
pr.detection_limit_uom,
pr.uncertainty_estimate,
pr.documentation,
pr.qa_report,
pr.duration_number,
pr.duration_unit,
pr.cadence_number,
pr.cadence_unit,
pr.responsible_authority_id,
pr.other_measurement_equipment,
pr.other_sampling_equipment,
mt.label as measurement_type_name,
mm.label as measurement_method_name,
me.label as measurement_equipment_name,
tm.label as duration_unit_name,
tm.label as cadence_unit_name,
ra.name as responsible_authority
FROM
processes pr,
eea_measurementtypes mt,
eea_measurementmethods mm,
eea_measurementequipments me,
eea_times tm,
responsible_authorities ra
WHERE
lower(pr.measurement_type) = lower(mt.id)
and lower(pr.measurement_method) = lower(mm.id)
and lower(pr.measurement_equipment) = lower(me.id)
and lower(pr.duration_unit) = lower(tm.id)
and lower(pr.cadence_unit) = lower(tm.id)
and lower(pr.responsible_authority_id) = lower(ra.id);
SELECT
pr.id,
pr.measurement_type,
pr.measurement_method,
pr.other_measurement_method,
pr.sampling_method,
pr.other_sampling_method,
pr.analytical_tech,
pr.other_analytical_tech,
pr.sampling_equipment,
pr.measurement_equipment,
pr.equiv_demonstration,
pr.equiv_demonstration_report,
pr.detection_limit::DOUBLE PRECISION,
pr.detection_limit_uom,
pr.uncertainty_estimate::DOUBLE PRECISION,
pr.documentation,
pr.qa_report,
pr.duration_number,
pr.duration_unit,
pr.cadence_number,
pr.cadence_unit,
pr.responsible_authority_id,
pr.other_measurement_equipment,
pr.other_sampling_equipment,
mt.label as measurement_type_name,
mm.label as measurement_method_name,
me.label as measurement_equipment_name,
tm.label as duration_unit_name,
tm.label as cadence_unit_name,
ra.name as responsible_authority,
ed.label as equiv_demonstration_name,
ct.notation as detection_limit_uom_name
FROM
processes pr
LEFT OUTER JOIN eea_measurementtypes mt ON lower(pr.measurement_type) = lower(mt.id)
LEFT OUTER JOIN eea_measurementmethods mm ON lower(pr.measurement_method) = lower(mm.id)
LEFT OUTER JOIN eea_measurementequipments me ON lower(pr.measurement_equipment) = lower(me.id)
LEFT OUTER JOIN eea_equivalencedemonstrated ed ON lower(pr.equiv_demonstration) = lower(ed.id)
LEFT OUTER JOIN responsible_authorities ra ON lower(pr.responsible_authority_id) = lower(ra.id)
LEFT OUTER JOIN eea_concentrations ct ON lower(pr.detection_limit_uom) = lower(ct.id),
eea_times tm
WHERE
lower(pr.duration_unit) = lower(tm.id)
and lower(pr.cadence_unit) = lower(tm.id);
"""
processes = Db.fetchall(sql)
......
......@@ -7,14 +7,16 @@ class SamplingPointsHandler:
@staticmethod
def handle():
sql = """
SELECT sp.*, mv.label as media_monitored_name, st.name as station, mr.label as measurement_regime_name, ast.label as assessment_type_name, sc.label as station_callsification_name
FROM sampling_points sp, networks n, eea_mediavalues mv, stations st, eea_measurementregimevalues mr, eea_assessmenttypes ast, eea_stationclassifications sc
WHERE lower(sp.media_monitored) = lower(mv.id)
and sp.station_id = st.id
and lower(sp.measurement_regime) = lower(mr.id)
and lower(sp.assessment_type) = lower(ast.id)
and lower(sp.station_classification) = lower(sc.id)
and st.network_id = n."id"
SELECT sp.*, mv.label as media_monitored_name, st.name as station, mr.label as measurement_regime_name, ast.label as assessment_type_name,
sc.label as station_callsification_name
FROM sampling_points sp
LEFT OUTER JOIN eea_mediavalues mv ON lower(sp.media_monitored) = lower(mv.id)
LEFT OUTER JOIN eea_measurementregimevalues mr ON lower(sp.measurement_regime) = lower(mr.id)
LEFT OUTER JOIN eea_assessmenttypes ast ON lower(sp.assessment_type) = lower(ast.id)
LEFT OUTER JOIN eea_stationclassifications sc ON lower(sp.station_classification) = lower(sc.id),
networks n, stations st
WHERE sp.station_id = st.id
and st.network_id = n.id
"""
sql = sql + Db.add_network_ids_requirement()
......
......@@ -12,11 +12,12 @@ class StationsHandler:
st.mobile, st.measurement_regime, st.area_classification, st.distance_junction, st.traffic_volume, st.heavy_duty_fraction::DOUBLE PRECISION,
st.height_facades, st.municipality, st.street_width, st.eoi_code, ST_X(st.geom) longitude,ST_Y(st.geom) latitude, ST_Z(st.geom) altitude, ST_SRID(st.geom) epsg,
n.name as network, mv.label as media_monitored_name, mr.label as measurement_regime_name, ac.label as area_classification_name
FROM stations st, networks n, eea_mediavalues mv, eea_measurementregimevalues mr, eea_areaclassifications ac
FROM stations st
LEFT OUTER JOIN eea_mediavalues mv ON lower(st.media_monitored) = lower(mv.id)
LEFT OUTER JOIN eea_measurementregimevalues mr ON lower(st.measurement_regime) = lower(mr.id)
LEFT OUTER JOIN eea_areaclassifications ac ON lower(st.area_classification) = lower(ac.id),
networks n
WHERE st.network_id = n.id
and lower(st.media_monitored) = lower(mv.id)
and lower(st.measurement_regime) = lower(mr.id)
and lower(st.area_classification) = lower(ac.id)
"""
sql = sql + Db.add_network_ids_requirement()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment