BICommonWay.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using MathNet.Numerics.LinearAlgebra.Double;
  2. using NUnit.Framework;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace TEAMModelOS.SDK.Models.Service.BI
  9. {
  10. public static class BICommonWay
  11. {
  12. /// <summary>
  13. /// 字串类型分割成double类型数组,在指定位置赋值
  14. /// </summary>
  15. /// <param name="source">需要分割的字符</param>
  16. /// <param name="splitChar">分割字符</param>
  17. /// <param name="indexes">索引</param>
  18. /// <param name="num">需要加减数量</param>
  19. /// <returns></returns>
  20. public static string SplitStr(string source, char splitChar, int indexes, int num)
  21. {
  22. string str = null;
  23. if (source != null)
  24. {
  25. double[] temps = Array.ConvertAll<string, double>(source.Split(splitChar), s => double.Parse(s));
  26. temps[indexes] = temps[indexes] + num;
  27. str = string.Join(splitChar, temps);
  28. }
  29. if (str != null)
  30. return str;
  31. else
  32. return source;
  33. }
  34. /// <summary>
  35. /// 多个拼接in条件
  36. /// </summary>
  37. /// <param name="condName"></param>
  38. /// <param name="scIds"></param>
  39. /// <returns></returns>
  40. public static string ManyScSql(string condName, List<string> scIds)
  41. {
  42. StringBuilder scSql = new();
  43. if (scIds.Count > 0)
  44. {
  45. scSql.Append($" {condName} in (");
  46. for (int i = 0; i < scIds.Count; i++)
  47. {
  48. if (i == scIds.Count - 1)
  49. scSql.Append($"'{scIds[i]}'");
  50. else
  51. scSql.Append($"'{scIds[i]}',");
  52. }
  53. scSql.Append($" )");
  54. }
  55. return scSql.ToString();
  56. }
  57. /// <summary>
  58. /// 每列合并 多个数组合并成一个数组 列合并
  59. /// </summary>
  60. /// <param name="doubles"></param>
  61. /// <returns></returns>
  62. public static List<double> ManyDoubleMerge(List<List<double>> doubles)
  63. {
  64. List<double> retDou = new();
  65. var artYear = DenseMatrix.OfColumns(doubles);
  66. //var rc = artYear.RowCount;
  67. var cc = artYear.ColumnCount;
  68. for (int i = 0; i < artYear.RowCount; i++)
  69. {
  70. retDou.Add(artYear.SubMatrix(i, 1, 0, cc).ColumnSums().Sum());
  71. }
  72. return retDou;
  73. }
  74. }
  75. }