import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Cursor from pylab import mpl mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] # 指定默认字体:解决plot不能显示中文问题 mpl.rcParams['axes.unicode_minus'] = False # 解决保存图像是负号'-'显示为方块的问题 # 数据 # 总时间:10 周 sac = 10 bac = np.array([[30], [70], [40], [30]]) # 每期预算分配(共10期) bac_list = np.array([ [10, 15, 5, 0, 0, 0, 0, 0, 0, 0], [0, 10, 10, 10, 20, 10, 10, 0, 0, 0], [0, 0, 0, 0, 5, 5, 25, 5, 0, 0], [0, 0, 0, 0, 0, 0, 0, 5, 5, 20] ]) # 每期实际成本(前6期) ac_list = np.array([ [10, 16, 8, 0, 0, 0], [0, 10, 10, 12, 24, 12], [0, 0, 0, 0, 5, 5], [0, 0, 0, 0, 0, 0] ]) # 每期完成任务百分率(前6期) radio = np.array([ [30, 80, 100, 0, 0, 0], [0, 10, 25, 35, 55, 65], [0, 0, 0, 0, 10, 20], [0, 0, 0, 0, 0, 0] ]) # 求PV函数 def get_PV(bac, num): # 取出每行前num列数据,对行对列进行相加得到PV pv = np.sum(np.sum(bac[:, :num], axis=1), axis=0) return pv # 求EV函数 def get_EV(bac, radio, num): # 每项任务的ev = 每项任务的bac * ra每一行的第num列值 ra = radio[:, num - 1:num] ev = np.sum(np.sum(bac * (0.01 * ra), axis=1), axis=0) return ev # 求AC函数 def get_AC(ac, num): # 每项任务的ac = 每项任务的前num列之和,axis=1是每一行的和 ac = np.sum(np.sum(ac[:, :num], axis=1), axis=0) return ac # 求sv函数 def get_SV(ev, pv): return ev - pv # 求SPI函数 def get_SPI(ev, pv): return ev / pv # 求cv函数 def get_CV(ev, ac): return ev - ac # 求CPI def get_CPI(ev, ac): return ev / ac # 求 TEAC def get_TEAC(sac, spi): return sac / spi # 求 EAC def get_EAC(bac, cpi): bac_all = np.sum(np.sum(bac, axis=1), axis=0) return bac_all / cpi # 问题:求1-3期的挣值分析 # 第一期 pv1 = get_PV(bac_list, 1) ev1 = get_EV(bac, radio, 1) ac1 = get_AC(ac_list, 1) sv1 = get_SV(ev1, pv1) cv1 = get_CV(ev1, ac1) spi1 = get_SPI(ev1, pv1) cpi1 = get_CPI(ev1, ac1) teac1 = get_TEAC(sac, spi1) eac1 = get_EAC(bac, cpi1) print("第1期的挣值分析: \n" "PV=%.2f(元), EV=%.2f(元), AC=%.2f(元)\n" "SV=%.2f(元),CV=%.2f(元)\n" "SPI=%.2f,CPI=%.2f\n" "TEAC=%.2f(天),EAC=%.2f(元)" % (pv1, ev1, ac1, sv1, cv1, spi1, cpi1, teac1, eac1)) # 第2期 pv2 = get_PV(bac_list, 2) ev2 = get_EV(bac, radio, 2) ac2 = get_AC(ac_list, 2) sv2 = get_SV(ev2, pv2) cv2 = get_CV(ev2, ac2) spi2 = get_SPI(ev2, pv2) cpi2 = get_CPI(ev2, ac2) teac2 = get_TEAC(sac, spi2) eac2 = get_EAC(bac, cpi2) print("第2期的挣值分析: \n" "PV=%.2f(元), EV=%.2f(元), AC=%.2f(元)\n" "SV=%.2f(元),CV=%.2f(元)\n" "SPI=%.2f,CPI=%.2f\n" "TEAC=%.2f(天),EAC=%.2f(元)" % (pv2, ev2, ac2, sv2, cv2, spi2, cpi2, teac2, eac2)) # 第三期 pv3 = get_PV(bac_list, 3) ev3 = get_EV(bac, radio, 3) ac3 = get_AC(ac_list, 3) sv3 = get_SV(ev3, pv3) cv3 = get_CV(ev3, ac3) spi3 = get_SPI(ev3, pv3) cpi3 = get_CPI(ev3, ac3) teac3 = get_TEAC(sac, spi3) eac3 = get_EAC(bac, cpi3) print("第3期的挣值分析: \n" "PV=%.2f(元), EV=%.2f(元), AC=%.2f(元)\n" "SV=%.2f(元),CV=%.2f(元)\n" "SPI=%.2f,CPI=%.2f\n" "TEAC=%.2f(天),EAC=%.2f(元)" % (pv3, ev3, ac3, sv3, cv3, spi3, cpi3, teac3, eac3)) # 绘制1-3期折线图 x_data = [1, 2, 3] y_pv = [pv1, pv2, pv3] y_ev = [ev1, ev2, ev3] y_ac = [ac1, ac2, ac3] plt.plot(x_data, y_pv, 'go-', alpha=0.5, linewidth=1, label='PV') plt.plot(x_data, y_ev, 'rs-', alpha=0.5, linewidth=1, label='EV') plt.plot(x_data, y_ac, 'b*-', alpha=0.5, linewidth=1, label='AC') plt.legend() plt.title("1-3期挣值分析") plt.xlabel("时间(周)") plt.ylabel("钱(元)") plt.show()
标签:分析,10,ac,%.,get,2f,bac,挣值 From: https://www.cnblogs.com/hmy22466/p/18113911