Browse Source

增加计算得分模块,初步写 main.py

liuyuqi-dellpc 5 years ago
parent
commit
f7f249c6d3
5 changed files with 86 additions and 8 deletions
  1. 7 1
      README.md
  2. 15 6
      code/data_preview.py
  3. 22 1
      code/main.py
  4. 32 0
      code/score.py
  5. 10 0
      code/test_pandas.py

+ 7 - 1
README.md

@@ -1,3 +1,9 @@
 # ServerManager
 
-2018年阿里巴巴全球调度算法大赛项目
+2018年阿里巴巴全球调度算法大赛项目
+
+```angular2html
+#远程执行:
+ssh://liuyuqi@localhost:2201/home/liuyuqi/anaconda3/envs/py36/bin/python -u /home/liuyuqi/workspace/ServerManager/code/data_preview.py -dAgg
+
+```

+ 15 - 6
code/data_preview.py

@@ -38,6 +38,7 @@ def for_df1():
     # [5 rows x 98 columns]
     df1["mem"]=tmp.T.mean().T #转置,求均值,再转置回来,这样求得一行的均值。
     print(df1.head())
+    print("总共应用:",df1["appid"].unique().shape)
 
 def for_df2():
     # 主机表 :宿主机id/ cpu规格/mem规格/disk规格/P上限/M上限/PM上限
@@ -56,20 +57,27 @@ def for_df2():
     # (6000, 7)
     print(df2.head())
     # machine_3   32   64   600  7  3   7
+    print("总共主机:",df2["machineid"].unique().shape)
+    # 6000
+
+    # 这里主机主要就两类:
+    # machine_1	32	64	600  	7	3	7    数量:3000
+    # machine_2	92	288	1024	7	7	9   数量:3000
 
 def for_df3():
     # 主机machine/实例instance/应用app 关系表
-    df2=pd.read_csv("../data/scheduling_preliminary_instance_deploy_20180606.csv", header=None,names=list(["instanceid", "appid", "machineid"]))
-    print(df2.dtypes)
-    print("df数据大小:",df2.shape)
-    print("instance唯一数量:",df2["instanceid"].unique().shape)
+    df3=pd.read_csv("../data/scheduling_preliminary_instance_deploy_20180606.csv", header=None,names=list(["instanceid", "appid", "machineid"]))
+    print(df3.dtypes)
+    print("df数据大小:",df3.shape)
+    print("instance唯一数量:",df3["instanceid"].unique().shape)
     # print(df2["instanceid"])
+    print("总共实例:",df3["instanceid"].unique().shape)
 
 
 
 def for_df4():
     # 主机和实例表。部署appid1的insterference最多可以部署n个appid2
-    df=pd.DataFrame(pd.read_csv("../data/scheduling_preliminary_app_interference_20180606.csv",header=None),columns=list(["appid1","appid2","max_interference"]))
+    df=pd.read_csv("../data/scheduling_preliminary_app_interference_20180606.csv",header=None,names=list(["appid1","appid2","max_interference"]))
     # 查看数据类型
     # print(df.dtypes)
     print("df数据大小:",df.shape)
@@ -97,6 +105,7 @@ def for_df4():
     # 描述性统计
     print("数据预览:",df.describe())
 
-    plt.plot(df["max_machine"])
+    plt.plot(df["max_interference"])
     plt.savefig("../submit/fig1.png")
 
+for_df4()

+ 22 - 1
code/main.py

@@ -5,6 +5,27 @@
 @Time :2018/7/4 15:55
 @File :main.py
 '''
+import os,sys
+import numpy as np,pandas as pd
+import matplotlib.pyplot as plt
 
-if __name__ == '__main__':
+#Wij矩阵表示第i个instance实例部署到j主机上
+Wij_size = np.zeros((68219, 6000))
+Wij = np.zeros_like(Wij_size)
+
+def getWij():
+    # inst_26195, app_147, machine_1149
+    df3=pd.read_csv("../data/scheduling_preliminary_instance_deploy_20180606.csv", header=None,names=list(["instanceid", "appid", "machineid"]))
+    for i in range(0,68219):
+            if df3[i]["machineid"]==None:
+                pass
+            else:
+                # Wij[i][j]=
+                pass
+
+def import_data():
     pass
+
+if __name__ == '__main__':
+    getWij()
+

+ 32 - 0
code/score.py

@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+'''
+得分计算
+@Auther :liuyuqi.gov@msn.cn
+@Time :2018/7/6 1:51
+@File :score.py
+'''
+import math
+
+# Sjt表示j主机在t时刻的得分score。
+
+flag = True
+alpha = 10
+beta = 0.5
+
+
+def getScore():
+    '''
+    计算得分
+    :return:
+    '''
+    sum=0
+    for j in range(0, 6000):
+        for t in range(0,92):
+            # c表示j主机在t时刻的CPU利用率
+            c = (1 + 2 + 3) / 50
+            if flag == False:
+                Sjt = 0
+            else:
+                Sjt = 1 + alpha * (math.exp(max(0, c - beta)))
+                sum=sum+Sjt

+ 10 - 0
code/test_pandas.py

@@ -20,4 +20,14 @@ def t2():
     print(obj.dtypes)
     print(uniques.shape)
 
+def t3():
+    df=pd.DataFrame()
+    df2=pd.read_csv()
+    df3=pd.Series()
+    pd.concat()
+    pd.to_datetime()
+    pd.merge()
+    pd.Timestamp
+
+
 t2()