Antares Simulator
Power System Simulator
Loading...
Searching...
No Matches
xcast-coefficients.hxx
1/*
2** Copyright 2007-2024, RTE (https://www.rte-france.com)
3** See AUTHORS.txt
4** SPDX-License-Identifier: MPL-2.0
5** This file is part of Antares-Simulator,
6** Adequacy and Performance assessment for interconnected energy networks.
7**
8** Antares_Simulator is free software: you can redistribute it and/or modify
9** it under the terms of the Mozilla Public Licence 2.0 as published by
10** the Mozilla Foundation, either version 2 of the License, or
11** (at your option) any later version.
12**
13** Antares_Simulator is distributed in the hope that it will be useful,
14** but WITHOUT ANY WARRANTY; without even the implied warranty of
15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16** Mozilla Public Licence 2.0 for more details.
17**
18** You should have received a copy of the Mozilla Public Licence 2.0
19** along with Antares_Simulator. If not, see <https://opensource.org/license/mpl-2-0/>.
20*/
21
22#include <antares/study/xcast/xcast.h>
23#include <antares/date/date.h>
24
25namespace Antares
26{
27namespace Component
28{
29namespace Datagrid
30{
31namespace Renderer
32{
33template<enum Data::TimeSeriesType T>
36 MatrixAncestorType(control), Renderer::ARendererArea(control, notifier)
37{
38}
39
40template<enum Data::TimeSeriesType T>
42{
43 destroyBoundEvents();
44}
45
46template<enum Data::TimeSeriesType T>
47wxString XCastCoefficients<T>::columnCaption(int colIndx) const
48{
49 static const wxString captions[Data::XCast::dataMax] = {wxT(" alpha "),
50 wxT(" beta "),
51 wxT(" gamma "),
52 wxT(" delta "),
53 wxT(" theta "),
54 wxT(" mu ")};
55 return colIndx < Data::XCast::dataMax ? captions[colIndx] : wxString();
56}
57
58template<enum Data::TimeSeriesType T>
59wxString XCastCoefficients<T>::cellValue(int x, int y) const
60{
61 return MatrixAncestorType::cellValue(x, y);
62}
63
64template<enum Data::TimeSeriesType T>
66{
67 return MatrixAncestorType::cellNumericValue(x, y);
68}
69
70template<enum Data::TimeSeriesType T>
71inline bool XCastCoefficients<T>::cellValue(int x, int y, const Yuni::String& value)
72{
73 using namespace Antares::Data;
74
75 if (!pArea)
76 return false;
77 auto& xcast = *(pArea->xcastData<T>());
78 float v;
79 if (!value.to(v))
80 return false;
81 if ((uint)x >= xcast.data.width || (uint)y >= xcast.data.height)
82 return false;
83
84 switch (x)
85 {
86 case XCast::dataCoeffAlpha:
87 {
88 switch (xcast.distribution)
89 {
91 break;
92 case XCast::dtBeta:
93 {
94 if (v <= 0.f)
95 return MatrixAncestorType::cellValue(x, y, "0");
96 break;
97 }
98 case XCast::dtNormal:
99 break;
100 default:
101 {
102 if (v < 1.f || v > 50.f)
103 return MatrixAncestorType::cellValue(x, y, "1");
104 }
105 }
106 break;
107 }
108 case XCast::dataCoeffBeta:
109 {
110 switch (xcast.distribution)
111 {
112 case XCast::dtUniform:
113 break;
114 default:
115 {
116 if (v <= 0.f)
117 return MatrixAncestorType::cellValue(x, y, "0");
118 break;
119 }
120 }
121 break;
122 }
123 case XCast::dataCoeffGamma:
124 {
125 switch (xcast.distribution)
126 {
127 case XCast::dtUniform:
128 {
129 // if (v > xcast.data.entry[XCast::dataCoeffDelta][y])
130 // return MatrixAncestorType::cellValue(x, y,
131 // String(xcast.data.entry[XCast::dataCoeffDelta][y]));
132 break;
133 }
134 case XCast::dtBeta:
135 {
136 // if (v >= xcast.data.entry[XCast::dataCoeffDelta][y])
137 // return MatrixAncestorType::cellValue(x, y, "0");
138 break;
139 }
140 case XCast::dtNormal:
141 break;
142 default:
143 break;
144 }
145 break;
146 }
147 case XCast::dataCoeffDelta:
148 {
149 switch (xcast.distribution)
150 {
151 case XCast::dtUniform:
152 {
153 // if (v < xcast.data.entry[XCast::dataCoeffGamma][y])
154 // return MatrixAncestorType::cellValue(x, y,
155 // xcast.data.entry[XCast::dataCoeffGamma][y]);
156 break;
157 }
158 case XCast::dtBeta:
159 {
160 // if (v <= xcast.data.entry[XCast::dataCoeffGamma][y])
161 // return MatrixAncestorType::cellValue(x, y, "1");
162 break;
163 }
164 default:
165 break;
166 }
167 break;
168 }
169
170 case XCast::dataCoeffTheta:
171 {
172 if (v < 0.f)
173 return MatrixAncestorType::cellValue(x, y, "0");
174 break;
175 }
176 case XCast::dataCoeffMu:
177 {
178 if (v < 1.f)
179 return MatrixAncestorType::cellValue(x, y, "1");
180 if (v > 23.f)
181 return MatrixAncestorType::cellValue(x, y, "23");
182 break;
183 }
184 }
185 return MatrixAncestorType::cellValue(x, y, value);
186}
187
188template<enum Data::TimeSeriesType T>
190{
191 if (area)
192 {
193 Data::XCast* xcastData = area->xcastData<T>();
194 this->matrix(&(xcastData->data));
195 }
196 else
197 this->matrix(NULL);
198 Renderer::ARendererArea::internalAreaChanged(area);
199}
200
201template<enum Data::TimeSeriesType T>
202IRenderer::CellStyle XCastCoefficients<T>::cellStyle(int col, int row) const
203{
204 // law \ coeff alpha beta gamma delta
205 //
206 // uniform ? ? R R
207 // beta >0 >0 R R
208 // normal R >0 R R
209 // weibull 1 <= x <= 50 >0 R ?
210 // gamma 1 <= x <= 50 >0 R ?
211 //
212 // R : -inf < x < +inf
213 // ? : whatever (disabled)
214 //
215 // mu : 1 <= mu <= 23
216 // if uniform || beta then gamma < delta
217 //
218 using namespace Antares::Data;
219 if (!pArea)
220 return IRenderer::cellStyleDefault;
221 XCast& xcast = *(pArea->xcastData<T>());
222 if ((uint)col >= xcast.data.width || (uint)row >= xcast.data.height)
223 return IRenderer::cellStyleDefault;
224
225 float d = xcast.data[col][row];
226 switch (col)
227 {
228 case XCast::dataCoeffAlpha:
229 {
230 switch (xcast.distribution)
231 {
232 case XCast::dtUniform:
233 return IRenderer::cellStyleDefaultDisabled;
234 case XCast::dtBeta:
235 {
236 if (d <= 0.f)
237 return IRenderer::cellStyleError;
238 break;
239 }
240 case XCast::dtNormal:
241 break;
242 default:
243 {
244 if (d < 1.f || d > 50.f)
245 return IRenderer::cellStyleError;
246 }
247 }
248 break;
249 }
250 case XCast::dataCoeffBeta:
251 {
252 switch (xcast.distribution)
253 {
254 case XCast::dtUniform:
255 return IRenderer::cellStyleDefaultDisabled;
256 case XCast::dtNormal:
257 {
258 if (d < 0.)
259 return IRenderer::cellStyleError;
260 break;
261 }
262 default:
263 {
264 if (d <= 0.)
265 return IRenderer::cellStyleError;
266 break;
267 }
268 }
269 break;
270 }
271 case XCast::dataCoeffGamma:
272 {
273 switch (xcast.distribution)
274 {
275 case XCast::dtUniform:
276 {
277 if (d > xcast.data.entry[XCast::dataCoeffDelta][row])
278 return IRenderer::cellStyleError;
279 break;
280 }
281 case XCast::dtBeta:
282 {
283 if (d >= xcast.data.entry[XCast::dataCoeffDelta][row])
284 return IRenderer::cellStyleError;
285 break;
286 }
287 case XCast::dtNormal:
288 return IRenderer::cellStyleDefaultDisabled;
289 default:
290 break;
291 }
292 break;
293 }
294 case XCast::dataCoeffDelta:
295 {
296 switch (xcast.distribution)
297 {
298 case XCast::dtUniform:
299 {
300 if (d < xcast.data.entry[XCast::dataCoeffGamma][row])
301 return IRenderer::cellStyleError;
302 break;
303 }
304 case XCast::dtBeta:
305 {
306 if (d <= xcast.data.entry[XCast::dataCoeffGamma][row])
307 return IRenderer::cellStyleError;
308 break;
309 }
310 default:
311 return IRenderer::cellStyleDefaultDisabled;
312 }
313 break;
314 }
315 case XCast::dataCoeffTheta:
316 {
317 if (d < 0.f)
318 return IRenderer::cellStyleError;
319 break;
320 }
321 case XCast::dataCoeffMu:
322 {
323 if (d < 1.f || d > 23.f)
324 return IRenderer::cellStyleError;
325 break;
326 }
327 default:
328 break;
329 }
330 return Yuni::Math::Zero(d) ? IRenderer::cellStyleDefaultDisabled : IRenderer::cellStyleDefault;
331}
332
333template<enum Data::TimeSeriesType T>
334wxString XCastCoefficients<T>::rowCaption(int rowIndx) const
335{
336 return ((uint)rowIndx < 12) ? wxString() << (1 + rowIndx) << wxT(" - ")
337 << wxStringFromUTF8(Date::MonthToString(rowIndx))
338 : wxString();
339}
340
341template<enum Data::TimeSeriesType T>
342inline Date::Precision XCastCoefficients<T>::precision()
343{
344 return Date::monthly;
345}
346
347template<enum Data::TimeSeriesType T>
353
354template<enum Data::TimeSeriesType T>
360
361} // namespace Renderer
362} // namespace Datagrid
363} // namespace Component
364} // namespace Antares
virtual void onStudyClosed() override
The study has been closed.
Definition area.cpp:83
virtual void onStudyLoaded() override
Event: the study has been loaded.
Definition area.cpp:89
virtual int width() const override
Get the width of the datagrid.
Definition matrix.hxx:63
virtual void onStudyLoaded() override
Event: the study has been loaded.
Definition matrix.hxx:244
virtual void onStudyClosed() override
Event: the study has been closed.
Definition matrix.hxx:238
virtual int height() const override
Get the height of the datagrid.
Definition matrix.hxx:69
virtual wxString columnCaption(int colIndx) const
Get the column caption.
Definition xcast-coefficients.hxx:47
virtual double cellNumericValue(int x, int y) const
Get the value of a cell.
Definition xcast-coefficients.hxx:65
virtual ~XCastCoefficients()
Destructor.
Definition xcast-coefficients.hxx:41
XCastCoefficients(wxWindow *control, Toolbox::InputSelector::Area *notifier)
Constructor.
Definition xcast-coefficients.hxx:34
virtual wxString rowCaption(int rowIndx) const
Get the row caption.
Definition xcast-coefficients.hxx:334
virtual void onStudyClosed() override
Event: the study has been closed.
Definition xcast-coefficients.hxx:348
virtual void onStudyLoaded() override
Event: the study has been loaded.
Definition xcast-coefficients.hxx:355
virtual Date::Precision precision()
Time Precision.
Definition xcast-coefficients.hxx:342
virtual wxString cellValue(int x, int y) const
Get the value of a cell.
Definition xcast-coefficients.hxx:59
Definition for a single area.
Definition area.h:52
Definition xcast.h:35
Distribution distribution
The probability distribution to use.
Definition xcast.h:182
@ dtNormal
The normal distribution.
Definition xcast.h:69
@ dtBeta
The Beta distribution.
Definition xcast.h:67
@ dtUniform
The uniform distribution.
Definition xcast.h:65
Matrix< float > data
Data required for XCast: coefficients (coeffMax x 12)
Definition xcast.h:166
@ dataMax
The maximum number of coefficients.
Definition xcast.h:54
Visual Component for displaying all available areas (and groups)
Definition area.h:41