# CONTRACTAGC

> CONTRACTAGC shows Automatic Generation Control (AGC) contract details for each dispatchable unit. There is a separate contract for each unit.

> CONTRACTAGC data is confidential to the relevant participant.
> 
> Source
> 
> CONTRACTAGC updates only where there is a contract variation.

## Column Schema

### CONTRACTID

> Contract Identifier

SQL Type: `VARCHAR2(10)`
Polars Type: `pl.Categorical`

This column is mandatory, and a primary key.

### VERSIONNO

> Contract Version No

SQL Type: `NUMBER(3,0)`
Polars Type: `pl.UInt16`

This column is mandatory, and a primary key.

### AUTHORISEDBY

> User Name

SQL Type: `VARCHAR2(15)`
Polars Type: `str`

This column is not mandatory.

### AUTHORISEDDATE

> Date Contract was Authorised

!!! danger "Warning"
    Despite what the name suggests, this is a datetime, not a date.

SQL Type: `DATE`
Polars Type: `pl.Datetime()`

This column is not mandatory.

Example: `2026/01/20 00:05:00`

### BS

> Block Size

SQL Type: `NUMBER(10,2)`
Polars Type: `pl.Float64`

This column is not mandatory.

### CCPRICE

> Compensation Cap in $

SQL Type: `NUMBER(10,2)`
Polars Type: `pl.Float64`

This column is not mandatory.

### CRL

> Control Range Lower 5 Min MW

SQL Type: `NUMBER(4,0)`
Polars Type: `pl.Int16`

This column is not mandatory.

### CRR

> Control Range Raise 5 Min MW

SQL Type: `NUMBER(4,0)`
Polars Type: `pl.Int16`

This column is not mandatory.

### DUID

> Dispatchable Unit ID

!!! danger "Warning"
    This column may contain funny characters such as / (slash) or # (hash). This may break hive-style partitioning.

For more information, see the [dedicated documentation page](../../guide/querying.md#duid-genset-id-etc).

SQL Type: `VARCHAR2(10)`
Polars Type: `pl.Categorical`

This column is not mandatory.

Example: `W/HOE#2`

### ENDDATE

> End date of contract

!!! danger "Warning"
    Despite what the name suggests, this is a datetime, not a date.

SQL Type: `DATE`
Polars Type: `pl.Datetime()`

This column is not mandatory.

Example: `2026/01/20 00:05:00`

### LASTCHANGED

> Last date and time record changed

For more information, see the [dedicated documentation page](../../guide/querying.md#deduplication).

SQL Type: `DATE`
Polars Type: `pl.Datetime()`

This column is not mandatory.

Example: `2026/01/20 00:05:00`

### PARTICIPANTID

> Unique participant identifier

For more information, see the [dedicated documentation page](../../guide/querying.md#duid-genset-id-etc).

SQL Type: `VARCHAR2(10)`
Polars Type: `pl.Categorical`

This column is not mandatory.

### RLPRICE

> Enabling Price in $

SQL Type: `NUMBER(10,2)`
Polars Type: `pl.Float64`

This column is not mandatory.

### STARTDATE

> Starting Date of Contract

!!! danger "Warning"
    Despite what the name suggests, this is a datetime, not a date.

SQL Type: `DATE`
Polars Type: `pl.Datetime()`

This column is not mandatory.

Example: `2026/01/20 00:05:00`

## New Data Timing

> When there is a contract variation

## Code Examples

### Polars

Explicitly listing every column, casting to enums, categoricals etc is not essential, but may speed up parsing.
Swapping `int` for `pl.UInt16`, `pl.Int32` would also speed up parsing. However some of the datatypes are inferred, so they may be wrong.

This code deduplicates for you.
Deduplication is normally only required across multiple months.

This code assumes that all columns are present, which may not be true for older files.

```python
import polars as pl
import polars.selectors as cs

# e.g. "2029/03/15 00:05:00"
dt_s_fmt = "%Y/%m/%d %H:%M:%S"

csv_paths = ["SOMEFILE.CSV", "OTHERFILE.CSV"]

lf = (
    pl.concat(
        [
            pl.scan_csv(
                csv_path,  # must be unzipped beforehand
                skip_rows=1,  # skip the header
                infer_schema=False,  # much faster
            )
            .filter(cs.by_index(0) == "D")  # drop the footer
            .select(~cs.by_index(range(4)))  # drop metadata columns
            for csv_path in csv_paths
        ],
        how="diagonal_relaxed",
    )
    .with_columns(
        pl.col("AUTHORISEDDATE", "ENDDATE", "LASTCHANGED", "STARTDATE").str.strptime(
            pl.Datetime, dt_s_fmt
        ),
    )
    .cast(
        {
            "CONTRACTID": pl.Categorical,
            "VERSIONNO": int,  # or pl.UInt16
            "AUTHORISEDBY": str,
            "BS": pl.Float64,
            "CCPRICE": pl.Float64,
            "CRL": int,  # or pl.Int16
            "CRR": int,  # or pl.Int16
            "DUID": pl.Categorical,
            "PARTICIPANTID": pl.Categorical,
            "RLPRICE": pl.Float64,
        }
    )
    # Deduplicate
    # We want one row per ['CONTRACTID', 'VERSIONNO']
    # Tie-breaker: greatest value of ['LASTCHANGED']
    .sort(["LASTCHANGED"], descending=False)
    .unique(subset=["CONTRACTID", "VERSIONNO"], keep="last")
)

```

### Nemosis

This table is not yet available in [Nemosis](https://github.com/UNSW-CEEM/NEMOSIS/#static_table).

## Availability

Visibility: Private

This table is not available in the public monthly [MMSDM archive](https://www.nemweb.com.au/Data_Archive/Wholesale_Electricity/MMSDM/).
Is is only available to registered market participants over FTP inside a VPN.

## Deduplication and PDR Loader Configuration

The primary keys are:

- [`CONTRACTID`](#contractid)

- [`VERSIONNO`](#versionno)

The transaction type is ["INSERT-UPDATE"](https://di-help.docs.public.aemo.com.au/Content/pdrLoader/How_it_works.htm?TocPath=pdrLoader%7CAbout+pdrLoader%7C_____5#UPDATEINSERT), which means that you will likely see duplicate data with different values.

You should deduplicate by sorting based on `LASTCHANGED`, within each group of primary keys.

[PDR Loader configuration](https://nemweb.com.au/Reports/Current/MMSDataModelReport/PDRCONFIG/PROD_PUBLIC_PDR_CONFIG_FULL.zip) is:

| Report Name | Report Subtype | Version |
|---------------|-------------------|-----------|
| ANCILLIARY_SERVICES | CONTRACTAGC  | 1 |

This means that the CSV files start with metadata columns:

```csv
I,ANCILLIARY_SERVICES,CONTRACTAGC,1,...
D,ANCILLIARY_SERVICES,CONTRACTAGC,1,...
```

`ROW_FILTER_TYPE` is LASTCHANGED

## Indexes

There is more than one index.

Index 1:

- [`LASTCHANGED`](#lastchanged)

Index 2:

- [`PARTICIPANTID`](#participantid)

- [`CONTRACTID`](#contractid)

## Links

[This page as JSON](../json/tables/CONTRACTAGC/bespoke.json) (schema documented [here](https://gitlab.com/MatthewDavis/mms-schema/-/blob/master/schema.py?ref_type=heads), but may change)

Download a [JSON Schema](../json/tables/CONTRACTAGC/json-schema.json) specification for this table.

[Official AEMO schema documentation](https://nemweb.com.au/Reports/Current/MMSDataModelReport/Electricity/ElectricityDataModelReport_files/Elec6.htm#1)

## Other Information

Package: [ANCILLARY_SERVICES](../packages/ANCILLARY_SERVICES.md)
