跳到主要内容

一个调用分布式des联调的接口的示例数据

输入信息

{
"messages": [
{
"uuid": "2897d138544e4fa7a1e11c6e2f4dd2b2",
"algo_init": "\ndef algo_init(app,vars):\n other_param=vars['other_param']\n from des.log import logger\n logger.info('这是algo init函数')\n def parseFunction(functionString):\n import types\n module_code = compile(functionString, '', 'exec')\n function_code = [c for c in module_code.co_consts if isinstance(c, types.CodeType)][0]\n f = types.FunctionType(function_code, globals())\n return f\n parseOriginalIndividual = parseFunction(other_param['parseOriginalIndividual'])\n preprocessIndividual = parseFunction(other_param['preprocessIndividual'])\n after_preprocess = parseFunction(other_param['after_preprocess'])\n\n #logger.info('解析程序完成')\n originalIndividual = parseOriginalIndividual(other_param['originData'],vars)\n #logger.info('原始个体获取成功')\n logger.info(originalIndividual)\n data = preprocessIndividual(other_param['individualData'],originalIndividual)\n #logger.info('数据解析完毕
')\n if 'updateConfig' in other_param and 'updateConfigFunction' in other_param:\n updateConfigFunction = other_param['updateConfigFunction']\n updateConfig = other_param['updateConfig']\n #logger.info(updateConfig)\n update_config_function = parseFunction(other_param['updateConfigFunction'])\n update_config_function(updateConfig, data, vars)\n
#logger.info(data)\n after_preprocess(app,data,vars)\n #logger.info('预处理完毕',data)\n
return\n",
"other_param": {
"originData": {
"param1": {
"searchType": "permutation",
"dataType": "csv",
"data": "studio/shanglu/share/69126/0988a5d1ac4311edb3d291628633f0cb/waitingOrder.csv"
}
},
"individualData": {
"param1": [
148,
155,
19,
61,
12,
59,
73,
51,
143,
134,
18,
168,
72,
0,
165,
27,
22,
4,
144,
56,
40,
107,
70,
86,
108,
125,
97,
36,
118,
35,
62,
113,
9,
25,
158,
16,
121,
167,
24,
11,
129,
146,
57,
110,
88,
47,
20,
98,
140,
41,
147,
5,
96,
43,
76,
49,
90,
10,
115,
119,
122,
80,
26,
117,
111,
123,
67,
17,
132,
173,
109,
89,
44,
54,
156,
8,
53,
81,
82,
145,
131,
172,
149,
153,
42,
15,
65,
169,
13,
152,
141,
112,
103,
114,
60,
52,
2,
45,
21,
85,
58,
127,
29,
116,
71,
170,
136,
93,
31,
174,
163,
128,
138,
157,
139,
91,
106,
166,
126,
1,
101,
133,
164,
32,
33,
151,
142,
6,
100,
39,
74,
46,
7,
94,
14,
171,
55,
120,
48,
135,
162,
124,
63,
95,
38,
92,
34,
150,
83,
64,
77,
130,
105,
160,
23,
69,
137,
78,
104,
154,
99,
37,
102,
3,
75,
68,
66,
50,
161,
28,
84,
30,
87,
159,
79
]
},
"parseOriginalIndividual": "\ndef parseOriginalIndividual(dataDict,vars):\n #dataDict={\n # 'param1':{'searchType':'permutation','dataType':'list','value':[1,3,5,7,9]},\n # 'param2':{'searchType':'permutation','dataType':'list','value':[10,8,6,4,2]}\n
# }\n #vars:Test()\n import os\n import copy\n import pandas as pd\n from des.storage import storage\n import uuid\n dataDict=copy.deepcopy(dataDict)\n for key,value in dataDict.items():\n if value['dataType']!='csv':\n value['value'] = value['data']\n elif value['dataType'] == 'csv':\n localTmpPath=getattr(vars, 'tempStore', os.path.join('tmp','local'))\n path = os.path.join(localTmpPath, uuid.uuid4().hex, value['data'])\n os.makedirs(os.path.dirname(path), exist_ok=True)\n storage.download(value['data'], path)\n value['value'] = pd.read_csv(path, index_col=0)\n return dataDict\n",
"preprocessIndividual": "\ndef preprocessIndividual(individual,parsedData):\n
new={}\n for paramName in individual.keys():\n encoder = individual[paramName]\n
temp = parsedData[paramName]\n if temp['searchType'] == 'permutation':\n if temp['dataType'] == 'list':\n new[paramName] = [temp['value'][encoder[i]] for i in range(len(encoder))]\n elif temp['dataType'] != 'list':\n new[paramName] = temp['value'].iloc[encoder,:]\n return new\n",
"updateConfigFunction": "\ndef updateConfigFunction(config,data,vars):\n def updateParameter(data,vars):\n vars.globalVars[data['key']]=data['value']\n for key,value in config.items():\n updateParameter(item,vars)\n",
"updateConfig": {},
"after_preprocess": "\ndef after_preprocess(app,data,vars):\n #app.endTime ='10000'\n from des.log import logger\n logger.info('after xxx')\n logger.info(data['param1'])\n vars.globalVars.updateFrom({'source1':data['param1']})\n if app.graph['processConfig']:\n for temp in app.graph['processConfig']:\n if temp['type'] == 'DataSource':\n for config in temp['processInfo'][0]['configs']:\n if config['key'] == 'sourceTye':\n config['value'] = 'table'\n if config['key'] == 'tableKey':\n config['value'] = 'source1'\n"
},
"objective_func": "\ndef gettime(app, vars):\n from des.log import logger\n r=vars.record\n num = 0\n if len(r)>1:\n num=sum([r[i]!=r[i+1] for i in range(len(r)-1)])\n app.objective_result.update({'time':num})\n vars.record=[]\n"
},
{
"uuid": "5ad52db91ea946558bfbd0bc36328847",
"algo_init": "\ndef algo_init(app,vars):\n other_param=vars['other_param']\n from des.log import logger\n logger.info('��是algo init函数')\n def parseFunction(functionString):\n import types\n module_code = compile(functionString, '', 'exec')\n function_code = [c for c in module_code.co_consts if isinstance(c, types.CodeType)][0]\n f = types.FunctionType(function_code, globals())\n return f\n parseOriginalIndividual = parseFunction(other_param['parseOriginalIndividual'])\n preprocessIndividual = parseFunction(other_param['preprocessIndividual'])\n after_preprocess = parseFunction(other_param['after_preprocess'])\n\n #logger.info('解析程序完成')\n originalIndividual = parseOriginalIndividual(other_param['originData'],vars)\n #logger.info('原始个体获取成功')\n logger.info(originalIndividual)\n data = preprocessIndividual(other_param['individualData'],originalIndividual)\n #logger.info('数据解析完毕
')\n if 'updateConfig' in other_param and 'updateConfigFunction' in other_param:\n updateConfigFunction = other_param['updateConfigFunction']\n updateConfig = other_param['updateConfig']\n #logger.info(updateConfig)\n update_config_function = parseFunction(other_param['updateConfigFunction'])\n update_config_function(updateConfig, data, vars)\n
#logger.info(data)\n after_preprocess(app,data,vars)\n #logger.info('预处理完毕',data)\n
return\n",
"other_param": {
"originData": {
"param1": {
"searchType": "permutation",
"dataType": "csv",
"data": "studio/shanglu/share/69126/0988a5d1ac4311edb3d291628633f0cb/waitingOrder.csv"
}
},
"individualData": {
"param1": [
25,
41,
67,
171,
116,
39,
21,
166,
58,
97,
69,
91,
151,
66,
79,
172,
84,
163,
87,
37,
7,
127,
139,
161,
112,
4,
129,
52,
75,
168,
165,
83,
51,
111,
34,
134,
102,
22,
140,
18,
28,
156,
158,
53,
153,
35,
148,
11,
42,
110,
0,
95,
92,
143,
159,
43,
44,
29,
142,
118,
71,
132,
137,
88,
63,
8,
146,
30,
157,
60,
138,
115,
26,
55,
38,
23,
155,
121,
173,
93,
20,
2,
80,
56,
96,
162,
54,
119,
150,
59,
5,
147,
82,
17,
122,
120,
64,
149,
152,
9,
133,
126,
70,
86,
144,
167,
24,
160,
49,
174,
50,
169,
14,
16,
128,
78,
123,
98,
108,
85,
99,
136,
40,
130,
106,
103,
1,
61,
109,
164,
15,
47,
72,
45,
76,
73,
31,
3,
33,
81,
125,
13,
32,
141,
57,
89,
65,
27,
19,
105,
170,
145,
131,
114,
36,
10,
154,
113,
135,
107,
90,
101,
12,
117,
68,
48,
77,
62,
104,
100,
94,
74,
6,
124,
46
]
},
"parseOriginalIndividual": "\ndef parseOriginalIndividual(dataDict,vars):\n #dataDict={\n # 'param1':{'searchType':'permutation','dataType':'list','value':[1,3,5,7,9]},\n # 'param2':{'searchType':'permutation','dataType':'list','value':[10,8,6,4,2]}\n
# }\n #vars:Test()\n import os\n import copy\n import pandas as pd\n from des.storage import storage\n import uuid\n dataDict=copy.deepcopy(dataDict)\n for key,value in dataDict.items():\n if value['dataType']!='csv':\n value['value'] = value['data']\n elif value['dataType'] == 'csv':\n localTmpPath=getattr(vars, 'tempStore', os.path.join('tmp','local'))\n path = os.path.join(localTmpPath, uuid.uuid4().hex, value['data'])\n os.makedirs(os.path.dirname(path), exist_ok=True)\n storage.download(value['data'], path)\n value['value'] = pd.read_csv(path, index_col=0)\n return dataDict\n",
"preprocessIndividual": "\ndef preprocessIndividual(individual,parsedData):\n
new={}\n for paramName in individual.keys():\n encoder = individual[paramName]\n
temp = parsedData[paramName]\n if temp['searchType'] == 'permutation':\n if temp['dataType'] == 'list':\n new[paramName] = [temp['value'][encoder[i]] for i in range(len(encoder))]\n elif temp['dataType'] != 'list':\n new[paramName] = temp['value'].iloc[encoder,:]\n return new\n",
"updateConfigFunction": "\ndef updateConfigFunction(config,data,vars):\n def updateParameter(data,vars):\n vars.globalVars[data['key']]=data['value']\n for key,value in config.items():\n updateParameter(item,vars)\n",
"updateConfig": {},
"after_preprocess": "\ndef after_preprocess(app,data,vars):\n #app.endTime ='10000'\n from des.log import logger\n logger.info('after xxx')\n logger.info(data['param1'])\n vars.globalVars.updateFrom({'source1':data['param1']})\n if app.graph['processConfig']:\n for temp in app.graph['processConfig']:\n if temp['type'] == 'DataSource':\n for config in temp['processInfo'][0]['configs']:\n if config['key'] == 'sourceTye':\n config['value'] = 'table'\n if config['key'] == 'tableKey':\n config['value'] = 'source1'\n"
},
"objective_func": "\ndef gettime(app, vars):\n from des.log import logger\n r=vars.record\n num = 0\n if len(r)>1:\n num=sum([r[i]!=r[i+1] for i in range(len(r)-1)])\n app.objective_result.update({'time':num})\n vars.record=[]\n"
}
],
"processingOrder": "studio/shanglu/share/69126/0988a5d1ac4311edb3d291628633f0cb/processingOrder.csv",
"waitingOrder": "studio/shanglu/share/69126/0988a5d1ac4311edb3d291628633f0cb/waitingOrder.csv",
"plan": "studio/shanglu/share/69126/0988a5d1ac4311edb3d291628633f0cb/plan.csv",
"calendar": "studio/shanglu/share/69126/0988a5d1ac4311edb3d291628633f0cb/calendar.csv"
}

输出信息

[
{
"uuid": "2897d138544e4fa7a1e11c6e2f4dd2b2",
"time": 116
},
{
"uuid": "5ad52db91ea946558bfbd0bc36328847",
"time": 112
}
]

模板链接
https://sp.xuelangyun.com/web/service/predict/69725 通用算法+des工厂模型_订单切换.zip