source: WorldVistAEHR/trunk/r/CAPACITY_MANAGEMENT_RUM-KMPR/KMPRUTL3.m@ 701

Last change on this file since 701 was 613, checked in by George Lilly, 15 years ago

initial load of WorldVistAEHR

File size: 6.1 KB
Line 
1KMPRUTL3 ;OAK/RAK - Resource Usage Monitor Utilities ;5/28/03 09:16
2 ;;2.0;CAPACITY MANAGEMENT - RUM;;May 28, 2003
3 ;
4HRSDAYS(KMPRSDT,KMPREDT,KMPRKILL,KMPRRES) ;
5 ;-- number of days/hours in the date range
6 ;-----------------------------------------------------------------------
7 ; KMPRSDT.. Start Date in internal fileman format
8 ; KMPREDT.. End Date in internal fileman format
9 ; KMPRKILL. Kill node after processing:
10 ; 0 - do not kill
11 ; 1 - kill
12 ; KMPRRES.. Array (passed by reference) containing days/hours info
13 ; in format: KMPRRES(KMPRSDT,Node)=Data
14 ; Where Data equals for the specified date range:
15 ; '^' Piece 1 - Prime Time Days
16 ; '^' Piece 2 - Prime Time Hours
17 ; '^' Piece 3 - Non-Prime Time Days
18 ; '^' Piece 4 - Non-Prime Time Hours
19 ; '^' Piece 5 - Workday Days
20 ; '^' Piece 6 - Workday Hours
21 ; '^' Piece 7 - Non-Workday Days
22 ; '^' Piece 8 - Non-Workday Hours
23 ; Example for the specified date range:
24 ; KMPRRES(3030418,"999A01")=5^45^7^123^5^120^2^48
25 ; KMPRRES(3030418,"999A02")=5^40^7^120^5^110^2^45 <=partial
26 ; KMPRRES(3030418,"999A03")=5^45^7^123^5^120^2^48
27 ; KMPRRES( ... , ... )=...
28 ;-----------------------------------------------------------------------
29 ;
30 K KMPRRES
31 ;
32 Q:'$G(KMPRSDT)
33 Q:'$G(KMPREDT)
34 S KMPRKILL=+$G(KMPRKILL)
35 ;
36 N DATA,DATE,DAYS,HOURS,I,NODE
37 ;
38 D HOURS(KMPRSDT,KMPREDT,KMPRKILL,.HOURS)
39 Q:'$D(HOURS)
40 ;
41 S NODE=""
42 F S NODE=$O(HOURS(NODE)) Q:NODE="" D
43 .S (DATE,DAYS,HOURS)=0
44 .F S DATE=$O(HOURS(NODE,DATE)) Q:'DATE D
45 ..;
46 ..; piece 1 - prime time hours per day
47 ..; piece 2 - non-prime time hours per day
48 ..; piece 3 - workday hours per day
49 ..; piece 4 - non-workday hours per day
50 ..S DATA=HOURS(NODE,DATE)
51 ..;
52 ..F I=1:1:4 D
53 ...; total hours for the specified date range
54 ...S $P(HOURS,U,I)=$P(HOURS,U,I)+$P(DATA,U,I)
55 ...; if current day has hours then increment total days for the
56 ...; specified date range
57 ...S:$P(DATA,U,I) $P(DAYS,U,I)=$P(DAYS,U,I)+1
58 .;
59 .; back to NODE level
60 .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)
61 ;
62 Q
63 ;
64HOURS(KMPRSDT,KMPREDT,KMPRKILL,KMPRRES) ;
65 ;-- determine prime time & non-prime time hours per day
66 ;-- determine workday & non-workday hours per day
67 ;-----------------------------------------------------------------------
68 ; KMPRSDT.. Start Date in internal fileman format
69 ; KMPREDT.. End Date in internal fileman format
70 ; KMPRKILL. Kill node after processing:
71 ; 0 - do not kill
72 ; 1 - kill
73 ; KMPRRES.. Array (passed by reference) containing hours info
74 ; in format: KMPRRES(Date,Node)=Data
75 ; Where Data equals:
76 ; '^' Piece 1 - Prime Time Hours per day
77 ; '^' Piece 2 - Non-Prime Time Hours per day
78 ; '^' Piece 3 - Workday Hours per day
79 ; '^' Piece 4 - Non-Workday Hours per day
80 ; Example:
81 ; KMPRRES(3030418,"999A01")=9^15^24^0 <= Friday
82 ; KMPRRES(3030418,"999A02")=4^10^14^0 <= Friday (partial)
83 ; KMPRRES(3030419,"999A01")=0^24^0^24 <= Saturday
84 ; KMPRRES( ... , ... )= ...
85 ;-----------------------------------------------------------------------
86 ;
87 K KMPRRES
88 ;
89 Q:'$G(KMPRSDT)
90 Q:'$G(KMPREDT)
91 S KMPRKILL=+$G(KMPRKILL)
92 ;
93 N DATA,DATE,DOW,END,HOURS,HRS,I,NODE,PIECE,WORKDAY
94 ;
95 ; end date
96 S END=KMPREDT
97 S DATE=KMPRSDT-.1,(DAYS,HOURS)=""
98 F S DATE=$O(^KMPTMP("KMPR","HOURS",DATE)) Q:'DATE!(DATE>END) D
99 .;
100 .Q:DATE<KMPRSDT!(DATE>END)
101 .;
102 .S NODE="",DOW=$$DOW^XLFDT(DATE,1),WORKDAY=$$WORKDAY^XUWORKDY(DATE)
103 .;
104 .; prime time (8am to 5pm)
105 .; if not saturday or sunday or holiday then prime time (piece 1)
106 .; if saturday or sunday then non-prime time (piece 2)
107 .S PIECE=$S(DOW'=0&(DOW'=6)&('$G(^HOLIDAY(DATE,0))):1,1:2)
108 .;
109 .F S NODE=$O(^KMPTMP("KMPR","HOURS",DATE,NODE)) Q:NODE="" D
110 ..S DATA=$G(^KMPTMP("KMPR","HOURS",DATE,NODE)) Q:DATA=""
111 ..S (HOURS,HRS)=0
112 ..;
113 ..;*** times are offset by 1 so zero hour is in piece 1
114 ..;*** one hour is in piece 2
115 ..;*** two hour is in piece 3
116 ..;*** etc.
117 ..;
118 ..; prime time hours
119 ..F I=9:1:17 S HRS=HRS+$P(DATA,U,I)
120 ..S $P(HOURS,U,PIECE)=$P(HOURS,U,PIECE)+HRS
121 ..;
122 ..; non-prime time hours
123 ..S HRS=0
124 ..F I=1:1:8,18:1:24 S HRS=HRS+$P(DATA,U,I)
125 ..S $P(HOURS,U,2)=$P(HOURS,U,2)+HRS
126 ..;
127 ..; workday, non-workday hours
128 ..S HRS=0
129 ..F I=1:1:24 S HRS=HRS+$P(DATA,U,I)
130 ..I WORKDAY S $P(HOURS,U,3)=$P(HOURS,U,3)+HRS
131 ..E S $P(HOURS,U,4)=$P(HOURS,U,4)+HRS
132 ..;
133 ..S KMPRRES(NODE,DATE)=HOURS
134 ..;
135 ..K:KMPRKILL ^KMPTMP("KMPR","HOURS",DATE,NODE)
136 ;
137 Q
138 ;
139PURGE(KMPRDDT,KMPRHRS) ;-- purge data in file #8971.1
140 ;-----------------------------------------------------------------------
141 ; KMPRDDT.. Date to begin purge in internal fileman format. Purge will
142 ; reverse $order and delete entries 'EARLIER' than KMPRDDT.
143 ; KMPRHRS.. Purge Hours/Days data from ^KMPTMP("KMPR","HOURS". Entries
144 ; 'EARLIER' than KMPRDDT will be deleted.
145 ; 0 - do not purge hours/days data.
146 ; 1 - purge hours/days data.
147 ;-----------------------------------------------------------------------
148 ;
149 Q:'$G(KMPRDDT)
150 S KMPRHRS=+$G(KMPRHRS)
151 ;
152 N DA,DATE,DIK,IEN
153 D:'$D(ZTQUEUED) EN^DDIOL("Deleting old records...")
154 S DATE=KMPRDDT
155 F S DATE=$O(^KMPR(8971.1,"B",DATE),-1) Q:'DATE!(DATE>KMPRDDT) D
156 .F IEN=0:0 S IEN=$O(^KMPR(8971.1,"B",DATE,IEN)) Q:'IEN D
157 ..; delete if no zero node
158 ..I '$D(^KMPR(8971.1,IEN,0)) K ^KMPR(8971.1,"B",DATE,IEN) Q
159 ..; quit if not 'sent to cm database'.
160 ..Q:$P($G(^KMPR(8971.1,IEN,0)),U,2)=0
161 ..; Delete entry.
162 ..S DA=IEN,DIK="^KMPR(8971.1," D ^DIK
163 ;
164 Q:'KMPRHRS
165 D:'$D(ZTQUEUED) EN^DDIOL("Deleting old entries from ^KMPTMP(""KMPR"",""HOURS""...")
166 S DATE=KMPRDDT
167 F S DATE=$O(^KMPTMP("KMPR","HOURS",DATE),-1) Q:'DATE!(DATE>KMPRDDT) D
168 .K ^KMPTMP("KMPR","HOURS",DATE)
169 ;
170 Q
Note: See TracBrowser for help on using the repository browser.