-
Notifications
You must be signed in to change notification settings - Fork 0
/
TariffValidity.m
263 lines (178 loc) · 15 KB
/
TariffValidity.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
function [TariffOK,Msg]=TariffValidity(MyTariff)
% for cheking all user input data if they are correct
TariffOK=1;
PossibleHour=[0:24];
PossibleMin=[0 30];
Msg='';
try
if MyTariff.Parameters.Daily.Value<0
Msg='Daily Charge cannot be negetive! Please try again!';
TariffOK=0;
end
end
try
if MyTariff.Parameters.Energy.Value<0
Msg='Energy Charge cannot be negetive! Please try again!';
TariffOK=0;
end
end
switch MyTariff.Type
case 'Flat Rate'
if MyTariff.Parameters.Other.Value<0
TariffOK=0;
Msg='$/kWh should be positive!';
end
case 'Flat Rate Seasonal'
for i=1:size(MyTariff.Parameters.Other,1)
if MyTariff.Parameters.Other.Rate(i)<0
TariffOK=0;
Msg='$/kWh should be positive!';
break
end
end
case 'Block Quarterly'
if numel(find(sign(diff(MyTariff.Parameters.Other.HighBound(:,1)))<=0))>0 ||numel(find(MyTariff.Parameters.Other.HighBound(:,1)<=0))>0
TariffOK=0;
Msg='Block usage bounds should be Postive and incremental';
%
elseif MyTariff.Parameters.Other.HighBound(end,1)~=inf
TariffOK=0;
Msg='Last block usage bound should be Inf';
elseif numel(find(MyTariff.Parameters.Other.Value(:,1)<0))>0
TariffOK=0;
Msg='The values should be positive';
end
case 'Block Annual'
if numel(find(sign(diff(MyTariff.Parameters.Other.HighBound(:,1)))<=0))>0 ||numel(find(MyTariff.Parameters.Other.HighBound(:,1)<=0))>0
TariffOK=0;
Msg='Block usage bounds should be positive and incremental';
%
elseif MyTariff.Parameters.Other.HighBound(end,1)~=inf
TariffOK=0;
Msg='Last block usage bound should be Inf';
elseif numel(find(MyTariff.Parameters.Other.Value(:,1)<0))>0
TariffOK=0;
Msg='The values should be positive';
end
case 'TOU'
MockTime=[datetime(2013,1,1,0,30,0):minutes(30):datetime(2014,1,1,0,0,0)]';
TimeIndex=zeros(size(MockTime));
DayNumber=weekday(TimeIndex);
for T=1:size(MyTariff.Parameters.Other,1)
if MyTariff.Parameters.Other.Weekday(T,1)==1
TimeIndex(DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex(DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
end
if MyTariff.Parameters.Other.Weekend(T,1)==1
TimeIndex((DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
end
end
if numel(find(TimeIndex>1))>0
TariffOK=0;
Msg='You have covered some time stamps in multiple lines! Please correct the tariffs!';
end
for T=1:size(MyTariff.Parameters.Other,1)
WWF(T,1)=MyTariff.Parameters.Other.Weekend(T,1)+MyTariff.Parameters.Other.Weekday(T,1);
end
if numel(find(WWF==0))>0
TariffOK=0;
Msg='In at least one line you did not select weekend or weekday!';
end
for T=1:size(MyTariff.Parameters.Other,1)
WWF(T,1)=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))-(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1));
end
if numel(find(WWF>0))>0
TariffOK=0;
Msg='Start time should be before end time!';
end
if (numel(find(ismember(MyTariff.Parameters.Other{:,[4,6]},PossibleHour)<1))>0)...
||(numel(find(ismember(MyTariff.Parameters.Other{:,[5,7]},PossibleMin)<1))>0)...
TariffOK=0;
Msg='There is a problem in entering the hour or minute value';
end
case 'TOU Seasonal'
MockTime=[datetime(2013,1,1,0,30,0):minutes(30):datetime(2014,1,1,0,0,0)]';
TimeIndex=zeros(size(MockTime,1),1);
DayNumber=weekday(TimeIndex);
for T=1:size(MyTariff.Parameters.Other,1)
if MyTariff.Parameters.Other.Weekday(T,1)==1
if MyTariff.Parameters.Other.StartMonth(T,1)>MyTariff.Parameters.Other.EndMonth(T,1)
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
else
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
end
end
if MyTariff.Parameters.Other.Weekend(T,1)==1
if MyTariff.Parameters.Other.StartMonth(T,1)>MyTariff.Parameters.Other.EndMonth(T,1)
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
else
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
end
end
end
if numel(find(TimeIndex>1))>0
TariffOK=0;
Msg='You have covered some time stamps in multiple lines! Please correct the tariffs!';
end
for T=1:size(MyTariff.Parameters.Other,1)
WWF(T,1)=MyTariff.Parameters.Other.Weekend(T,1)+MyTariff.Parameters.Other.Weekday(T,1);
end
if numel(find(WWF==0))>0
TariffOK=0;
Msg='In at least one line you did not select weekend or weekday!';
end
for T=1:size(MyTariff.Parameters.Other,1)
WWF(T,1)=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))-(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1));
end
if numel(find(WWF>0))>0
TariffOK=0;
Msg='Start time should be before end time!';
end
if (numel(find(ismember(MyTariff.Parameters.Other{:,[4,6]},PossibleHour)<1))>0)...
||(numel(find(ismember(MyTariff.Parameters.Other{:,[5,7]},PossibleMin)<1))>0)...
TariffOK=0;
Msg='There is a problem in entering the hour or minute value';
end
case 'Demand Charge'
MockTime=[datetime(2013,1,1,0,30,0):minutes(30):datetime(2014,1,1,0,0,0)]';
TimeIndex=zeros(size(MockTime,1),1);
% IndexMonth=zeros(1,12);
DayNumber=weekday(TimeIndex);
for T=1:size(MyTariff.Parameters.Other,1)
if MyTariff.Parameters.Other.Weekday(T,1)==1
if MyTariff.Parameters.Other.StartMonth(T,1)>MyTariff.Parameters.Other.EndMonth(T,1)
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
else
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&DayNumber>1&DayNumber<7&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
end
end
if MyTariff.Parameters.Other.Weekend(T,1)==1
if MyTariff.Parameters.Other.StartMonth(T,1)>MyTariff.Parameters.Other.EndMonth(T,1)
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)|MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
else
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)=...
TimeIndex((MockTime.Month>=MyTariff.Parameters.Other.StartMonth(T,1)&MockTime.Month<=MyTariff.Parameters.Other.EndMonth(T,1))&(DayNumber==1|DayNumber==7)&(60*MockTime.Hour+MockTime.Minute)>=(60*MyTariff.Parameters.Other.StartHour(T,1)+MyTariff.Parameters.Other.StartMin(T,1))&(60*MockTime.Hour+MockTime.Minute)<(60*MyTariff.Parameters.Other.EndHour(T,1)+MyTariff.Parameters.Other.EndMin(T,1)),1)+1;
end
end
end
if numel(find(TimeIndex>1))>0
TariffOK=0;
Msg='You have covered some time stamps in multiple lines! Please correct the tariffs!';
end
for T=1:size(MyTariff.Parameters.Other,1)
WWF(T,1)=MyTariff.Parameters.Other.Weekend(T,1)+MyTariff.Parameters.Other.Weekday(T,1);
end
if numel(find(WWF==0))>0
TariffOK=0;
Msg='In at least one line you did not select weekend or weekday!';
end
end
end