wd_orca_api
This is a wrapper to communicate with the World Direct ORCA API, both Finish and Swedish instances.
WDOrcaAPI
Source code in physical_operations_utils/wd_orca_utils/WDOrcaAPI.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
__init__(country)
Initialize a World Direct Orca API client for a specific asset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country
|
str
|
The country for which to fetch data (eg. "SE", "FI"). |
required |
Example
from physical_operations_utils.wd_orca_utils.WDOrcaAPI import WDOrcaAPI
api = WDOrcaAPI("SE")
device_id = 23 # Hultema -> 32
signals_dict = {
249: "kw",
126: "m/s",
101: "boolean",
}
df = api.fetch_monitoring_data(
device_id=device_id,
signals=signals_dict.keys(),
start_time_lb_utc=pd.Timestamp.now(tz="UTC") - pd.Timedelta(hours=2),
end_time_lb_utc=pd.Timestamp.now(tz="UTC"),
)
df_dict = api.reformat(df, signals_dict=signals_dict, variable_id="735999100016826260", resolution_seconds=900)
for signal_id, df_signal in df_dict.items():
print(f"Signal ID: {signal_id}")
print(df_signal)
Source code in physical_operations_utils/wd_orca_utils/WDOrcaAPI.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
fetch_monitoring_data(device_id, signals, start_time_lb_utc=None, end_time_lb_utc=None)
Returns monitoring data from the World Direct API for a given signal, device and time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time_lb_utc
|
Timestamp
|
Start time in UTC. Default to 10 minutes before end_time_lb_utc. |
None
|
end_time_lb_utc
|
Timestamp
|
End time in UTC. Defaults to current time. |
None
|
device_id
|
int
|
The ID of the device. Stored in Ancillary Services Database [dbo.asset] |
required |
signals
|
list
|
List of signals to fetch (e.g., [101, 331]). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame containing the monitoring data. (timestamp_utc, variable_value, signal_id) |
Source code in physical_operations_utils/wd_orca_utils/WDOrcaAPI.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
reformat(df, signals_dict, variable_id, resolution_seconds=900)
Reformats the DataFrame from the World Direct API to a standardized CTDB format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input DataFrame containing columns 'timestamp_lb_utc', 'variable_value', and 'signal_id'. |
required |
signals_dict
|
dict
|
Dictionary mapping signal IDs to signal unit. |
required |
variable_id
|
str
|
The ID of the variable for which to reformat data. |
required |
resolution_seconds
|
int
|
The desired time resolution in seconds (e.g., 900 for 15 minutes, 3600 for 1 hour). |
900
|
Returns:
| Type | Description |
|---|---|
dict[int, DataFrame]
|
dict[int, pd.DataFrame]: A dictionary where the keys are signal IDs and the values are DataFrames reformatted to the CommonTradingData format, containing columns 'start_time_lb_utc', 'stop_time_lb_utc', 'db_updated_utc', 'variable_id', 'variable_value', 'variable_unit', and 'resolution_seconds'. |
Source code in physical_operations_utils/wd_orca_utils/WDOrcaAPI.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |