根据百分比划分结果
我正在为我们的应用程序中的一项新功能编写规格。 现在我们想要做的是,每当客户以特定货币发送转账消息时,我们需要在一个或多个银行之间分配。
每次发送转账消息时,80% 支付给银行 A,20% 支付给银行 B,以此类推。我们需要在我们的数据库(sql 2005)中构建它,以便如果百分比发生变化,我们就能够更改它。 我很难根据数据库中的百分比编写计算规范,计算何时将 80% 的消息发送到银行 A,何时将 20% 的消息发送到银行 B。我最初想到实现一个计数器来对消息进行计数,然后根据百分比进行计算,但不确定算法。你能帮忙吗?
I am writing the spacifications for a new feature in our application.
Now what we want to do is whenever a message for trasfers is sent by client in a specific currency we need to divide between one or more banks.
80 % to bank A and 20% to bank B etc each time a transfer message is sent. We need to build this in our db (sql 2005) so that if the percentage change for us to be able to change that.
I am having difficulty writing the spec for the calculation of when the 80% of messages will be sent to BANK A and when the 20% will be sent to bank b based on the perecentage we have in our db. I initially thought of implenting a counter that counts the messages and then doing a calculation based on the percentage but not sure of the algorythm. can you help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不需要保证结果,您可以简单地将路由基于随机数生成器:
上面的内容显然是硬编码的,并且仅针对两个银行进行了简化,但我认为您可以看到如何将其推广到 N具有 N 个百分比的银行:按百分比排序并按升序测试数组。
如果您确实需要精确说明(将四个发送到银行 A,第五个始终发送到银行 B),那么我认为您需要实施一个计数器。我心中最重要的问题是:
一般来说,首先通过除以最大公约数来减少比率,然后发送按顺序向每个银行发送正确数量的消息,或者沿着相同的重复周期将所有结果混在一起。
If you don't need the results to be guaranteed, you could simply base the routing on a random number generator:
The above is obviously hard-coded and simplified for just two banks, but I think you could see how to generalize it for N banks with N percentages: sort by percentage and test the array in increasing order.
If you do need to be exact about it (send four to Bank A and the fifth always to Bank B) then I think you will need to implement a counter. The most important question in my mind for this is:
In general, look to first reduce your ratios by dividing by the greatest common divisor, and then either send the right number of messages to each bank sequentially, or shuffle all the results together along the same repetition period.