/* All user scripts should derive from the base "Application" class */
require ("Application");
/* Get the Gamma library functions and methods for ODBC and/or
* Windows programming. Uncomment either or both. */
require ("WgetSupport");
//require ("ODBCSupport");
/* Applications share the execution thread and the global name
* space, so we create a class that contains all of the functions
* and variables for the application. This does two things:
* 1) creates a private name space for the application, and
* 2) allows you to re-load the application to create either
* a new unique instance or multiple instances without
* damaging an existing running instance.
*/
class GetWebData Application
{
}
/* Use methods to create functions outside the 'main line'. */
method GetWebData.getPricePage ()
{
//princ(ResultString, "\n");
local split = string_split(ResultString, "$", 2);
local arraySplit = list_to_array(split);
//princ(arraySplit[0]," FIRST \n\n\n\n\n\n");
//princ(arraySplit[1]," Next \n\n\n\n\n\n\n");
//princ(substr(arraySplit[1], 0, 5), "\n");
datahub_write("Power:Price", number(substr(arraySplit[1], 0, 5)));
}
method GetWebData.getTableData(resultString, title, tag)
{
local stringPos = strstr(resultString, title);
local subString1 = substr(resultString, stringPos+length(title)+9,10);
local stringPos2 = strstr(subString1, "<");
local value = substr(subString1, 0, stringPos2);
//princ(value, " = Testing \n");
datahub_write(tag, number(value));
}
method GetWebData.getCoalPage()
{
//princ(ResultString, "\n");
local stringPosSD5 = strstr(ResultString, "(SD6)");
//princ(substr(ResultString, stringPosSD5+14, 3), " = SD6_MC \n");
//princ(substr(ResultString, stringPosSD5+26, 3), " = SD6_TNG \n");
datahub_write("Coal:SD6_Max Capacity", number(substr(ResultString, stringPosSD5+14, 3)));
datahub_write("Coal:SD6_Total Net Generation", number(substr(ResultString, stringPosSD5+26, 3)));
local stringPosSD6 = strstr(ResultString, "(SD5)");
//princ(substr(ResultString, stringPosSD6+14, 3), " = SD5_MC \n");
//princ(substr(ResultString, stringPosSD6+26, 3), " = SD5_TNG \n");
datahub_write("Coal:SD5_Max Capacity", number(substr(ResultString, stringPosSD6+14, 3)));
datahub_write("Coal:SD5_Total Net Generation", number(substr(ResultString, stringPosSD6+26, 3)));
.getTableData(ResultString, "LSSi Offered Volume", "Power:LSSi_Offered_Volume");
.getTableData(ResultString, "LSSi Armed Dispatch", "Power:LSSi_Armed_Dispatch");
.getTableData(ResultString, "British Columbia", "Power:British_Columbia");
.getTableData(ResultString, "Saskatchewan", "Power:Saskatchewan");
.getTableData(ResultString, "Interchange", "Power:Interchange");
.getTableData(ResultString, "Alberta Internal Load (AIL)", "Power:Alberta_Internal_Load_(AIL)");
}
method GetWebData.getPoolPricePage()
{
//princ(ResultString, "\n");
local textToSkip = "
- | - | - | ";
local textToFind1 = "";
local textToFind2 = " | ";
local stringPos1 = strstr(ResultString, textToSkip);
//princ("String Pos = ", stringPos1, "\n");
local subString1 = substr(ResultString, stringPos1 +length(textToSkip), -1);
//princ("SubString = ", subString1, "\n");
local stringPos2 = strstr(subString1, textToFind1);
//princ("String Pos2 = ", stringPos2, "\n");
local subString2 = substr(subString1, stringPos2+length(textToFind1), -1);
//princ("SubString2 = ", subString2, "\n");
local stringPos3 = strstr(subString2, textToFind2);
//princ("String Pos3 = ", stringPos3, "\n");
local realValue = substr(subString2, 0, stringPos3);
//princ("realValue = ", realValue, "\n");
if(realValue != "-")
{
datahub_write("Power:Past_Pooled_Price", number(realValue));
}
else
{
local stringPos5 = strstr(subString2, textToFind1);
//princ("String Pos2 = ", stringPos2, "\n");
local subString5 = substr(subString2, stringPos5+length(textToFind1), -1);
//princ("SubString5 = ", subString5, "\n");
local stringPos6 = strstr(subString5, textToFind1);
local subString6 = substr(subString5, stringPos6+length(textToFind1), -1);
//princ("SubString6 = ", subString6, "\n");
local stringPos7 = strstr(subString6, textToFind1);
local subString7 = substr(subString6, stringPos7+length(textToFind1), -1);
//princ("SubString7 = ", subString7, "\n");
local stringPos8 = strstr(subString7, textToFind2);
//princ("String Pos4 = ", stringPos4, "\n");
local realValue = substr(subString7, 0, stringPos8);
//princ("realValue = ", realValue, "\n");
if(realValue != "-")
{
datahub_write("Power:Past_Pooled_Price", number(realValue));
}
}
}
method GetWebData.getSMPPage()
{
//princ(ResultString, "\n");
local textToFind1 = "";
local textToFind2 = "";
local stringPos1 = strstr(ResultString, textToFind1);
//princ("String Pos = ", stringPos1, "\n");
local subString1 = substr(ResultString, stringPos1 +length(textToFind1), -1);
//princ("SubString = ", subString1, "\n");
local stringPos2 = strstr(subString1, textToFind1);
//princ("String Pos2 = ", stringPos2, "\n");
local subString2 = substr(subString1, stringPos2+length(textToFind1), -1);
//princ("SubString2 = ", subString2, "\n");
local stringPos3 = strstr(subString2, textToFind2);
//princ("String Pos2 = ", stringPos2, "\n");
local realValue = substr(subString2, 0, stringPos3);
//princ("SubString3 = ", subString3, "\n");
datahub_write("Power:SMP", number(realValue));
}
method GetWebData.getPage()
{
Wget("http://ets.aeso.ca/ets_web/ip/Market/Reports/CSMPriceReportServlet?contentType=html", `(@self).getPricePage());
Wget("http://ets.aeso.ca/ets_web/ip/Market/Reports/CSDReportServlet?contentType=html", `(@self).getCoalPage());
Wget("http://ets.aeso.ca/ets_web/ip/Market/Reports/SMPriceReportServlet?contentType=html", `(@self).getPoolPricePage());
Wget("http://ets.aeso.ca/ets_web/ip/Market/Reports/CSMPriceReportServlet?contentType=html", `(@self).getSMPPage());
}
/* Write the 'main line' of the program here. */
method GetWebData.constructor ()
{
.TimerEvery(5, `(@self).getPage());
}
/* Any code to be run when the program gets shut down. */
method GetWebData.destructor ()
{
}
ApplicationSingleton (GetWebData);
|