# INTERCONNMWFLOW

> INTERCONNMWFLOW shows Metered Interconnector flow data. INTERCONNMWFLOW shows the meter data provided by Meter Data Providers to MSATS.
> Despite the name, this view shows metered energy (MWh) and not power flow (MW).

!!! tip "Deprecation Warning"
    This table is in the [HISTORICAL TABLES](../packages/HISTORICAL TABLES.md) package,
    so is likely deprecated.

> INTERCONNMWFLOW data is public, available to all participants.
> 
> Source
> 
> INTERCONNMWFLOW updates weekly.
> 
> Volume
> 
> The volume depends on number of interconnectors and number of loads
> (versions) from MSATS per settlement run.

## Column Schema

### INTERCONNECTORID

> Interconnector Identifier

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

This column is mandatory, and a primary key.

Examples:

- `N-Q-MNSP1`
- `NSW1-QLD1`
- `V-S-MNSP1`
- `V-SA`
- `VIC1-NSW1`

### PERIODID

> Settlement Period identifier (half hour period)

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

This column is mandatory, and a primary key.

Examples:
`1`, `48`

### SETTLEMENTDATE

> Settlement Date (based on Trading day, not dispatch day - i.e. period 1 ends 00:30)

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

This column is mandatory, and a primary key.

Example: `2021/04/24 00:00:00`

Note that AEMO represents dates as datetimes with a midnight time component.

### VERSIONNO

> Meter Data Version number

SQL Type: `NUMBER(6,0)`
Polars Type: `pl.UInt32`

This column is mandatory, and a primary key.

Example: `8416`

### EXPORTENERGYVALUE

> Exported Energy value (MWh)

SQL Type: `NUMBER(15,6)`
Polars Type: `pl.Float64`

This column is not mandatory.

Examples:
`0.053009`, `0`, `341.405188`

### IMPORTENERGYVALUE

> Imported Energy value (MWh)

SQL Type: `NUMBER(15,6)`
Polars Type: `pl.Float64`

This column is not mandatory.

Examples:
`0.711736`, `0`, `569.0325`

### LASTCHANGED

> Record creation timestamp

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: `2021/05/01 00:13:10`

## New Data Timing

> Weekly

## 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"

# Dates are represented as datetimes at midnight

d_fmt = "%Y/%m/%d 00:00:00"

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("LASTCHANGED").str.strptime(pl.Datetime, dt_s_fmt),
        pl.col("SETTLEMENTDATE").str.strptime(pl.Date, d_fmt),
    )
    .cast(
        {
            "INTERCONNECTORID": pl.Categorical,
            "PERIODID": int,  # or pl.Int16
            "SETTLEMENTDATE": pl.Date(),
            "VERSIONNO": int,  # or pl.UInt32
            "EXPORTENERGYVALUE": pl.Float64,
            "IMPORTENERGYVALUE": pl.Float64,
        }
    )
    # Deduplicate
    # We want one row per ['INTERCONNECTORID', 'PERIODID', 'SETTLEMENTDATE', 'VERSIONNO']
    # Tie-breaker: greatest value of ['LASTCHANGED']
    .sort(["LASTCHANGED"], descending=False)
    .unique(
        subset=["INTERCONNECTORID", "PERIODID", "SETTLEMENTDATE", "VERSIONNO"],
        keep="last",
    )
)

```

### Nemosis

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

## Example File

From [PUBLIC_DVD_INTERCONNMWFLOW_202105010000.zip](https://www.nemweb.com.au/Data_Archive/Wholesale_Electricity/MMSDM/2021/MMSDM_2021_05/MMSDM_Historical_Data_SQLLoader/DATA/PUBLIC_DVD_INTERCONNMWFLOW_202105010000.zip)

=== "Raw Text with Metadata"
    ```csv
    C,SETP.WORLD,DVD_INTERCONNMWFLOW,AEMO,PUBLIC,2021/06/06,16:50:05,0000000342865512,,0000000342865442
    I,METER_DATA,INTERCONNECTOR,1,SETTLEMENTDATE,VERSIONNO,INTERCONNECTORID,PERIODID,IMPORTENERGYVALUE,EXPORTENERGYVALUE,LASTCHANGED
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,1,55.41791,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,2,56.694691,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,3,49.791938,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,4,42.627543,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,5,42.312102,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,6,40.973695,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,7,37.463234,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,8,37.360527,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,9,37.666586,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,10,41.17091,0,"2021/05/01 00:13:10"
    D,METER_DATA,INTERCONNECTOR,1,"2021/04/24 00:00:00",8416,N-Q-MNSP1,11,40.806816,0,"2021/05/01 00:13:10"
    ...
    C,"END OF REPORT",1003
    ```

## Availability

Visibility: Public

This table is in the public monthly [MMSDM archive](https://www.nemweb.com.au/Data_Archive/Wholesale_Electricity/MMSDM/).

I have collated the list of all those files into one place, in [this CSV metadata file](../../manifests/per_table/csv/INTERCONNMWFLOW.csv). (Columns `year`, `month`, `url`, `compressed_size` in bytes).

The earliest available data is month 1 of 2015.
The most recent available data is month 5 of 2021.

 Every month in between has a file. (No gaps.)

## Data Size

Each year of data is approximately
3 MB when zipped,
30 MB as unzipped CSV.

## Deduplication and PDR Loader Configuration

The primary keys are:

- [`INTERCONNECTORID`](#interconnectorid)

- [`PERIODID`](#periodid)

- [`SETTLEMENTDATE`](#settlementdate)

- [`VERSIONNO`](#versionno)

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

| Report Name | Report Subtype | Version | Undisclosed |
|---------------|-------------------|-----------|-------------|
| METER_DATA | INTERCONNECTOR  | 1 | ⚠️ |

!!! danger "Warning"
    Some of these file mappings are not in the
    [published PDR Loader configuration file](https://nemweb.com.au/Reports/Current/MMSDataModelReport/PDRCONFIG/PROD_PUBLIC_PDR_CONFIG_FULL.zip),
    even though files for this table exist with those metadata values.
    Mappings marked with ⚠️ have been added by me after manually inspecting those files.

This means that the CSV files start with metadata columns:

```csv
I,METER_DATA,INTERCONNECTOR,1,...
D,METER_DATA,INTERCONNECTOR,1,...
```

## Indexes

- [`LASTCHANGED`](#lastchanged)

## Links

[This page as JSON](../json/tables/INTERCONNMWFLOW/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/INTERCONNMWFLOW/json-schema.json) specification for this table.

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

## Other Information

Package: [HISTORICAL TABLES](../packages/HISTORICAL TABLES.md)
