DBProcessData.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using Universal;
  2. namespace ProximaAnalizer.Helpers;
  3. public class DBProcessData<T_Hierarchy>(char spilter, int skip)
  4. where T_Hierarchy : IDictionary<string, object>, new()
  5. {
  6. public bool ToDictionary(IDictionary<string, object> input, out T_Hierarchy? output)
  7. {
  8. output = default;
  9. if (input is null)
  10. return false;
  11. T_Hierarchy cache = [];
  12. foreach (KeyValuePair<string, object> rawData in input)
  13. {
  14. Span<string> source = rawData.Key.Split(spilter).AsSpan()[skip..];
  15. ColumAnalizer(cache, source, rawData.Key);
  16. }
  17. output = cache;
  18. return true;
  19. }
  20. private static void ColumAnalizer(/*ref*/ T_Hierarchy cache, Span<string> seprated, object value)
  21. {
  22. if (seprated.Length <= 1)
  23. {
  24. cache[seprated[0]] = value;
  25. return;
  26. }
  27. if (!cache.TryGetValue(seprated[0], out object? output) || output is not T_Hierarchy hierarchy)
  28. {
  29. hierarchy = [];
  30. cache[seprated[0]] = hierarchy;
  31. }
  32. cache = hierarchy;
  33. ColumAnalizer(cache, seprated[1..], value);
  34. }
  35. }
  36. public class GeneralProcessData(int skip = 0) : DBProcessData<Dictionary<string, object>>('.', skip)
  37. {
  38. public static bool CreateTablePM(IDictionary<string, object> data, IDictionary<string, object> cache)
  39. {
  40. Dictionary<string, object> ValueSensor = [];
  41. Dictionary<string, object> StatusSensor = [];
  42. Dictionary<string, object> leakCheck = [];
  43. Dictionary<string, object> recipe = [];
  44. Dictionary<string, object> aoValue = [];
  45. Dictionary<string, object> ffu = [];
  46. Dictionary<string, object> mfc = [];
  47. Dictionary<string, object> gaslineHeater = [];
  48. Dictionary<string, object> bufferFoup = [];
  49. Dictionary<string, object> avValue = [];
  50. foreach (var item in data)
  51. {
  52. if (item.Value is not IDictionary<string, object> values)
  53. {
  54. switch (item.Key)
  55. {
  56. case string s when s.EndsWith("Enable"):
  57. continue;
  58. case string s when s.StartsWith("LeakCheck"):
  59. leakCheck.Add(item.Key, item.Value);
  60. continue;
  61. default:
  62. recipe.Add(item.Key, item.Value);
  63. continue;
  64. }
  65. }
  66. switch (item.Key)
  67. {
  68. case "APC":
  69. case "APCVATGV":
  70. case "BoatElevatorServo":
  71. case "BoatRotationServo":
  72. case "BufferServo":
  73. case "Shutter":
  74. CreateTable(cache, item.Key, values);
  75. continue;
  76. case string s when s.StartsWith("Trig"):
  77. if (item.Value is IDictionary<string, object> value)
  78. aoValue.Add(item.Key, value["AOValue"]);
  79. continue;
  80. case string s when s.StartsWith("FS"):
  81. case string s1 when s1.StartsWith("PG"):
  82. case string s2 when s2.StartsWith("PS"):
  83. case string s3 when s3.StartsWith("VG"):
  84. if (item.Value is IDictionary<string, object> vss)
  85. ValueSensor.Add(item.Key, vss["Value"]);
  86. continue;
  87. case string s when s.StartsWith("Sensor"):
  88. if (item.Value is IDictionary<string, object> status)
  89. StatusSensor.Add(item.Key, status["Value"]);
  90. continue;
  91. case string s when s.StartsWith("MFC"):
  92. if (item.Value is IDictionary<string, object> mfcs)
  93. mfcs.Foreach(t => mfc.Add($"{item.Key}_{t.Key}", t.Value));
  94. continue;
  95. case string s when s.StartsWith("FFU"):
  96. if (item.Value is IDictionary<string, object> ffus)
  97. ffus.Foreach(t => ffu.Add($"{item.Key}_{t.Key}", t.Value));
  98. continue;
  99. case string s when s.StartsWith("GaselineHeater"):
  100. if (item.Value is IDictionary<string, object> gaslines)
  101. gaslines.Foreach(t => gaslineHeater.Add($"{item.Key}_{t.Key}", t.Value));
  102. continue;
  103. case string s when s.StartsWith("Valve"):
  104. if (item.Value is IDictionary<string, object> valves)
  105. valves.Foreach(t => avValue.Add($"{item.Key}_{t.Key}", t.Value));
  106. continue;
  107. default:
  108. continue;
  109. }
  110. }
  111. CreateTable(cache, "MFC", mfc);
  112. CreateTable(cache, "FFU", ffu);
  113. CreateTable(cache, "Valve", avValue);
  114. CreateTable(cache, "GaselineHeater", gaslineHeater);
  115. CreateTable(cache, "ValueSensor", ValueSensor);
  116. CreateTable(cache, "StatusSensor", StatusSensor);
  117. CreateTable(cache, "LeakCheck", leakCheck);
  118. CreateTable(cache, "AoValue", aoValue);
  119. CreateTable(cache, "Recipe", recipe);
  120. return true;
  121. }
  122. public static void CreateTableSystem(IDictionary<string, object> data, IDictionary<string, object> cache)
  123. {
  124. Dictionary<string, object> systemCollection = [];
  125. Dictionary<string, object> alarmCollection = [];
  126. Dictionary<string, object> Heater = [];
  127. Dictionary<string, object> Stocker = [];
  128. Dictionary<string, object> LoadPort = [];
  129. //Dictionary<string, object> FIMS = [];
  130. foreach (var item in data)
  131. {
  132. if (item.Value is not IDictionary<string, object> values)
  133. continue;
  134. switch (item.Key)
  135. {
  136. case "Boat":
  137. case "CarrierRobot":
  138. case "Scheduler":
  139. case "WaferRobot":
  140. CreateTable(cache, item.Key, values);
  141. continue;
  142. case string s when s.StartsWith("Stocker"):
  143. Stocker.Add(item.Key, values);
  144. continue;
  145. case string s when s.StartsWith("LP"):
  146. LoadPort.Add(item.Key, values);
  147. continue;
  148. //case string s when s.StartsWith("FIMS"):
  149. // FIMS.Add(item.Key, values);
  150. // continue;
  151. case "System":
  152. if (values is not IDictionary<string, object> systems)
  153. continue;
  154. foreach (var system in systems)
  155. {
  156. switch (system.Key)
  157. {
  158. case string s when s.StartsWith("Heater"):
  159. Heater.Add(system.Key, system.Value);
  160. continue;
  161. case string s when s.StartsWith("AlarmSignalHeater"):
  162. alarmCollection.Add(system.Key, ((IDictionary<string, object>)system.Value)["Value"] ??= false);
  163. continue;
  164. default:
  165. systemCollection.Add(system.Key, system.Value);
  166. break;
  167. }
  168. }
  169. continue;
  170. default:
  171. break;
  172. }
  173. //CreateTable(cache, "FIMS", FIMS);
  174. CreateTable(cache, "Heater", Heater);
  175. CreateTable(cache, "LoadPort", LoadPort);
  176. CreateTable(cache, "Stocker", Stocker);
  177. CreateTable(cache, "System", systemCollection);
  178. CreateTable(cache, "AlarmSignalHeater", alarmCollection);
  179. }
  180. }
  181. private static bool CreateTable(IDictionary<string, object> cache, string key, object value)
  182. {
  183. return cache.TryAdd(key, value);
  184. }
  185. }