最新消息:20210917 已从crifan.com换到crifan.org

【已解决】用Python计算整个团队的当期业绩

Python crifan 747浏览 0评论
折腾:
【未解决】用Python实现解析excel计算业绩统计并打包成可执行文件
期间,此处接着去更新计算逻辑:
要去计算整个团队的业绩
对于这种推荐关系:
a推荐b,c,d
b推荐e,f
e推荐g,h
  • bcdefgh各自的业绩,加起来就是a团队的业绩。
    • a团队业绩=b团队+C+d=(b+e团队+f)+c+d=b+e+(g+h)+f+c+d
  • e,f,g,h加起来就是b团队的业绩
  • g,h的业绩加起来就是e团队的业绩
然后就在考虑:
是否要用Tree树状结构去辅助计算团队业绩
还是直接手动计算,调用循环处理
想了想,为了以后计算逻辑更清晰,还是用树吧
所以问题转换为:
【已解决】Python中如何实现Tree树结构且带辅助数据以便于后续计算
构建好树tree后,很容易就计算好了团队业绩:
由此,后续再去更新和计算 团队业绩teamSaleMoney,就很简单了:
for eachNode in gRootNode.descendants:
  eachNode.teamSaleMoney = calcTeamSaleMoney(eachNode)
  print("Updated team sale money: eachNode=%s" % eachNode)

for eachNode in gRootNode.descendants:
  teamSaleMoneyDict[eachNode.name] = eachNode.teamSaleMoney
然后调试,加了团队业绩后的效果:
# for debug
updatedTeamSaleMoneyFilename = "RelationAll_%s_updatedTeamSaleMoney.json" % gCurDateStr
dbgPrintTreeToJson(gRootNode, outputFilename=updatedTeamSaleMoneyFilename)
值是:
{
  "children": [
    {
      "children": [
        {
          "name": "wyj121212121",
          "personalSaleMoney": 431485.96540387,
          "teamSaleMoney": 0
        },
        {
          "name": "wyf333222111",
          "personalSaleMoney": 23265.72892793,
          "teamSaleMoney": 0
        },
        {
          "name": "tzf123451234",
          "personalSaleMoney": 93156.16512627,
          "teamSaleMoney": 0
        },
        {
          "name": "jch123123123",
          "personalSaleMoney": 45692.213125,
          "teamSaleMoney": 0
        },
        {
          "name": "ha1234512345",
          "personalSaleMoney": 45613.9907069,
          "teamSaleMoney": 0
        }
      ],
      "name": "aaaaaaaa5522",
      "personalSaleMoney": 0,
      "teamSaleMoney": 639214.06328997
    },
。。。
   {
      "children": [
        {
          "name": "neo12345cccc",
          "personalSaleMoney": 4916.84429293,
          "teamSaleMoney": 0
        }
      ],
      "name": "zz12345ccccc",
      "personalSaleMoney": 1230090.8656935801,
      "teamSaleMoney": 4916.84429293
    }
  ],
  "name": "fakeroot0000",
  "personalSaleMoney": 0,
  "teamSaleMoney": 0
}

转载请注明:在路上 » 【已解决】用Python计算整个团队的当期业绩

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
92 queries in 0.209 seconds, using 23.41MB memory