Models.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using System;
  2. using System.Collections.Generic;
  3. using FMSAdmin.Helpers.Formula;
  4. namespace FMSAdmin.Models.Formula {
  5. public class FormulaData {
  6. public int SiteId { get; set; }
  7. public int FacilityTypeId { get; set; }
  8. public int FacilityCode { get; set; }
  9. public int FormulaId { get; set; }
  10. public string Formula { get; set; }
  11. public List<FormulaParameterData> Paramters { get; set; }
  12. };
  13. public class FormulaParameterData {
  14. public int SiteId { get; set; }
  15. public int FacilityTypeId { get; set; }
  16. public int FacilityCode { get; set; }
  17. public int FormulaId { get; set; }
  18. public string ParameterId { get; set; }
  19. public int ParameterFacilityCode { get; set; }
  20. public int ParameterPropertyId { get; set; }
  21. };
  22. public class CalculationResult {
  23. public DateTime DateTime { get; set; }
  24. public string ShortDateTime { get; set; }
  25. public double Value { get; set; }
  26. public double Percent { get; set; }
  27. };
  28. public class CalculationValue {
  29. public CalculationValue() {
  30. }
  31. public DateTime DateTime { get; set; }
  32. public double Value { get; set; }
  33. };
  34. public class CalculationValueBudget {
  35. public CalculationValueBudget() {
  36. }
  37. public DateTime DateTime { get; set; }
  38. public double Value { get; set; }
  39. public double Value2 { get; set; }
  40. };
  41. public class CalculationValueSType {
  42. public CalculationValueSType() {
  43. }
  44. public DateTime DateTime { get; set; }
  45. public double Value { get; set; }
  46. public int ServiceType { get; set; }
  47. };
  48. public class CalculationParameter {
  49. public MathParameterValue ParameterValue { get; set; }
  50. //public string FacilityCode { get; set; }
  51. //public int PropertyId { get; set; }
  52. public CalculationValue[] Values { get; set; }
  53. public DateTime SetValueFromIndex(int index) {
  54. var value = this.Values[index];
  55. this.ParameterValue.Value = (decimal)value.Value;
  56. return value.DateTime;
  57. }
  58. };
  59. public class CalculationLastResult {
  60. public DateTime DateTime { get; set; }
  61. public string ShortDateTime { get; set; }
  62. public double Value { get; set; }
  63. public double Percent { get; set; }
  64. public DateTime LastDateTime { get; set; }
  65. public string LastShortDateTime { get; set; }
  66. public double LastValue { get; set; }
  67. public double LastPercent { get; set; }
  68. public string DayOfWeek { get; set; }
  69. };
  70. public class ParameterBox {
  71. public DateTime DateTime { get; set; }
  72. Box[] boxes;
  73. public ParameterBox(CalculationParameter[] parameters) {
  74. this.boxes = new Box[parameters.Length];
  75. for (int i = 0; i < parameters.Length; i++) {
  76. var box = this.boxes[i] = new Box();
  77. box.parameter = parameters[i];
  78. }
  79. }
  80. public bool NextStage() {
  81. for (var i = 0; i < this.boxes.Length; i++) {
  82. var box = this.boxes[i];
  83. box.Set = false;
  84. if (box.Next() == false) {
  85. return false;
  86. }
  87. }
  88. return true;
  89. }
  90. public bool Sync() {
  91. if (this.boxes == null || this.boxes.Length == 0) return false;
  92. var value = this.boxes[0].GetValue();
  93. if (value == null)
  94. return false;
  95. var dateTime = value.DateTime;
  96. Loop:
  97. for (var i = 0; i < this.boxes.Length; i++) {
  98. var box = this.boxes[i];
  99. if (box.Set) {
  100. continue;
  101. }
  102. switch (box.Sync(dateTime)) {
  103. case -1: // 없다. 더이상 계산이 필요 없다.
  104. return false;
  105. case 0: // 동일한 것이 있다.
  106. box.Set = true;
  107. break;
  108. case 1: // 초과한 시간이 있다.
  109. dateTime = box.GetValue().DateTime;
  110. goto Loop;
  111. }
  112. }
  113. this.DateTime = dateTime;
  114. return true;
  115. }
  116. class Box {
  117. public enum IndexAtDateTimeResult {
  118. };
  119. public bool Set { get; set; }
  120. public int currentIndex = 0;
  121. public CalculationParameter parameter;
  122. public IndexAtDateTimeResult Result { get; set; }
  123. public Box() {
  124. Set = false;
  125. }
  126. public bool Next() {
  127. this.currentIndex++;
  128. return (this.currentIndex < parameter.Values.Length);
  129. }
  130. public int Sync(DateTime dateTime) {
  131. var values = parameter.Values;
  132. if (values != null) {
  133. for (var i = currentIndex; i < values.Length; i++) {
  134. if (values[i].DateTime == dateTime) {
  135. this.currentIndex = i;
  136. this.Setup();
  137. return 0;
  138. }
  139. if (dateTime < values[i].DateTime) {
  140. this.currentIndex = i;
  141. return 1;
  142. }
  143. }
  144. }
  145. return -1;
  146. }
  147. public CalculationValue GetValue() {
  148. if (parameter.Values == null)
  149. return null;
  150. if (parameter.Values.Length <= currentIndex)
  151. return null;
  152. return parameter.Values[currentIndex];
  153. }
  154. public void Setup() {
  155. this.Set = true;
  156. this.parameter.SetValueFromIndex(currentIndex);
  157. }
  158. }
  159. }
  160. }