Hi jthi,
Thanks for an approaching this, below is the script and I also attached the file.
Clear Log();
DefaultStartTime = (today()-12*3600);
DefaultEndTime = Today();
User = Get Environment Variable( "UserName" );
HourAlertRateDefault = 5;
SixHourAlertRateDefault = 5;
start_week = Week Of Year( Today() );
list_weeks = {};
For( i = 1, /*i<=10 &*/ i <= start_week, i++, //the i<=10 limits the combobox to last 10 weeks
//iwwtodate(start_week - (i - 1), year(today()), 2 /*Monday*/ )
Insert Into( list_weeks, Eval( "WW" || Char( start_week - (i - 1) ) ) )
);
User = Get Environment Variable( "UserName" );
// Define time function.
iwwtodate = Function( {_ww_, _year_, _dayofweek_},
//Local Variables
{_ww01thisyear_ = 0, _sundayww01_ = 0},
_ww01thisyear_ = Informat( "01Jan" || Char( _year_ ) );
_sundayww01_ = _ww01thisyear_ - (Day Of Week( _ww01thisyear_ ) - 1) * 24 * 3600;
(_ww_ - 1) * 7 * 24 * 3600 + _sundayww01_ + (_dayofweek_ - 1) * 24 * 3600
;
);
date_box = Function( //makes Graham's datebox that is hard to mess up
{timething = Today()},
{newbox},
current_ver = Left( JMP Version(), 2 );
If( Num( current_ver ) >= 11,
newbox = Eval(
Substitute(
Name Expr(
Number Edit Box(
timething, //Eval(Sub()) because of JMP quirk
10, //just need this because JMP doesn't default a width
<<Set function(
Function( {self},
{},
If( Is Missing( self << get ),
self << Set( Eval( DUMMY ) )//sets the date to the timething argument
)
)
),
<<Set Format( Format( "m/d/y h:m:s", 23, 0 ) );//makes datetime format for the box (gives calendar)
)
),
Expr( DUMMY ), timething
)
)
,
newbox = Text Edit Box( Char( Format( Timething, "m/d/y h:m:s" ) ) )
);
//newbox;
);
// End Define time function.
// Create expr window popup + Time checking
expr_window = Expr(
QueryOptionsChooser = New Window( "CHT PWL SPL CV Quick Monitoring " || User || "",
<<Modal,
<<Return Result,
V List Box(
Text Box( " " ),
Panel Box( "Do you want the Report to Auto-Refresh?",
H List Box(
V List Box( Text Box( "Method" ), tautorefresh = Combo Box( {"Run Once", "Auto Refresh"}, Show( tautorefresh << Get() ) ) ),
Text Box( " " ),
V List Box(
Text Box( "Option" ),
Option_select = Radio Box( {"Both", "Only SPEC-PL Last 30mins","Only PWL, SPL, CV " }, show( Option_select << get() ) )
),
V List Box(
Text Box( "Refresh every " ),
trefresh = Radio Box( {"5 minutes", "20 minutes", "60 minutes", "2 hours"}, Show( trefresh << Get() ) )
),
/*
Text Box( " " ),
V List Box( Text Box( "Refresh speed " ), rspeed_cb = Check Box( {"Fast"} ), rspeed_cb << Set( 1, 1 ) ),
*/
Text Box( " " ),
V List Box( Text Box( "Time Range Data for Auto refresh" ), days = Radio Box( {"1 Day", "0.5 Day", "6 Hours", "2 Hours"} ) ),
Text Box( " " ),
),
),
/*
Panel Box( "Please select the timeframe",
H List Box(
V List Box(
//Text box ("Time Method"),
//method=Radio Box( {"Days Ago", "Date Range"}),
Text Box( "Time Method" ),
method = Combo Box( {"Days Ago", "Date Range"} ),
),
Text Box( " " ),
V List Box( Text Box( "Days Ago" ), days = Radio Box( {"1.5", "3.5", "7", "2 Hours"} ) ),
Text Box( " " ),
V List Box(
Text Box( "Date Range" ),
V List Box(
startdatebox = date_box( Today() - 3.5 * 24 * 60 * 60 );
enddatebox = date_box( Today() );
startdate = startdatebox;,
enddate = enddatebox,
),
),
),
),
*/
Spacer Box( Size( 10, 10 ) ),
H List Box(
Spacer Box( Size( 10, 10 ) ),
Panel Box( "Choose Plant:",
H List Box(
Spacer Box( Size( 10, 0 ) ),
V List Box( "Plant", PlantSelect = Radio Box( {"DMT1", "DMT2", "KMT1", "PGT1", "PGT2"} ), PlantSelect << set( 1 ) ),
Spacer Box( Size( 10, 0 ) ),
)
),
Spacer Box( Size( 20, 10 ) ),
Panel Box( "Choose transaction time window:",
Text Box( " " ),
H List Box(
Text Box( "Start Time: " ),
StartTimeBox = H List Box(
StartTimePickBox = date_box( DefaultStartTime );
StartTimePick = StartTimePickBox;
//RocoTimeStartPick = date_box( (StartTimePick << Get) - 3600 );
),
Text Box( " " ),
Button Box( "Set to 12:00a.m.",
LastTime = StartTimePickBox << Get;
StartTimePickBox << Delete;
StartTimeBox << Append(
StartTimePickBox = date_box( 86400 * Floor( LastTime / 86400 ) );
StartTimePick = StartTimePickBox;
//RocoTimeStartPick = date_box( 86400 * Floor( (LastTime - 3600) / 86400 ) );
//RocoTimeStartPick = date_box( (StartTimePick << Get) - 3600 );
);
),
),
//RocoTimeStartPick = date_box( (StartTimePickBox << Get) - 3600 );
Text Box( " " ),
H List Box(
Text Box( "End Time: " ),
EndTimeBox = H List Box(
EndTimePickBox = date_box( DefaultEndTime );
EndTimePick = EndTimePickBox;
),
Text Box( " " ),
Button Box( "Set to 12:00a.m.",
LastTime = EndTimePickBox << Get;
EndTimePickBox << Delete;
EndTimeBox << Append(
EndTimePickBox = date_box( 86400 * Floor( LastTime / 86400 ) );
EndTimePick = EndTimePickBox;
);
),
),
),
Spacer Box( Size( 10, 10 ) ),
),
Spacer Box( Size( 20, 20 ) ),
//RocoTimeEndPick = date_box( (EndTimePick << Get) + 3600 );
H List Box( Align( Right ), Spacer Box(), Button Box( "OK" ), Button Box( "Cancel" ) )
) //end overall VListBox()
);
If( QueryOptionsChooser["Button"] == -1,
StopRunningTheThing
);
// Decleration Time to refresh.
days = days << Get;
dateoffset = Match( days, 1, "24", 2, "12", 3, "6", 4, "2" );
ar = tautorefresh << get;
ref = trefresh << get;
refresh = Match( ref, 1, "5", 2, "20", 3, "60", 4, "120" );
//rspeed = rspeed_cb << get;
//Process event Refresh ticked
If( ar == 2,
StartTimePick = date_box( Today() - Num( dateoffset ) * 3600 );
EndTimePick = date_box( DefaultEndTime );
);
RocoTimeStartPick = date_box( (StartTimePick << Get) - 3600 ); // Get roco time 1hour before CHT time
RocoTimeEndPick = date_box( (EndTimePick << Get) + 3600 );// Get roco time 1hour later CHT time
CHTTimeStartPick = date_box( (StartTimePick << Get) - 1800 );
CHTTimeEndPick = date_box( (EndTimePick << Get) + 1800 );
SPL_PL_start = date_box( (EndTimePick << Get) - 1800 );
SPL_PL_end = date_box( EndTimePick << Get );
//Collect user selections
PlantSelection = QueryOptionsChooser["PlantSelect"];
PlantName = Match( PlantSelection, 1, "DMT1", 2, "DMT2", 3, "KMT1", 4, "PGT1", 5, "PGT2" );
//show(PlantName);
StartTimeSelection = Format( StartTimePick << Get, "m/d/y h:m:s" );
EndTimeSelection = Format( EndTimePick << Get, "m/d/y h:m:s" );
RocoTimeStart = Format( RocoTimeStartPick << Get, "m/d/y h:m:s" );
RocoTimeEnd = Format( RocoTimeEndPick << Get, "m/d/y h:m:s" );
CHTTimeStart = Format( CHTTimeStartPick << Get, "m/d/y h:m:s" );
CHTTimeEnd = Format( CHTTimeEndPick << Get, "m/d/y h:m:s" );
SPLPL_timestart = Format( SPL_PL_start << Get, "m/d/y h:m:s" );
SPLPL_timeend = Format( SPL_PL_end << Get, "m/d/y h:m:s" );
option_selection = QueryOptionsChooser["Option_select"];
Print( option_selection );
Print( PlantName );
Print( StartTimeSelection );
Print( EndTimeSelection );
Print( RocoTimeStart );
Print( RocoTimeEnd );
Print( CHTTimeStart );
Print( CHTTimeEnd );
Print( refresh || " Refresh time" );
expr_TimeCheck = Expr(
TimeFixWindow = New Window( "Time Selection Error!",
<<Modal,
<<Return Result,
H List Box(
V List Box(
Text Box( " " ),
Text Box( "Your Start Time was later than your End Time! Care to try again?" ),
Text Box( " " ),
Text Box( "You chose:" ),
H List Box(
Text Box( " " ),
V List Box(
H List Box( Text Box( "Start Time: " || StartTimeSelection ), ),
H List Box( Text Box( "End Time: " || EndTimeSelection ) )
)
),
Text Box( " " ),
H List Box(
Text Box( "Start Time: " ),
StartTimePickBox = date_box( DefaultStartTime );
StartTimePick = StartTimePickBox;
),
Text Box( " " ),
H List Box(
Text Box( "End Time: " ),
EndTimePickBox = date_box( DefaultEndTime );
EndTimePick = EndTimePickBox;
),
Text Box( " " ),
)
),
H List Box( Align( Right ), Spacer Box(), OKButton = Button Box( "OK" ), Button Box( "Cancel" ) )
);
StartTimeSelection = Format( StartTimePick << Get, "m/d/y h:m:s" );
EndTimeSelection = Format( EndTimePick << Get, "m/d/y h:m:s" );
If( TimeFixWindow["Button"] == -1,
StopRunningTheThing
);
//Recurse as needed
If( Informat( StartTimeSelection, "m/d/y h:m:s" ) > Informat( EndTimeSelection, "m/d/y h:m:s" ),
Eval( expr_TimeCheck ),
Eval( expr_Scrap_SQL )
);
); //end expr_TimeCheck
If( Informat( StartTimeSelection, "m/d/y h:m:s" ) > Informat( EndTimeSelection, "m/d/y h:m:s" ),
Eval( expr_TimeCheck ),
VisionStartTime = Format(
Max( Informat( StartTimeSelection, "m/d/y h:m:s" ), 86400 * Floor( (Informat( EndTimeSelection, "m/d/y h:m:s" ) - 86400) / 86400 ) ),
"m/d/y h:m:s"
);
If( Today() - Informat( EndTimeSelection, "m/d/y h:m:s" ) > 86400,
VisionEndTime = Format(
Min( Informat( EndTimeSelection, "m/d/y h:m:s" ), 86400 * Ceiling( (Informat( EndTimeSelection, "m/d/y h:m:s" ) - 86400) / 86400 ) ),
"m/d/y h:m:s"
),
VisionEndTime = Format(
Min( Informat( VisionStartTime, "m/d/y h:m:s" ) + 86400, Informat( EndTimeSelection, "m/d/y h:m:s" ) ),
"m/d/y h:m:s"
)
);
);
);
SPL_expr = Expr(
QueryInfo = "DRIVER=SQL Server;SERVER=" || PlantName || "MESSQLODS;APP=Microsoft Office XP;WSID=FS-1261;DATABASE=ODS;Trusted_Connection=Yes";
//QueryInfo = "DRIVER=SQL Server;SERVER=" || PlantName ||
//"messqlods.fs.local;APP=Microsoft Office XP; WSID=FS-10967;DATABASE=ODS;Trusted_Connection=Yes";