 ALTER TABLE public.cd_energy_voltages_for_houses_with_pv OWNER TO eileen;
 
 --
+-- Name: readings_by_meter_location_history; Type: VIEW; Schema: public; Owner: postgres
+--
+
+CREATE VIEW readings_by_meter_location_history AS
+    SELECT "MeterLocationHistory".meter_name, "MeterLocationHistory".service_point_id, "MeterLocationHistory".service_point_latitude, "MeterLocationHistory".service_point_longitude, "MeterLocationHistory".location, "MeterLocationHistory".address, "MeterLocationHistory".latitude, "MeterLocationHistory".longitude, "MeterLocationHistory".installed, "MeterLocationHistory".uninstalled, "Reading".channel, "Reading".raw_value, "Reading".value, "Reading".uom, "Interval".end_time, "MeterData".meter_data_id FROM (((("MeterLocationHistory" JOIN "MeterData" ON ((("MeterLocationHistory".meter_name)::bpchar = "MeterData".meter_name))) 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) AND ("Interval".end_time >= "MeterLocationHistory".installed)) AND CASE WHEN ("MeterLocationHistory".uninstalled IS NULL) THEN true ELSE ("Interval".end_time < "MeterLocationHistory".uninstalled) END)));
+
+
+ALTER TABLE public.readings_by_meter_location_history OWNER TO postgres;
+
+--
+-- Name: VIEW readings_by_meter_location_history; Type: COMMENT; Schema: public; Owner: postgres
+--
+
+COMMENT ON VIEW readings_by_meter_location_history IS 'Readings that are referenced by the MLH. @author Daniel Zhang (張道博)';
+
+
+--
+-- Name: cd_report_testing; Type: VIEW; Schema: public; Owner: eileen
+--
+
+CREATE VIEW cd_report_testing AS
+    SELECT max((readings_by_meter_location_history.service_point_id)::text) AS max, sum(readings_by_meter_location_history.value) AS sum, (readings_by_meter_location_history.end_time)::date AS end_time FROM readings_by_meter_location_history WHERE (((readings_by_meter_location_history.end_time >= '2013-01-01 00:00:00'::timestamp without time zone) AND (readings_by_meter_location_history.end_time <= '2013-02-01 00:00:00'::timestamp without time zone)) AND ((readings_by_meter_location_history.service_point_id)::text = '98726'::text)) GROUP BY (readings_by_meter_location_history.end_time)::date;
+
+
+ALTER TABLE public.cd_report_testing OWNER TO eileen;
+
+--
+-- Name: cd_report_testing_2; Type: VIEW; Schema: public; Owner: eileen
+--
+
+CREATE VIEW cd_report_testing_2 AS
+    SELECT readings_by_meter_location_history.service_point_id, avg(readings_by_meter_location_history.value) AS avg, date_trunc('hour'::text, readings_by_meter_location_history.end_time) AS date_trunc FROM readings_by_meter_location_history WHERE ((readings_by_meter_location_history.end_time >= '2012-12-01 00:00:00'::timestamp without time zone) AND (readings_by_meter_location_history.end_time <= '2013-01-01 00:00:00'::timestamp without time zone)) GROUP BY readings_by_meter_location_history.service_point_id, date_trunc('hour'::text, readings_by_meter_location_history.end_time);
+
+
+ALTER TABLE public.cd_report_testing_2 OWNER TO eileen;
+
+--
+-- Name: cd_spid=115477_2013-01; Type: VIEW; Schema: public; Owner: eileen
+--
+
+CREATE VIEW "cd_spid=115477_2013-01" AS
+    SELECT readings_by_meter_location_history.service_point_id, sum(readings_by_meter_location_history.value) AS sum, (readings_by_meter_location_history.end_time)::date AS end_time FROM readings_by_meter_location_history WHERE ((((readings_by_meter_location_history.channel = (1)::smallint) AND ((readings_by_meter_location_history.service_point_id)::text = '115477'::text)) AND (readings_by_meter_location_history.end_time >= '2013-01-01 00:00:00'::timestamp without time zone)) AND (readings_by_meter_location_history.end_time < '2013-02-01 00:00:00'::timestamp without time zone)) GROUP BY (readings_by_meter_location_history.end_time)::date, readings_by_meter_location_history.service_point_id;
+
+
+ALTER TABLE public."cd_spid=115477_2013-01" OWNER TO eileen;
+
+--
 -- Name: count_of_event_duplicates; Type: VIEW; Schema: public; Owner: daniel
 --
 

--

COMMENT ON VIEW meter_ids_for_houses_without_pv IS 'Meter IDs for houses that do not have PV. @author Daniel Zhang (張道博)';


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

CREATE VIEW deprecated_readings_for_houses_without_pv AS
    SELECT meter_ids_for_houses_without_pv.device_util_id, view_readings_with_meter_id_unsorted.end_time, view_readings_with_meter_id_unsorted.channel, view_readings_with_meter_id_unsorted.raw_value, view_readings_with_meter_id_unsorted.value, view_readings_with_meter_id_unsorted.uom, view_readings_with_meter_id_unsorted.start_time, view_readings_with_meter_id_unsorted.ird_end_time FROM (meter_ids_for_houses_without_pv JOIN readings_unfiltered view_readings_with_meter_id_unsorted ON (((meter_ids_for_houses_without_pv.device_util_id)::integer = (view_readings_with_meter_id_unsorted.meter_name)::integer)));


ALTER TABLE public.deprecated_readings_for_houses_without_pv OWNER TO postgres;

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

COMMENT ON VIEW deprecated_readings_for_houses_without_pv IS 'Retrieve readings for houses that do not have PV. @author Daniel Zhang (張道博)';


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

CREATE VIEW deprecated_view_readings 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 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))) ORDER BY "Interval".end_time, "MeterData".meter_name, "Reading".channel;


ALTER TABLE public.deprecated_view_readings OWNER TO postgres;

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

COMMENT ON VIEW deprecated_view_readings IS 'View readings along with their end times.

@author Daniel Zhang (張道博)';


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

CREATE VIEW deprecated_view_readings_with_meter_id 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 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))) ORDER BY "Interval".end_time, "MeterData".meter_name, "Reading".channel;


ALTER TABLE public.deprecated_view_readings_with_meter_id OWNER TO postgres;

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

COMMENT ON VIEW deprecated_view_readings_with_meter_id IS 'View readings along with their end times. Retrieve the meter name along with the readings.

@author Daniel Zhang (張道博)';


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

CREATE VIEW deprecated_voltage_locations_highlow_events AS
    SELECT "LocationRecords".service_pt_latitude, "LocationRecords".service_pt_longitude, "LocationRecords".service_pt_height, "LocationRecords".device_serial_no, "LocationRecords".device_status, "MeterData".util_device_id, "MeterData".meter_name, "Reading".channel, "Reading".uom, "Reading".value AS voltage, "LocationRecords".address1, CASE WHEN ("Reading".value > (252)::double precision) THEN 1 ELSE 0 END AS high_event, CASE WHEN ("Reading".value < (228)::double precision) THEN 1 ELSE 0 END AS low_event, "LocationRecords".service_point_util_id, "Interval".end_time FROM (((("LocationRecords" JOIN "MeterData" ON (((("LocationRecords".device_util_id)::bpchar = "MeterData".util_device_id) AND (("LocationRecords".device_util_id)::bpchar = "MeterData".util_device_id)))) 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))) WHERE (("Reading".channel = 4) AND ("Reading".value > (0)::double precision));


ALTER TABLE public.deprecated_voltage_locations_highlow_events OWNER TO postgres;

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

CREATE VIEW readings_by_meter_location_history AS
    SELECT "MeterLocationHistory".meter_name, "MeterLocationHistory".service_point_id, "MeterLocationHistory".service_point_latitude, "MeterLocationHistory".service_point_longitude, "MeterLocationHistory".location, "MeterLocationHistory".address, "MeterLocationHistory".latitude, "MeterLocationHistory".longitude, "MeterLocationHistory".installed, "MeterLocationHistory".uninstalled, "Reading".channel, "Reading".raw_value, "Reading".value, "Reading".uom, "Interval".end_time, "MeterData".meter_data_id FROM (((("MeterLocationHistory" JOIN "MeterData" ON ((("MeterLocationHistory".meter_name)::bpchar = "MeterData".meter_name))) 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) AND ("Interval".end_time >= "MeterLocationHistory".installed)) AND CASE WHEN ("MeterLocationHistory".uninstalled IS NULL) THEN true ELSE ("Interval".end_time < "MeterLocationHistory".uninstalled) END)));


ALTER TABLE public.readings_by_meter_location_history OWNER TO postgres;

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

COMMENT ON VIEW readings_by_meter_location_history IS 'Readings that are referenced by the MLH. @author Daniel Zhang (張道博)';


--



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

