Program.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using Azure;
  2. using HTEX.Test.Service;
  3. using MathNet.Numerics;
  4. using System.Configuration;
  5. using System.Diagnostics;
  6. using System.Text.RegularExpressions;
  7. using TEAMModelOS.SDK.DI;
  8. using TEAMModelOS.SDK.Extension;
  9. namespace HTEX.Test
  10. {
  11. public class Program
  12. {
  13. public static void Main(string[] args)
  14. {
  15. Test();
  16. var builder = WebApplication.CreateBuilder(args);
  17. // Add services to the container.
  18. builder.Services.AddControllers();
  19. builder.Services.AddAzureStorage(builder.Configuration.GetValue<string>("Azure:Storage:ConnectionString"));
  20. builder.Services.AddAzureRedis(builder.Configuration.GetValue<string>("Azure:Redis:ConnectionString"));
  21. builder.Services.AddAzureCosmos(builder.Configuration.GetValue<string>("Azure:Cosmos:ConnectionString"));
  22. builder.Services.AddAzureServiceBus(builder.Configuration.GetValue<string>("Azure:ServiceBus:ConnectionString"));
  23. builder.Services.AddAzureSignalR(builder.Configuration.GetValue<string>("Azure:SignalR:ConnectionString"));
  24. builder.Services.AddSnowflakeId(Convert.ToInt64(builder.Configuration.GetValue<string>("Option:LocationNum")), 1);
  25. builder.Services.AddHttpClient();
  26. var app = builder.Build();
  27. // Configure the HTTP request pipeline.
  28. app.UseHttpsRedirection();
  29. app.UseAuthorization();
  30. app.MapControllers();
  31. app.Run();
  32. }
  33. public static string Test()
  34. {
  35. var a = new int[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];
  36. var b = new int[2192, 2379, 2070, 1813, 1662, 1421, 1134, 1043, 861, 763, 608, 563, 451, 358, 291, 252, 213, 170, 152, 133, 132, 95, 82, 71, 73, 63, 43];
  37. // var per= GetPersent(array,3);
  38. // Console.WriteLine(per);
  39. //var data = MLService.GetNormalCluster(array.ToArray(),3,0.3);
  40. // var group = array.GroupBy(x=>x).Select(x=>new { key = x.Key, list = x.ToList()}).OrderBy(x=>x.key);
  41. // Console.WriteLine(group.Select(x => x.key).ToJsonString());
  42. //Console.WriteLine(group.Select(x => x.list.Count()).ToJsonString());
  43. //int count = 10;
  44. //int score = 10;
  45. //for (int i = 0; i < 10; i++)
  46. //{
  47. // int work = Random.Shared.Next(1, count);
  48. // int right = Random.Shared.Next(1, work);
  49. // double xIRS = (work+right);
  50. // var exsIRS = 150/(1+Math.Exp(-(xIRS/2)))-75;
  51. // Console.WriteLine($"{i}=》答题 {work}-----{right}: {exsIRS}");
  52. // double xPIC = (work+right*3);
  53. // var exsPIC = 40/(1+Math.Exp(-(xPIC/5)))-20;
  54. // Console.WriteLine($"{i}=》挑人 {work}-----{right}: {exsPIC}");
  55. // double xBUS = (work+right*3+(work-right));
  56. // var exsBUZ = 80/(1+Math.Exp(-(xBUS/3)))-40;
  57. // Console.WriteLine($"{i}=》抢权 {work}-----{right}: {exsBUZ}");
  58. // int pscr = Random.Shared.Next(1, 10)*10;
  59. // int gscr = Random.Shared.Next(1, 10)*10;
  60. // double xSCR = (pscr + gscr );
  61. // var exsSCR= 60/(1+Math.Exp(-(xSCR/8)))-30;
  62. // Console.WriteLine($"{i}=》计分 {pscr}-----{gscr}: {exsSCR}");
  63. // double xWRK = (work);
  64. // var exsWRK = 150/(1+Math.Exp(-(xWRK)))-75;
  65. // Console.WriteLine($"{i}=》作品 {work}-----{right}: {exsBUZ}");
  66. // int vt = Random.Shared.Next(1, 3);
  67. // int sc = Random.Shared.Next(1, 3);
  68. // int cm = Random.Shared.Next(1, 3);
  69. // int pt = Random.Shared.Next(1, 3);
  70. // double xCMT = (vt + sc+cm*2+pt);
  71. // var exsCMT = 100/(1+Math.Exp(-(xSCR/8)))-50;
  72. // Console.WriteLine($"{i}=》评分 {vt}-----{sc}---{cm}---{pt}: {exsCMT}");
  73. // int b = Random.Shared.Next(1, 100)/20;
  74. // int m = Random.Shared.Next(1, 100)/20;
  75. // int g = Random.Shared.Next(1, 10)/2;
  76. // int t = Random.Shared.Next(1, 10)/2;
  77. // double xXZ = (b + m+g+t);
  78. // var exsXZ= 150/(1+Math.Exp(-(xSCR/8)))-75;
  79. // Console.WriteLine($"{i}=》协作 {b}-----{m}---{g}---{t}: {exsXZ}");
  80. // var xALL = xXZ+xCMT+xWRK+xSCR+xBUS+exsPIC+xIRS;
  81. // var exsALL = 190/(1+Math.Exp(-(xALL/25)))-95;
  82. // Console.WriteLine($"{i}=》所有: {exsALL}");
  83. //}
  84. //List<int> nums = new List<int>();
  85. //for (int i = 0; i < 100; i++)
  86. //{
  87. // nums.Add(Random.Shared.Next(1,5));
  88. //}
  89. //for (int i = 0; i < 100; i++)
  90. //{
  91. // nums.Add(Random.Shared.Next(4, 8));
  92. //}
  93. //for (int i = 0; i < 100; i++)
  94. //{
  95. // nums.Add(Random.Shared.Next(5, 20));
  96. //}
  97. //for (int i = 0; i < 50; i++)
  98. //{
  99. // nums.Add(Random.Shared.Next(15, 36));
  100. //}
  101. //var per = GetPersent(nums, 11);
  102. //bool[] anomalies = MarkAnomalies(nums);
  103. //for (int i = 0; i < nums.Count; i++)
  104. //{
  105. // if (anomalies[i]) { Console.WriteLine($"Number{ i}: {nums[i]} is an anomaly."); }
  106. //}
  107. return "Hello World!";
  108. }
  109. static bool[] MarkAnomalies(List<int> array)
  110. {
  111. if (array.Count == 0) return new bool[0];
  112. double average = array.Average();
  113. double variance = array.Average(x => Math.Pow(x - average, 2));
  114. double standardDeviation = Math.Sqrt(variance);
  115. // 定义异常值的阈值,这里使用2倍标准差
  116. double threshold =3* standardDeviation;
  117. bool[] anomalies = new bool[array.Count];
  118. for (int i = 0; i < array.Count; i++)
  119. {
  120. double deviation = Math.Abs(array[i] - average);
  121. anomalies[i] = deviation > threshold;
  122. }
  123. return anomalies;
  124. }
  125. /// <summary>
  126. /// 计算当前元素在集合中超过了多少百分比的值
  127. /// </summary>
  128. /// <param name="nums"></param>
  129. /// <param name="curr"></param>
  130. /// <returns></returns>
  131. public static double GetPersent(IEnumerable<double> nums, int curr)
  132. {
  133. int count = 0;
  134. foreach (var op in nums.OrderBy(x => x))
  135. {
  136. if (op < curr)
  137. {
  138. count++;
  139. }
  140. else if (op == curr)
  141. {
  142. count++;
  143. }
  144. else
  145. {
  146. break;
  147. }
  148. }
  149. return count *1.0/ nums.Count() * 100;
  150. }
  151. public class KeyCount
  152. {
  153. public int count { get; set;}
  154. public int key { get; set;}
  155. }
  156. }
  157. }