Antares Simulator
Power System Simulator
xcast-coefficients.hxx
1 /*
2  * Copyright 2007-2025, 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 
25 namespace Antares::Component::Datagrid::Renderer
26 {
27 template<enum Data::TimeSeriesType T>
28 inline XCastCoefficients<T>::XCastCoefficients(wxWindow* control,
30  MatrixAncestorType(control),
31  Renderer::ARendererArea(control, notifier)
32 {
33 }
34 
35 template<enum Data::TimeSeriesType T>
37 {
38  destroyBoundEvents();
39 }
40 
41 template<enum Data::TimeSeriesType T>
42 wxString XCastCoefficients<T>::columnCaption(int colIndx) const
43 {
44  static const wxString captions[Data::XCast::dataMax] = {wxT(" alpha "),
45  wxT(" beta "),
46  wxT(" gamma "),
47  wxT(" delta "),
48  wxT(" theta "),
49  wxT(" mu ")};
50  return colIndx < Data::XCast::dataMax ? captions[colIndx] : wxString();
51 }
52 
53 template<enum Data::TimeSeriesType T>
54 wxString XCastCoefficients<T>::cellValue(int x, int y) const
55 {
56  return MatrixAncestorType::cellValue(x, y);
57 }
58 
59 template<enum Data::TimeSeriesType T>
60 double XCastCoefficients<T>::cellNumericValue(int x, int y) const
61 {
62  return MatrixAncestorType::cellNumericValue(x, y);
63 }
64 
65 template<enum Data::TimeSeriesType T>
66 inline bool XCastCoefficients<T>::cellValue(int x, int y, const Yuni::String& value)
67 {
68  using namespace Antares::Data;
69 
70  if (!pArea)
71  {
72  return false;
73  }
74  auto& xcast = *(pArea->xcastData<T>());
75  float v;
76  if (!value.to(v))
77  {
78  return false;
79  }
80  if ((uint)x >= xcast.data.width || (uint)y >= xcast.data.height)
81  {
82  return false;
83  }
84 
85  switch (x)
86  {
87  case XCast::dataCoeffAlpha:
88  {
89  switch (xcast.distribution)
90  {
91  case XCast::dtUniform:
92  break;
93  case XCast::dtBeta:
94  {
95  if (v <= 0.f)
96  {
97  return MatrixAncestorType::cellValue(x, y, "0");
98  }
99  break;
100  }
101  case XCast::dtNormal:
102  break;
103  default:
104  {
105  if (v < 1.f || v > 50.f)
106  {
107  return MatrixAncestorType::cellValue(x, y, "1");
108  }
109  }
110  }
111  break;
112  }
113  case XCast::dataCoeffBeta:
114  {
115  switch (xcast.distribution)
116  {
117  case XCast::dtUniform:
118  break;
119  default:
120  {
121  if (v <= 0.f)
122  {
123  return MatrixAncestorType::cellValue(x, y, "0");
124  }
125  break;
126  }
127  }
128  break;
129  }
130  case XCast::dataCoeffGamma:
131  {
132  switch (xcast.distribution)
133  {
134  case XCast::dtUniform:
135  {
136  // if (v > xcast.data.entry[XCast::dataCoeffDelta][y])
137  // return MatrixAncestorType::cellValue(x, y,
138  // String(xcast.data.entry[XCast::dataCoeffDelta][y]));
139  break;
140  }
141  case XCast::dtBeta:
142  {
143  // if (v >= xcast.data.entry[XCast::dataCoeffDelta][y])
144  // return MatrixAncestorType::cellValue(x, y, "0");
145  break;
146  }
147  case XCast::dtNormal:
148  break;
149  default:
150  break;
151  }
152  break;
153  }
154  case XCast::dataCoeffDelta:
155  {
156  switch (xcast.distribution)
157  {
158  case XCast::dtUniform:
159  {
160  // if (v < xcast.data.entry[XCast::dataCoeffGamma][y])
161  // return MatrixAncestorType::cellValue(x, y,
162  // xcast.data.entry[XCast::dataCoeffGamma][y]);
163  break;
164  }
165  case XCast::dtBeta:
166  {
167  // if (v <= xcast.data.entry[XCast::dataCoeffGamma][y])
168  // return MatrixAncestorType::cellValue(x, y, "1");
169  break;
170  }
171  default:
172  break;
173  }
174  break;
175  }
176 
177  case XCast::dataCoeffTheta:
178  {
179  if (v < 0.f)
180  {
181  return MatrixAncestorType::cellValue(x, y, "0");
182  }
183  break;
184  }
185  case XCast::dataCoeffMu:
186  {
187  if (v < 1.f)
188  {
189  return MatrixAncestorType::cellValue(x, y, "1");
190  }
191  if (v > 23.f)
192  {
193  return MatrixAncestorType::cellValue(x, y, "23");
194  }
195  break;
196  }
197  }
198  return MatrixAncestorType::cellValue(x, y, value);
199 }
200 
201 template<enum Data::TimeSeriesType T>
203 {
204  if (area)
205  {
206  Data::XCast* xcastData = area->xcastData<T>();
207  this->matrix(&(xcastData->data));
208  }
209  else
210  {
211  this->matrix(NULL);
212  }
213  Renderer::ARendererArea::internalAreaChanged(area);
214 }
215 
216 template<enum Data::TimeSeriesType T>
217 IRenderer::CellStyle XCastCoefficients<T>::cellStyle(int col, int row) const
218 {
219  // law \ coeff alpha beta gamma delta
220  //
221  // uniform ? ? R R
222  // beta >0 >0 R R
223  // normal R >0 R R
224  // weibull 1 <= x <= 50 >0 R ?
225  // gamma 1 <= x <= 50 >0 R ?
226  //
227  // R : -inf < x < +inf
228  // ? : whatever (disabled)
229  //
230  // mu : 1 <= mu <= 23
231  // if uniform || beta then gamma < delta
232  //
233  using namespace Antares::Data;
234  if (!pArea)
235  {
236  return IRenderer::cellStyleDefault;
237  }
238  XCast& xcast = *(pArea->xcastData<T>());
239  if ((uint)col >= xcast.data.width || (uint)row >= xcast.data.height)
240  {
241  return IRenderer::cellStyleDefault;
242  }
243 
244  float d = xcast.data[col][row];
245  switch (col)
246  {
247  case XCast::dataCoeffAlpha:
248  {
249  switch (xcast.distribution)
250  {
251  case XCast::dtUniform:
252  return IRenderer::cellStyleDefaultDisabled;
253  case XCast::dtBeta:
254  {
255  if (d <= 0.f)
256  {
257  return IRenderer::cellStyleError;
258  }
259  break;
260  }
261  case XCast::dtNormal:
262  break;
263  default:
264  {
265  if (d < 1.f || d > 50.f)
266  {
267  return IRenderer::cellStyleError;
268  }
269  }
270  }
271  break;
272  }
273  case XCast::dataCoeffBeta:
274  {
275  switch (xcast.distribution)
276  {
277  case XCast::dtUniform:
278  return IRenderer::cellStyleDefaultDisabled;
279  case XCast::dtNormal:
280  {
281  if (d < 0.)
282  {
283  return IRenderer::cellStyleError;
284  }
285  break;
286  }
287  default:
288  {
289  if (d <= 0.)
290  {
291  return IRenderer::cellStyleError;
292  }
293  break;
294  }
295  }
296  break;
297  }
298  case XCast::dataCoeffGamma:
299  {
300  switch (xcast.distribution)
301  {
302  case XCast::dtUniform:
303  {
304  if (d > xcast.data.entry[XCast::dataCoeffDelta][row])
305  {
306  return IRenderer::cellStyleError;
307  }
308  break;
309  }
310  case XCast::dtBeta:
311  {
312  if (d >= xcast.data.entry[XCast::dataCoeffDelta][row])
313  {
314  return IRenderer::cellStyleError;
315  }
316  break;
317  }
318  case XCast::dtNormal:
319  return IRenderer::cellStyleDefaultDisabled;
320  default:
321  break;
322  }
323  break;
324  }
325  case XCast::dataCoeffDelta:
326  {
327  switch (xcast.distribution)
328  {
329  case XCast::dtUniform:
330  {
331  if (d < xcast.data.entry[XCast::dataCoeffGamma][row])
332  {
333  return IRenderer::cellStyleError;
334  }
335  break;
336  }
337  case XCast::dtBeta:
338  {
339  if (d <= xcast.data.entry[XCast::dataCoeffGamma][row])
340  {
341  return IRenderer::cellStyleError;
342  }
343  break;
344  }
345  default:
346  return IRenderer::cellStyleDefaultDisabled;
347  }
348  break;
349  }
350  case XCast::dataCoeffTheta:
351  {
352  if (d < 0.f)
353  {
354  return IRenderer::cellStyleError;
355  }
356  break;
357  }
358  case XCast::dataCoeffMu:
359  {
360  if (d < 1.f || d > 23.f)
361  {
362  return IRenderer::cellStyleError;
363  }
364  break;
365  }
366  default:
367  break;
368  }
369  return Yuni::Math::Zero(d) ? IRenderer::cellStyleDefaultDisabled : IRenderer::cellStyleDefault;
370 }
371 
372 template<enum Data::TimeSeriesType T>
373 wxString XCastCoefficients<T>::rowCaption(int rowIndx) const
374 {
375  return ((uint)rowIndx < 12) ? wxString() << (1 + rowIndx) << wxT(" - ")
376  << wxStringFromUTF8(Date::MonthToString(rowIndx))
377  : wxString();
378 }
379 
380 template<enum Data::TimeSeriesType T>
381 inline Date::Precision XCastCoefficients<T>::precision()
382 {
383  return Date::monthly;
384 }
385 
386 template<enum Data::TimeSeriesType T>
388 {
391 }
392 
393 template<enum Data::TimeSeriesType T>
395 {
398 }
399 
400 } // namespace Antares::Component::Datagrid::Renderer
virtual void onStudyClosed() override
The study has been closed.
Definition: area.cpp:86
virtual void onStudyLoaded() override
Event: the study has been loaded.
Definition: area.cpp:92
virtual int height() const override
Get the height of the datagrid.
virtual int width() const override
Get the width of the datagrid.
virtual wxString columnCaption(int colIndx) const
Get the column caption.
Definition: xcast-coefficients.hxx:42
virtual double cellNumericValue(int x, int y) const
Get the value of a cell.
Definition: xcast-coefficients.hxx:60
virtual ~XCastCoefficients()
Destructor.
Definition: xcast-coefficients.hxx:36
XCastCoefficients(wxWindow *control, Toolbox::InputSelector::Area *notifier)
Constructor.
Definition: xcast-coefficients.hxx:28
virtual wxString rowCaption(int rowIndx) const
Get the row caption.
Definition: xcast-coefficients.hxx:373
virtual void onStudyClosed() override
Event: the study has been closed.
Definition: xcast-coefficients.hxx:387
virtual void onStudyLoaded() override
Event: the study has been loaded.
Definition: xcast-coefficients.hxx:394
virtual Date::Precision precision()
Time Precision.
Definition: xcast-coefficients.hxx:381
virtual wxString cellValue(int x, int y) const
Get the string representation of a cell.
Definition: xcast-coefficients.hxx:54
Definition for a single area.
Definition: area.h:51
Definition: xcast.h:35
Distribution distribution
The probability distribution to use.
Definition: xcast.h:182
@ dataMax
The maximum number of coefficients.
Definition: xcast.h:54
@ 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
A n-by-n matrix.
Definition: matrix.h:44
Visual Component for displaying all available areas (and groups)
Definition: area.h:37