algorithm.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. from .DataStream import EMchPosmap
  2. import numpy as np
  3. import logging
  4. logger = logging.getLogger('calcer')
  5. def calc_chratios(data, pos_map, start, end):
  6. view = data[[pos_map.succ_count, pos_map.fail_count, pos_map.commit_count], :]
  7. view = view[:, start:end]
  8. all = np.cumsum(view, axis=1)
  9. succ = all[0, :]
  10. commit = all[0, :] + all[1, :]
  11. commit += 0.0000001
  12. y = succ / commit
  13. y = y.ravel()
  14. return int(all[0, -1]), int(all[0, -1] + all[1, -1]), y
  15. def calc_chspeed(data, pos_map, start, end):
  16. view = data[[pos_map.commit_count], :]
  17. view = view[:, start:end]
  18. all = np.sum(view, axis=1)
  19. all = all.ravel()
  20. def calc_mchratios(data, pos_map, start, end):
  21. view = data[[pos_map.succ_count, pos_map.fail_count, pos_map.submit_count], :]
  22. view = view[:, start:end]
  23. all = np.cumsum(view, axis=1)
  24. succ = all[0, :]
  25. commit = all[0, :] + all[1, :]
  26. commit += 0.0000001
  27. y = succ / commit
  28. y = y.ravel()
  29. return int(all[0, -1]), int(all[0, -1] + all[1, -1]), y
  30. def calc_morder_send(data, pos_map: type(EMchPosmap), start: int, end: int):
  31. view = data[:, start:end]
  32. sums = np.sum(view, axis=1)
  33. all_return = sums[pos_map.succ_mch_amounts] + sums[pos_map.fail_mch_amounts] + 0.0000001
  34. ratio = sums[pos_map.succ_mch_amounts] / all_return
  35. send_count = sums[pos_map.submit_count] - sums[pos_map.succ_count] - sums[pos_map.fail_count]
  36. send_amounts = sums[pos_map.submit_amounts] - sums[pos_map.succ_mch_amounts] - sums[pos_map.fail_mch_amounts]
  37. lack_amounts = send_amounts * ratio
  38. return send_count, sums[pos_map.submit_count], sums[pos_map.succ_count], sums[pos_map.fail_count], sums[pos_map.submit_amounts], \
  39. sums[pos_map.succ_mch_amounts], sums[pos_map.fail_mch_amounts], send_amounts, lack_amounts
  40. def calc_morder_lack(data, pos_map: type(EMchPosmap), start: int, end: int):
  41. view = data[:, start:end]
  42. sums = np.sum(view, axis=1)
  43. all_return = sums[pos_map.succ_count] + sums[pos_map.fail_count] + 0.0000001
  44. ratio = sums[pos_map.succ_count] / all_return
  45. send_count = sums[pos_map.submit_count] - sums[pos_map.succ_count] - sums[pos_map.fail_count]
  46. send_amounts = sums[pos_map.submit_amounts] - sums[pos_map.succ_mch_amounts] - sums[pos_map.fail_mch_amounts]
  47. lack_amounts = send_amounts * ratio
  48. logger.info("send_count=%d send_amounts=%.4f ratio=%.4f lack_amounts=%.4f", send_count, send_amounts, ratio, lack_amounts)
  49. return send_amounts, lack_amounts
  50. # 用于计算成功率及利润率
  51. # succ_count, fail_count, succ_ratio, profit,profit_ratio
  52. def calc_mch_profit(data, pos_map: type(EMchPosmap), start: int, end: int):
  53. view = data[:, start:end]
  54. sums = np.sum(view, axis=1)
  55. submit_count = sums[pos_map.submit_count]
  56. succ_count = sums[pos_map.succ_count]
  57. fail_count = sums[pos_map.fail_count]
  58. succ_ratio = succ_count / (succ_count + fail_count + 0.0000001)
  59. ch_amounts = sums[pos_map.succ_ch_amounts]
  60. mch_amounts = sums[pos_map.succ_mch_amounts]
  61. profit = mch_amounts - ch_amounts
  62. return int(submit_count), int(succ_count), int(fail_count), round(succ_ratio, 5), round(profit, 3)