Skip to content

Commit

Permalink
Implemented getapiversion report & optimized get_df testing
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmostGreenz committed Oct 30, 2024
1 parent e591d9b commit dd0283e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
26 changes: 26 additions & 0 deletions MISOReports/MISOReports.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import requests
import pandas as pd
import packaging.version


class URLBuilder(ABC):
Expand Down Expand Up @@ -670,6 +671,22 @@ def parse_generationoutagesplusminusfivedays(
)

return df

@staticmethod
def parse_apiversion(
res: requests.Response,
) -> pd.DataFrame:
text = res.text
dictionary = json.loads(text)


df = pd.DataFrame(
data=[dictionary]
)

df['Semantic'] = df['Semantic'].apply(packaging.version.Version)

return df


report_mappings: dict[str, Report] = {
Expand Down Expand Up @@ -949,6 +966,15 @@ def parse_generationoutagesplusminusfivedays(
type_to_parse="csv",
parser=ReportParsers.parse_generationoutagesplusminusfivedays
),

"apiversion": Report(
url_builder=MISORTWDDataBrokerURLBuilder(
target="getapiversion",
supported_extensions=["json"],
),
type_to_parse="json",
parser=ReportParsers.parse_apiversion,
),
}

@staticmethod
Expand Down
39 changes: 20 additions & 19 deletions MISOReports/test_MISOReports.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,25 @@ def test_MISOMarketReportsURLBuilder_build_url(
def test_MISORTWDData_get_df_completes_and_has_something_or_is_not_implemented():
mappings = MISOReports.report_mappings

expected_columns = [
{'INTERVALEST', 'CATEGORY', 'ACT', 'TOTALMW'},
{'instantEST', 'value'},
{'SOLUTIONTIME', 'CASEAPPROVALDATE', 'PJMFORECASTEDLMP'},
{"ForecastDateTimeEST", "ForecastWindValue", "ActualWindValue", "ForecastHourEndingEST", "ForecastSolarValue", "ActualHourEndingEST", "ActualDateTimeEST", "ActualSolarValue"},
{"HourEndingEST", "Value", "DateTimeEST"},
{"ForecastDateTimeEST", "ActualValue", "ForecastHourEndingEST", "ActualHourEndingEST", "ActualDateTimeEST", "ForecastValue"},
{"Congestion", "Loss", "LMP", "Name"},
{'CSWS', 'MHEB', 'PJM', 'OKGE', 'timestamp', 'SPA', 'SWPP', 'WAUE', 'MISO', 'SOCO', 'TVA', 'GLHB', 'LGEE', 'ONT', 'AEC', 'AECI'},
{'timestamp', 'NSI'},
{'Time', 'Value'},
{'Name', 'Description', 'Price', 'Period'},
{'COMMIT_REASON', 'MKT_INT_END_EST', 'NUM_RESOURCES', 'TOTAL_ECON_MAX'},
{'Name', 'Value'},
{' UDSFLOW_MW', 'INTERVALEST', 'NORTH_SOUTH_LIMIT', 'RAW_MW', 'SOUTH_NORTH_LIMIT'},
{'Derated', 'Forced', 'OutageDate', 'OutageMonthDay', 'Planned', 'Unplanned'},

]
expected_columns = frozenset({
('INTERVALEST', 'CATEGORY', 'ACT', 'TOTALMW'),
('instantEST', 'value'),
('CASEAPPROVALDATE', 'SOLUTIONTIME', 'PJMFORECASTEDLMP'),
('ForecastDateTimeEST', 'ForecastHourEndingEST', 'ForecastWindValue', 'ForecastSolarValue', 'ActualDateTimeEST', 'ActualHourEndingEST', 'ActualWindValue', 'ActualSolarValue'),
('DateTimeEST', 'HourEndingEST', 'Value'),
('ForecastDateTimeEST', 'ForecastHourEndingEST', 'ForecastValue', 'ActualDateTimeEST', 'ActualHourEndingEST', 'ActualValue'),
('Name', 'LMP', 'Loss', 'Congestion'),
('timestamp', 'AEC', 'AECI', 'CSWS', 'GLHB', 'LGEE', 'MHEB', 'MISO', 'OKGE', 'ONT', 'PJM', 'SOCO', 'SPA', 'SWPP', 'TVA', 'WAUE'),
('timestamp', 'NSI'),
('Time', 'Value'),
('Name', 'Price', 'Period', 'Description'),
('MKT_INT_END_EST', 'COMMIT_REASON', 'TOTAL_ECON_MAX', 'NUM_RESOURCES'),
('Name', 'Value'),
('INTERVALEST', 'NORTH_SOUTH_LIMIT', 'SOUTH_NORTH_LIMIT', 'RAW_MW', 'UDSFLOW_MW'),
('INTERVALEST', 'NORTH_SOUTH_LIMIT', 'SOUTH_NORTH_LIMIT', 'RAW_MW', ' UDSFLOW_MW'),
('OutageDate', 'OutageMonthDay', 'Unplanned', 'Planned', 'Forced', 'Derated'),
('Semantic',),
})

for k, v in mappings.items():
if type(v.url_builder) == MISORTWDDataBrokerURLBuilder:
Expand All @@ -149,7 +150,7 @@ def test_MISORTWDData_get_df_completes_and_has_something_or_is_not_implemented()
assert isinstance(df, pd.DataFrame)
assert not df.empty

df_columns = set(df.columns)
df_columns = tuple(df.columns)
assert df_columns in expected_columns, \
f"Columns {df_columns} do not match any expected format."

Expand Down
2 changes: 1 addition & 1 deletion TODOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ We may add more in the future, but the ones listed currently are the ones that w
The possible extensions (ones that are offered in the link) are listed on the right side.

```
https://api.misoenergy.org/MISORTWDDataBroker/DataBrokerServices.asmx?messageType=getapiversion&returnType=json JSON
https://api.misoenergy.org/MISORTWDDataBroker/DataBrokerServices.asmx?messageType=getapiversion&returnType=json JSON
https://api.misoenergy.org/MISORTWDDataBroker/DataBrokerServices.asmx?messageType=getfuelmix&returnType=csv CSV XML JSON
https://api.misoenergy.org/MISORTWDDataBroker/DataBrokerServices.asmx?messageType=getace&returnType=csv CSV XML JSON
https://api.misoenergy.org/MISORTWDDataBroker/DataBrokerServices.asmx?messageType=getAncillaryServicesMCP&returnType=csv CSV XML JSON
Expand Down

0 comments on commit dd0283e

Please sign in to comment.