KMPRUTL3 ;OAK/RAK - Resource Usage Monitor Utilities ;5/28/03 09:16
;;2.0;CAPACITY MANAGEMENT - RUM;;May 28, 2003
;
HRSDAYS(KMPRSDT,KMPREDT,KMPRKILL,KMPRRES) ;
;-- number of days/hours in the date range
;-----------------------------------------------------------------------
; KMPRSDT.. Start Date in internal fileman format
; KMPREDT.. End Date in internal fileman format
; KMPRKILL. Kill node after processing:
; 0 - do not kill
; 1 - kill
; KMPRRES.. Array (passed by reference) containing days/hours info
; in format: KMPRRES(KMPRSDT,Node)=Data
; Where Data equals for the specified date range:
; '^' Piece 1 - Prime Time Days
; '^' Piece 2 - Prime Time Hours
; '^' Piece 3 - Non-Prime Time Days
; '^' Piece 4 - Non-Prime Time Hours
; '^' Piece 5 - Workday Days
; '^' Piece 6 - Workday Hours
; '^' Piece 7 - Non-Workday Days
; '^' Piece 8 - Non-Workday Hours
; Example for the specified date range:
; KMPRRES(3030418,"999A01")=5^45^7^123^5^120^2^48
; KMPRRES(3030418,"999A02")=5^40^7^120^5^110^2^45 <=partial
; KMPRRES(3030418,"999A03")=5^45^7^123^5^120^2^48
; KMPRRES( ... , ... )=...
;-----------------------------------------------------------------------
;
K KMPRRES
;
Q:'$G(KMPRSDT)
Q:'$G(KMPREDT)
S KMPRKILL=+$G(KMPRKILL)
;
N DATA,DATE,DAYS,HOURS,I,NODE
;
D HOURS(KMPRSDT,KMPREDT,KMPRKILL,.HOURS)
Q:'$D(HOURS)
;
S NODE=""
F S NODE=$O(HOURS(NODE)) Q:NODE="" D
.S (DATE,DAYS,HOURS)=0
.F S DATE=$O(HOURS(NODE,DATE)) Q:'DATE D
..;
..; piece 1 - prime time hours per day
..; piece 2 - non-prime time hours per day
..; piece 3 - workday hours per day
..; piece 4 - non-workday hours per day
..S DATA=HOURS(NODE,DATE)
..;
..F I=1:1:4 D
...; total hours for the specified date range
...S $P(HOURS,U,I)=$P(HOURS,U,I)+$P(DATA,U,I)
...; if current day has hours then increment total days for the
...; specified date range
...S:$P(DATA,U,I) $P(DAYS,U,I)=$P(DAYS,U,I)+1
.;
.; back to NODE level
.S KMPRRES(KMPRSDT,NODE)=$P(DAYS,U)_"^"_$P(HOURS,U)_"^"_$P(DAYS,U,2)_"^"_$P(HOURS,U,2)_"^"_$P(DAYS,U,3)_"^"_$P(HOURS,U,3)_"^"_$P(DAYS,U,4)_"^"_$P(HOURS,U,4)
;
Q
;
HOURS(KMPRSDT,KMPREDT,KMPRKILL,KMPRRES) ;
;-- determine prime time & non-prime time hours per day
;-- determine workday & non-workday hours per day
;-----------------------------------------------------------------------
; KMPRSDT.. Start Date in internal fileman format
; KMPREDT.. End Date in internal fileman format
; KMPRKILL. Kill node after processing:
; 0 - do not kill
; 1 - kill
; KMPRRES.. Array (passed by reference) containing hours info
; in format: KMPRRES(Date,Node)=Data
; Where Data equals:
; '^' Piece 1 - Prime Time Hours per day
; '^' Piece 2 - Non-Prime Time Hours per day
; '^' Piece 3 - Workday Hours per day
; '^' Piece 4 - Non-Workday Hours per day
; Example:
; KMPRRES(3030418,"999A01")=9^15^24^0 <= Friday
; KMPRRES(3030418,"999A02")=4^10^14^0 <= Friday (partial)
; KMPRRES(3030419,"999A01")=0^24^0^24 <= Saturday
; KMPRRES( ... , ... )= ...
;-----------------------------------------------------------------------
;
K KMPRRES
;
Q:'$G(KMPRSDT)
Q:'$G(KMPREDT)
S KMPRKILL=+$G(KMPRKILL)
;
N DATA,DATE,DOW,END,HOURS,HRS,I,NODE,PIECE,WORKDAY
;
; end date
S END=KMPREDT
S DATE=KMPRSDT-.1,(DAYS,HOURS)=""
F S DATE=$O(^KMPTMP("KMPR","HOURS",DATE)) Q:'DATE!(DATE>END) D
.;
.Q:DATE<KMPRSDT!(DATE>END)
.;
.S NODE="",DOW=$$DOW^XLFDT(DATE,1),WORKDAY=$$WORKDAY^XUWORKDY(DATE)
.;
.; prime time (8am to 5pm)
.; if not saturday or sunday or holiday then prime time (piece 1)
.; if saturday or sunday then non-prime time (piece 2)
.S PIECE=$S(DOW'=0&(DOW'=6)&('$G(^HOLIDAY(DATE,0))):1,1:2)
.;
.F S NODE=$O(^KMPTMP("KMPR","HOURS",DATE,NODE)) Q:NODE="" D
..S DATA=$G(^KMPTMP("KMPR","HOURS",DATE,NODE)) Q:DATA=""
..S (HOURS,HRS)=0
..;
..;*** times are offset by 1 so zero hour is in piece 1
..;*** one hour is in piece 2
..;*** two hour is in piece 3
..;*** etc.
..;
..; prime time hours
..F I=9:1:17 S HRS=HRS+$P(DATA,U,I)
..S $P(HOURS,U,PIECE)=$P(HOURS,U,PIECE)+HRS
..;
..; non-prime time hours
..S HRS=0
..F I=1:1:8,18:1:24 S HRS=HRS+$P(DATA,U,I)
..S $P(HOURS,U,2)=$P(HOURS,U,2)+HRS
..;
..; workday, non-workday hours
..S HRS=0
..F I=1:1:24 S HRS=HRS+$P(DATA,U,I)
..I WORKDAY S $P(HOURS,U,3)=$P(HOURS,U,3)+HRS
..E S $P(HOURS,U,4)=$P(HOURS,U,4)+HRS
..;
..S KMPRRES(NODE,DATE)=HOURS
..;
..K:KMPRKILL ^KMPTMP("KMPR","HOURS",DATE,NODE)
;
Q
;
PURGE(KMPRDDT,KMPRHRS) ;-- purge data in file #8971.1
;-----------------------------------------------------------------------
; KMPRDDT.. Date to begin purge in internal fileman format. Purge will
; reverse $order and delete entries 'EARLIER' than KMPRDDT.
; KMPRHRS.. Purge Hours/Days data from ^KMPTMP("KMPR","HOURS". Entries
; 'EARLIER' than KMPRDDT will be deleted.
; 0 - do not purge hours/days data.
; 1 - purge hours/days data.
;-----------------------------------------------------------------------
;
Q:'$G(KMPRDDT)
S KMPRHRS=+$G(KMPRHRS)
;
N DA,DATE,DIK,IEN
D:'$D(ZTQUEUED) EN^DDIOL("Deleting old records...")
S DATE=KMPRDDT
F S DATE=$O(^KMPR(8971.1,"B",DATE),-1) Q:'DATE!(DATE>KMPRDDT) D
.F IEN=0:0 S IEN=$O(^KMPR(8971.1,"B",DATE,IEN)) Q:'IEN D
..; delete if no zero node
..I '$D(^KMPR(8971.1,IEN,0)) K ^KMPR(8971.1,"B",DATE,IEN) Q
..; quit if not 'sent to cm database'.
..Q:$P($G(^KMPR(8971.1,IEN,0)),U,2)=0
..; Delete entry.
..S DA=IEN,DIK="^KMPR(8971.1," D ^DIK
;
Q:'KMPRHRS
D:'$D(ZTQUEUED) EN^DDIOL("Deleting old entries from ^KMPTMP(""KMPR"",""HOURS""...")
S DATE=KMPRDDT
F S DATE=$O(^KMPTMP("KMPR","HOURS",DATE),-1) Q:'DATE!(DATE>KMPRDDT) D
.K ^KMPTMP("KMPR","HOURS",DATE)
;
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HKMPRUTL3 6372 printed Oct 16, 2024@17:42:39 Page 2
KMPRUTL3 ;OAK/RAK - Resource Usage Monitor Utilities ;5/28/03 09:16
+1 ;;2.0;CAPACITY MANAGEMENT - RUM;;May 28, 2003
+2 ;
HRSDAYS(KMPRSDT,KMPREDT,KMPRKILL,KMPRRES) ;
+1 ;-- number of days/hours in the date range
+2 ;-----------------------------------------------------------------------
+3 ; KMPRSDT.. Start Date in internal fileman format
+4 ; KMPREDT.. End Date in internal fileman format
+5 ; KMPRKILL. Kill node after processing:
+6 ; 0 - do not kill
+7 ; 1 - kill
+8 ; KMPRRES.. Array (passed by reference) containing days/hours info
+9 ; in format: KMPRRES(KMPRSDT,Node)=Data
+10 ; Where Data equals for the specified date range:
+11 ; '^' Piece 1 - Prime Time Days
+12 ; '^' Piece 2 - Prime Time Hours
+13 ; '^' Piece 3 - Non-Prime Time Days
+14 ; '^' Piece 4 - Non-Prime Time Hours
+15 ; '^' Piece 5 - Workday Days
+16 ; '^' Piece 6 - Workday Hours
+17 ; '^' Piece 7 - Non-Workday Days
+18 ; '^' Piece 8 - Non-Workday Hours
+19 ; Example for the specified date range:
+20 ; KMPRRES(3030418,"999A01")=5^45^7^123^5^120^2^48
+21 ; KMPRRES(3030418,"999A02")=5^40^7^120^5^110^2^45 <=partial
+22 ; KMPRRES(3030418,"999A03")=5^45^7^123^5^120^2^48
+23 ; KMPRRES( ... , ... )=...
+24 ;-----------------------------------------------------------------------
+25 ;
+26 KILL KMPRRES
+27 ;
+28 if '$GET(KMPRSDT)
QUIT
+29 if '$GET(KMPREDT)
QUIT
+30 SET KMPRKILL=+$GET(KMPRKILL)
+31 ;
+32 NEW DATA,DATE,DAYS,HOURS,I,NODE
+33 ;
+34 DO HOURS(KMPRSDT,KMPREDT,KMPRKILL,.HOURS)
+35 if '$DATA(HOURS)
QUIT
+36 ;
+37 SET NODE=""
+38 FOR
SET NODE=$ORDER(HOURS(NODE))
if NODE=""
QUIT
Begin DoDot:1
+39 SET (DATE,DAYS,HOURS)=0
+40 FOR
SET DATE=$ORDER(HOURS(NODE,DATE))
if 'DATE
QUIT
Begin DoDot:2
+41 ;
+42 ; piece 1 - prime time hours per day
+43 ; piece 2 - non-prime time hours per day
+44 ; piece 3 - workday hours per day
+45 ; piece 4 - non-workday hours per day
+46 SET DATA=HOURS(NODE,DATE)
+47 ;
+48 FOR I=1:1:4
Begin DoDot:3
+49 ; total hours for the specified date range
+50 SET $PIECE(HOURS,U,I)=$PIECE(HOURS,U,I)+$PIECE(DATA,U,I)
+51 ; if current day has hours then increment total days for the
+52 ; specified date range
+53 if $PIECE(DATA,U,I)
SET $PIECE(DAYS,U,I)=$PIECE(DAYS,U,I)+1
End DoDot:3
End DoDot:2
+54 ;
+55 ; back to NODE level
+56 SET KMPRRES(KMPRSDT,NODE)=$PIECE(DAYS,U)_"^"_$PIECE(HOURS,U)_"^"_$PIECE(DAYS,U,2)_"^"_$PIECE(HOURS,U,2)_"^"_$PIECE(DAYS,U,3)_"^"_$PIECE(HOURS,U,3)_"^"_$PIECE(DAYS,U,4)_"^"_$PIECE(HOURS,U,4)
End DoDot:1
+57 ;
+58 QUIT
+59 ;
HOURS(KMPRSDT,KMPREDT,KMPRKILL,KMPRRES) ;
+1 ;-- determine prime time & non-prime time hours per day
+2 ;-- determine workday & non-workday hours per day
+3 ;-----------------------------------------------------------------------
+4 ; KMPRSDT.. Start Date in internal fileman format
+5 ; KMPREDT.. End Date in internal fileman format
+6 ; KMPRKILL. Kill node after processing:
+7 ; 0 - do not kill
+8 ; 1 - kill
+9 ; KMPRRES.. Array (passed by reference) containing hours info
+10 ; in format: KMPRRES(Date,Node)=Data
+11 ; Where Data equals:
+12 ; '^' Piece 1 - Prime Time Hours per day
+13 ; '^' Piece 2 - Non-Prime Time Hours per day
+14 ; '^' Piece 3 - Workday Hours per day
+15 ; '^' Piece 4 - Non-Workday Hours per day
+16 ; Example:
+17 ; KMPRRES(3030418,"999A01")=9^15^24^0 <= Friday
+18 ; KMPRRES(3030418,"999A02")=4^10^14^0 <= Friday (partial)
+19 ; KMPRRES(3030419,"999A01")=0^24^0^24 <= Saturday
+20 ; KMPRRES( ... , ... )= ...
+21 ;-----------------------------------------------------------------------
+22 ;
+23 KILL KMPRRES
+24 ;
+25 if '$GET(KMPRSDT)
QUIT
+26 if '$GET(KMPREDT)
QUIT
+27 SET KMPRKILL=+$GET(KMPRKILL)
+28 ;
+29 NEW DATA,DATE,DOW,END,HOURS,HRS,I,NODE,PIECE,WORKDAY
+30 ;
+31 ; end date
+32 SET END=KMPREDT
+33 SET DATE=KMPRSDT-.1
SET (DAYS,HOURS)=""
+34 FOR
SET DATE=$ORDER(^KMPTMP("KMPR","HOURS",DATE))
if 'DATE!(DATE>END)
QUIT
Begin DoDot:1
+35 ;
+36 if DATE<KMPRSDT!(DATE>END)
QUIT
+37 ;
+38 SET NODE=""
SET DOW=$$DOW^XLFDT(DATE,1)
SET WORKDAY=$$WORKDAY^XUWORKDY(DATE)
+39 ;
+40 ; prime time (8am to 5pm)
+41 ; if not saturday or sunday or holiday then prime time (piece 1)
+42 ; if saturday or sunday then non-prime time (piece 2)
+43 SET PIECE=$SELECT(DOW'=0&(DOW'=6)&('$GET(^HOLIDAY(DATE,0))):1,1:2)
+44 ;
+45 FOR
SET NODE=$ORDER(^KMPTMP("KMPR","HOURS",DATE,NODE))
if NODE=""
QUIT
Begin DoDot:2
+46 SET DATA=$GET(^KMPTMP("KMPR","HOURS",DATE,NODE))
if DATA=""
QUIT
+47 SET (HOURS,HRS)=0
+48 ;
+49 ;*** times are offset by 1 so zero hour is in piece 1
+50 ;*** one hour is in piece 2
+51 ;*** two hour is in piece 3
+52 ;*** etc.
+53 ;
+54 ; prime time hours
+55 FOR I=9:1:17
SET HRS=HRS+$PIECE(DATA,U,I)
+56 SET $PIECE(HOURS,U,PIECE)=$PIECE(HOURS,U,PIECE)+HRS
+57 ;
+58 ; non-prime time hours
+59 SET HRS=0
+60 FOR I=1:1:8,18:1:24
SET HRS=HRS+$PIECE(DATA,U,I)
+61 SET $PIECE(HOURS,U,2)=$PIECE(HOURS,U,2)+HRS
+62 ;
+63 ; workday, non-workday hours
+64 SET HRS=0
+65 FOR I=1:1:24
SET HRS=HRS+$PIECE(DATA,U,I)
+66 IF WORKDAY
SET $PIECE(HOURS,U,3)=$PIECE(HOURS,U,3)+HRS
+67 IF '$TEST
SET $PIECE(HOURS,U,4)=$PIECE(HOURS,U,4)+HRS
+68 ;
+69 SET KMPRRES(NODE,DATE)=HOURS
+70 ;
+71 if KMPRKILL
KILL ^KMPTMP("KMPR","HOURS",DATE,NODE)
End DoDot:2
End DoDot:1
+72 ;
+73 QUIT
+74 ;
PURGE(KMPRDDT,KMPRHRS) ;-- purge data in file #8971.1
+1 ;-----------------------------------------------------------------------
+2 ; KMPRDDT.. Date to begin purge in internal fileman format. Purge will
+3 ; reverse $order and delete entries 'EARLIER' than KMPRDDT.
+4 ; KMPRHRS.. Purge Hours/Days data from ^KMPTMP("KMPR","HOURS". Entries
+5 ; 'EARLIER' than KMPRDDT will be deleted.
+6 ; 0 - do not purge hours/days data.
+7 ; 1 - purge hours/days data.
+8 ;-----------------------------------------------------------------------
+9 ;
+10 if '$GET(KMPRDDT)
QUIT
+11 SET KMPRHRS=+$GET(KMPRHRS)
+12 ;
+13 NEW DA,DATE,DIK,IEN
+14 if '$DATA(ZTQUEUED)
DO EN^DDIOL("Deleting old records...")
+15 SET DATE=KMPRDDT
+16 FOR
SET DATE=$ORDER(^KMPR(8971.1,"B",DATE),-1)
if 'DATE!(DATE>KMPRDDT)
QUIT
Begin DoDot:1
+17 FOR IEN=0:0
SET IEN=$ORDER(^KMPR(8971.1,"B",DATE,IEN))
if 'IEN
QUIT
Begin DoDot:2
+18 ; delete if no zero node
+19 IF '$DATA(^KMPR(8971.1,IEN,0))
KILL ^KMPR(8971.1,"B",DATE,IEN)
QUIT
+20 ; quit if not 'sent to cm database'.
+21 if $PIECE($GET(^KMPR(8971.1,IEN,0)),U,2)=0
QUIT
+22 ; Delete entry.
+23 SET DA=IEN
SET DIK="^KMPR(8971.1,"
DO ^DIK
End DoDot:2
End DoDot:1
+24 ;
+25 if 'KMPRHRS
QUIT
+26 if '$DATA(ZTQUEUED)
DO EN^DDIOL("Deleting old entries from ^KMPTMP(""KMPR"",""HOURS""...")
+27 SET DATE=KMPRDDT
+28 FOR
SET DATE=$ORDER(^KMPTMP("KMPR","HOURS",DATE),-1)
if 'DATE!(DATE>KMPRDDT)
QUIT
Begin DoDot:1
+29 KILL ^KMPTMP("KMPR","HOURS",DATE)
End DoDot:1
+30 ;
+31 QUIT