Oracle 8i Data Cartridge Developer's Guide Release 2 (8.1.6) Part Number A76937-01 |
|
Power Demand Cartridge Example , 7 of 8
This section describes how Oracle Time Series can be used with the Power Demand cartridge. With Time Series, you can apply the many time series and time scaling functions, such as various averages (arithmetic, cumulative, moving) and scaleup, to the power demand data.
This section assumes that you are familiar with time series concepts and basic usage information for Time Series. For detailed conceptual and usage information, see the Oracle8i Time Series User's Guide.
To use Time Series with the power demand data, you must perform the following steps:
This section does not discuss creating the underlying table for time series data or loading the data, because these operations were done in "Creating and Populating the Power Demand Table".
The following operations are not illustrated in this section, but should be included for use in a production environment:
INSTEAD
OF
triggers for actions that can modify time series data
Time Series requires that each data row include the following:
In this example, the timestamp is the SampleTime
attribute of the PowerDemand_Typ
object type, which is used to define the Samples
column of the PowerDemand_Tab
table.
In this example, the qualifier is the region
column of the PowerDemand_Tab
table. In a financial time series, the qualifier might be the stock ticker symbol (for example, ACME for Acme Corporation.)
In this example, the TotGridDemand
, MaxCellDemand
, MinCellDemand
, and CellDemandValues
attributes of the PowerDemand_Typ
object type can be used with Time Series functions. In a financial time series of daily stock market data, the columns to be operated on by Time Series functions might include the opening, closing, high, and low prices, and the total volume of shares traded.
To define the calendars, you must create their definitions in a table of calendars. If the table of calendars does not already exist, create it first. (The calendar table might not exist because this is your first use of Time Series; or a calendar table might exist for another application, but you choose to place power demand calendars in a separate table.)
The following statements create a table named PowerDemand_calendars
and defines the first of three calendars, this one named PowerReadingsCal_Hourly
. Explanatory notes follow the example.
-- Create the table for the calendars. CREATE TABLE PowerDemand_calendars of ORDSYS.ORDTCalendar; -- Create three calendars: first one for hourly readings, the -- other two for daily and monthly scaleup operations. INSERT INTO PowerDemand_calendarsVALUES( ORDSYS.ORDTCalendar( 0,
'PowerReadingsCal_Hourly',
3,
ORDSYS.ORDTPattern(ORDSYS.ORDTPatternBits(1),
to_date('01-01-1998 01','MM-DD-YYYY HH')), to_date('01-01-1998 01','MM-DD-YYYY HH'),
to_date('01-01-2008 01','MM-DD-YYYY HH'), ORDSYS.ORDTExceptions(),
ORDSYS.ORDTExceptions() ) );
Notes on the preceding example:
PowerDemand_calendars
is a table of ORDSYS
.ORDTCalendar
objects.
0
(zero) for calendar type (caltype
) indicates that this is an exception-based calendar.
PowerReadingsCal_Hourly
is the name of this calendar.
3
is the frequency code for hour
.
off
timestamps (that is, power readings are taken for all hours), any hourly timestamp can be used for the anchor date ('01-01-1998 01' is used in this example).
The following statements create two additional calendars, for use with scaleup operations in which hourly power demand readings are scaled up to compute daily and monthly values:
INSERT INTO PowerDemand_calendars VALUES( ORDSYS.ORDTCalendar( 0, 'PowerReadingsCal_Daily', 4, ORDSYS.ORDTPattern(ORDSYS.ORDTPatternBits(1), to_date('01-01-1998','MM-DD-YYYY')), to_date('01-01-1998','MM-DD-YYYY'), to_date('01-01-2008','MM-DD-YYYY'), ORDSYS.ORDTExceptions(), ORDSYS.ORDTExceptions() ) ); INSERT INTO PowerDemand_calendars VALUES( ORDSYS.ORDTCalendar( 0, 'PowerReadingsCal_Monthly', 6, ORDSYS.ORDTPattern(ORDSYS.ORDTPatternBits(1), to_date('01-01-1998','MM-DD-YYYY')), to_date('01-01-1998','MM-DD-YYYY'), to_date('01-01-2008','MM-DD-YYYY'), ORDSYS.ORDTExceptions(), ORDSYS.ORDTExceptions() ) );
Create a table to map regions to calendars, and insert a row for each region. In this example, regions 1 and 2 are associated with the PowerReadingsCal_Hourly
calendar. This mapping allows the reference-based view to be used.
-- Create the metadata table and insert rows for two regions. CREATE TABLE PowerDemand_metadata ( region number, calendarname varchar2(30), constraint pk_PowerDemand_metadata primary key (region)); INSERT INTO PowerDemand_metadata VALUES(1, 'PowerReadingsCal_Hourly'); INSERT INTO PowerDemand_metadata VALUES(2, 'PowerReadingsCal_Hourly');
Create a reference-based view for convenient and efficient access to time series data.
The following statements create a reference-based view for the power demand data:
-- Create the reference view. CREATE OR REPLACE VIEW PowerDemand_rv(region,TotGridDemand, MaxCellDemand,MinCellDemand,CellDemandValues) AS SELECT meta.region, ORDSYS.ORDTNumSeriesIOTRef( 'TotGridDemand_ts', Ref(cal), 'PowerCartUser.PowerDemand_Tab T', 'T.sample.SampleTime', 'T.sample.TotGridDemand', 'region', meta.region), ORDSYS.ORDTNumSeriesIOTRef( 'MaxCellDemand_ts', Ref(cal), 'PowerCartUser.PowerDemand_Tab T', 'T.sample.SampleTime', 'T.sample.MaxCellDemand', 'region', meta.region), ORDSYS.ORDTNumSeriesIOTRef( 'MinCellDemand_ts', Ref(cal), 'PowerCartUser.PowerDemand_Tab T', 'T.sample.SampleTime', 'T.sample.MinCellDemand', 'region', meta.region), ORDSYS.ORDTNumSeriesIOTRef( 'CellDemandValues_ts', Ref(cal), 'PowerCartUser.PowerDemand_Tab T', 'T.sample.SampleTime', 'T.sample.CellDemandValues', 'region', meta.region) FROM PowerDemand_metadata meta, PowerDemand_calendars cal WHERE meta.calendarname = cal.name;
Formulating time series queries involves invoking time series or time scaling functions, or both. The power demand example includes SQL and PL/SQL queries that return the following information:
TotGridDemand
) for region 1
TotGridDemand
for region 1
TotGridDemand
for region 1
TotGridDemand
for region 1
TotGridDemand
readings for region 1 from hourly to daily
MinCellDemand
and MaxCellDemand
)
The following example shows the execution of the Lead and Moving average functions with power demand data. This example includes the SQL statements and the output with ECHO
and SERVEROUTPUT
turned on.
SVRMGR> -- Lead: Using timestamps from 1:00 through 5:00 AM on 01-Feb-1998, SVRMGR> -- create a time series of the number of timestamps 24 hours later. SVRMGR> -- The result is a time series from 1:00 through 5:00 AM on 02-Feb-1998 SVRMGR> -- containing the same TotGridDemand values as the corresponding SVRMGR> -- timestamps on 01-Feb-1998. SVRMGR> -- SVRMGR> SELECT * FROM the 2> (SELECT CAST(ORDSYS.TIMESERIES.ExtractTable( 3> ORDSYS.TIMESERIES.Lead(ts.TotGridDemand, 24, 4> to_date('01-FEB-98 01','DD-MON-YY HH'), 5> to_date('01-FEB-98 05','DD-MON-YY HH')) 6> ) AS ordsys.ordtNumTab) 7> FROM PowerCartUser.powerdemand_rv ts 8> WHERE region = 1); TSTAMP VALUE --------- ---------- 02-FEB-98 90 02-FEB-98 89 02-FEB-98 88 02-FEB-98 87 02-FEB-98 86 5 rows selected. SVRMGR> SVRMGR> -- SVRMGR> -- Compute a moving average over a window of 3 timestamps SVRMGR> -- for region 1. SVRMGR> -- SVRMGR> SVRMGR> SELECT * FROM the 2> (SELECT CAST(ORDSYS.TIMESERIES.ExtractTable( 3> ORDSYS.TIMESERIES.Mavg(ts.TotGridDemand,3) 4> ) AS ordsys.ordtNumTab) 5> FROM PowerCartUser.powerdemand_rv ts 6> WHERE region = 1); TSTAMP VALUE --------- ---------- 01-FEB-98 01-FEB-98 01-FEB-98 89 01-FEB-98 88 01-FEB-98 87 5 rows selected.
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|