 --
 
 COMMENT ON VIEW dz_monthly_energy_summary_for_nonpv_service_points IS 'Monthly energy summary for Non-PV service points. @author Daniel Zhang (張道博)';
+
+
+--
+-- Name: dz_pv_interval_ids; Type: VIEW; Schema: public; Owner: postgres
+--
+
+CREATE VIEW dz_pv_interval_ids AS
+    SELECT readings_unfiltered.interval_id, readings_unfiltered.value, readings_unfiltered.channel, readings_unfiltered.end_time, readings_unfiltered.meter_name FROM (nonpv_mlh JOIN readings_unfiltered ON (((nonpv_mlh.meter_name)::bpchar = readings_unfiltered.meter_name))) WHERE ((readings_unfiltered.channel = 2::smallint) AND (readings_unfiltered.value > 0::real));
+
+
+ALTER TABLE public.dz_pv_interval_ids OWNER TO postgres;
+
+--
+-- Name: VIEW dz_pv_interval_ids; Type: COMMENT; Schema: public; Owner: postgres
+--
+
+COMMENT ON VIEW dz_pv_interval_ids IS 'Provides interval IDs for readings where channel 2 has energy > 0.0. @author Daniel Zhang (張道博)';
+
+
+--
+-- Name: dz_pv_readings_in_nonpv_mlh; Type: VIEW; Schema: public; Owner: postgres
+--
+
+CREATE VIEW dz_pv_readings_in_nonpv_mlh AS
+    SELECT nonpv_mlh.service_point_id, readings_unfiltered.end_time, readings_unfiltered.meter_name, readings_unfiltered.channel, readings_unfiltered.raw_value, readings_unfiltered.value, readings_unfiltered.uom, readings_unfiltered.start_time, readings_unfiltered.ird_end_time, readings_unfiltered.meter_data_id, readings_unfiltered.interval_id FROM ((dz_pv_interval_ids JOIN readings_unfiltered ON ((dz_pv_interval_ids.interval_id = readings_unfiltered.interval_id))) JOIN nonpv_mlh ON ((dz_pv_interval_ids.meter_name = (nonpv_mlh.meter_name)::bpchar)));
+
+
+ALTER TABLE public.dz_pv_readings_in_nonpv_mlh OWNER TO postgres;
+
+--
+-- Name: VIEW dz_pv_readings_in_nonpv_mlh; Type: COMMENT; Schema: public; Owner: postgres
+--
+
+COMMENT ON VIEW dz_pv_readings_in_nonpv_mlh IS 'A report of readings that are in the MLH but do not have PV service points IDs. @author Daniel Zhang (張道博)';
+
+
+--
+-- Name: dz_summary_pv_readings_in_nonpv_mlh; Type: VIEW; Schema: public; Owner: postgres
+--
+
+CREATE VIEW dz_summary_pv_readings_in_nonpv_mlh AS
+    SELECT dz_pv_readings_in_nonpv_mlh.meter_name, dz_pv_readings_in_nonpv_mlh.service_point_id, min(dz_pv_readings_in_nonpv_mlh.end_time) AS first_reading_time, max(dz_pv_readings_in_nonpv_mlh.end_time) AS last_reading_time FROM dz_pv_readings_in_nonpv_mlh GROUP BY dz_pv_readings_in_nonpv_mlh.meter_name, dz_pv_readings_in_nonpv_mlh.service_point_id;
+
+
+ALTER TABLE public.dz_summary_pv_readings_in_nonpv_mlh OWNER TO postgres;
+
+--
+-- Name: VIEW dz_summary_pv_readings_in_nonpv_mlh; Type: COMMENT; Schema: public; Owner: postgres
+--
+
+COMMENT ON VIEW dz_summary_pv_readings_in_nonpv_mlh IS 'Summary of service points and meters in the MLH that have PV readings but do not have PV Service Point IDs. @author Daniel Zhang (張道博)';
 
 
 --



--
-- Name: deprecated_meter_ids_for_houses_without_pv; Type: ACL; Schema: public; Owner: postgres
--


ALTER TABLE public.cd_meter_ids_for_houses_with_pv_with_locations OWNER TO eileen;

--
-- Name: readings_unfiltered; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW readings_unfiltered AS
    SELECT "Interval".end_time, "MeterData".meter_name, "Reading".channel, "Reading".raw_value, "Reading".value, "Reading".uom, "IntervalReadData".start_time, "IntervalReadData".end_time AS ird_end_time, "MeterData".meter_data_id, "Reading".interval_id FROM ((("MeterData" JOIN "IntervalReadData" ON (("MeterData".meter_data_id = "IntervalReadData".meter_data_id))) JOIN "Interval" ON (("IntervalReadData".interval_read_data_id = "Interval".interval_read_data_id))) JOIN "Reading" ON (("Interval".interval_id = "Reading".interval_id)));


ALTER TABLE public.readings_unfiltered OWNER TO postgres;

--
-- Name: VIEW readings_unfiltered; Type: COMMENT; Schema: public; Owner: postgres
--

COMMENT ON VIEW readings_unfiltered IS 'All readings along with their end times by meter. @author Daniel Zhang (張道博)';


--
-- Name: cd_energy_voltages_for_houses_with_pv; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW cd_energy_voltages_for_houses_with_pv AS
    SELECT cd_meter_ids_for_houses_with_pv_with_locations.device_util_id, view_readings_with_meter_id_unsorted.end_time, max(CASE WHEN (view_readings_with_meter_id_unsorted.channel = (1)::smallint) THEN view_readings_with_meter_id_unsorted.value ELSE NULL::real END) AS "Energy to House kwH", zero_to_null(max(CASE WHEN (view_readings_with_meter_id_unsorted.channel = (4)::smallint) THEN view_readings_with_meter_id_unsorted.value ELSE NULL::real END)) AS "Voltage", max(cd_meter_ids_for_houses_with_pv_with_locations.service_pt_longitude) AS service_pt_longitude, max(cd_meter_ids_for_houses_with_pv_with_locations.service_pt_latitude) AS service_pt_latitude, max((cd_meter_ids_for_houses_with_pv_with_locations.address1)::text) AS address1 FROM (cd_meter_ids_for_houses_with_pv_with_locations JOIN readings_unfiltered view_readings_with_meter_id_unsorted ON (((cd_meter_ids_for_houses_with_pv_with_locations.device_util_id)::bpchar = view_readings_with_meter_id_unsorted.meter_name))) WHERE ((view_readings_with_meter_id_unsorted.channel = (1)::smallint) OR (view_readings_with_meter_id_unsorted.channel = (4)::smallint)) GROUP BY cd_meter_ids_for_houses_with_pv_with_locations.device_util_id, view_readings_with_meter_id_unsorted.end_time;


ALTER TABLE public.cd_energy_voltages_for_houses_with_pv OWNER TO postgres;

--
-- Name: readings_by_meter_location_history; Type: VIEW; Schema: public; Owner: postgres
