Last active
May 4, 2017 15:32
-
-
Save lovasoa/2138149aeef60c4fad5ffd3ecc35579c to your computer and use it in GitHub Desktop.
Quick-and-dirty command-line editor for WiMi model files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<model description="Model 1" formatXmlVersion="2.0" id="{ed7a8cc7-38a3-4ca4-8373-751d7374bc9e}" shortName="Model 1"> | |
<class id="{1f381b22-438a-4243-987c-51fdd36758a8}" shortName="Model 1"> | |
<parameters /> | |
<rules> | |
<rule description="tk=0,5(tk1+tk2)" id="005516d4-2cbf-4e6d-9836-70c2e424e4a6" initId="b:cb01c927-966b-433a-a53a-30e6b9f5ba51;c:3e35e46f-c897-4376-93c9-d83d9910942e" relation="dbae2f6c-b823-4e27-9067-080feece5355" resultId="a:478c281f-8d74-48ac-87ed-cb57ed515049" shortName="tk(среднее значение времени обработки запроса в канале передачи данных)" /> | |
<rule id="2cedfec1-9f66-4684-b84b-ab842827d4ce" initId="T0:7e954f2b-1ed2-4273-beeb-993a9f0e7d4c;Td:a4044004-c43b-4962-80e2-2de5fea1cca1;Tp:fc34e5e5-a77a-4891-ab01-c15d730ca825;Tk:478c281f-8d74-48ac-87ed-cb57ed515049;Tcpu:5330e86c-2d69-431e-b6e0-975faa5514ac" relation="cce0f96c-9f3a-4339-9cdb-b46542c66475" resultId="Tloop:26ff6ad3-378d-4ed2-813b-9a468930efe1" shortName="Время цикла системы" /> | |
<rule description="x1=Tp x2=Tk x3=Tcpu x4=Td" id="705851a9-8cd0-429f-a6b2-8e7648191d79" initId="x3:5330e86c-2d69-431e-b6e0-975faa5514ac;x1:fc34e5e5-a77a-4891-ab01-c15d730ca825;x4:a4044004-c43b-4962-80e2-2de5fea1cca1;x2:4aa1217f-1dc5-4cba-80e2-8c7506832bfd" relation="08c7625d-3112-4abb-ba93-9db817818ac2" resultId="y:5398ba9f-0000-4533-a75f-81d9beef799a" shortName="Tr=Tp+Tk+Tcpu+Td" /> | |
<rule description="работа в цикле" id="8f15f5f3-1ce0-44bc-8175-48ad0450cceb" initId="K2:64bf1047-d735-422a-9ffb-da5c685b3bab;tk:478c281f-8d74-48ac-87ed-cb57ed515049;T0:7e954f2b-1ed2-4273-beeb-993a9f0e7d4c;b:c22dd349-c37c-40ba-83c0-4f3041f07b2e;tdi:0ecaf57c-8fff-4986-8416-f49035b3d898;K1:c24ac627-80d8-4f31-8ae8-c7beed09de3c;delta:11620d32-fefc-45a2-93af-50cb93939993;Tp:fc34e5e5-a77a-4891-ab01-c15d730ca825;min:a7537ebe-1ce9-4a81-be70-83a9d865ae61;Pi:8d63fa7f-e2f0-4f42-91c0-961c5bb399a7;C:18bd7b85-adc2-479e-98ee-04aa6e5c98f2;N:33ae3033-1a44-44f5-a5eb-b9b51841e313;tcpu:3340086e-ed00-4a32-b395-ae6372b576c6" relation="7bb0321e-8f86-4688-b38d-a510a88d9def" resultId="Td:a4044004-c43b-4962-80e2-2de5fea1cca1;i:eab37a07-3278-4baa-b5d1-e7f3949acc76;Tk:4aa1217f-1dc5-4cba-80e2-8c7506832bfd;Tcpu:5330e86c-2d69-431e-b6e0-975faa5514ac" shortName="работа в цикле" /> | |
<rule description="Pi=1/m;" id="98d7472e-1eee-49ab-a054-98a3cb4590c5" initId="x:684d9d5f-a365-42c8-adaa-ef299f2e1731" relation="7bcf58d9-da31-4571-8f92-712ec06dd50c" resultId="y:8d63fa7f-e2f0-4f42-91c0-961c5bb399a7" shortName="вероятность обращения к i-му диску сервера" /> | |
<rule description="b=1/(1–р);" id="da015ead-513f-4510-ab4a-6dde8a0af348" initId="x:0c791744-9c82-4f33-96f5-d46336922e67" relation="76b74a59-3140-446b-9d37-aabaf7bc4606" resultId="y:c22dd349-c37c-40ba-83c0-4f3041f07b2e" shortName="b - среднее количество проходов запроса по тракту процессор-диски за время одного цикла его обработки в системе." /> | |
<rule description="l=N/Tloop" id="1095002577864842" initId="N:33ae3033-1a44-44f5-a5eb-b9b51841e313;Tloop:26ff6ad3-378d-4ed2-813b-9a468930efe1" relation="306511601108597" resultId="l:549207159730024" shortName="l=N/Tloop" /><rule description="Ppc=(T0+Tp)/Tloop" id="166083959164990" initId="T0:7e954f2b-1ed2-4273-beeb-993a9f0e7d4c;Tp:fc34e5e5-a77a-4891-ab01-c15d730ca825;Tloop:26ff6ad3-378d-4ed2-813b-9a468930efe1" relation="881552089504519" resultId="Ppc:a29ace9b-8fa4-4225-9640-97f0e37939d3" shortName="Ppc=(T0+Tp)/Tloop" /><rule description="Pu=Tp/Tloop" id="359302515792228" initId="Tp:fc34e5e5-a77a-4891-ab01-c15d730ca825;Tloop:26ff6ad3-378d-4ed2-813b-9a468930efe1" relation="1090890814876914" resultId="Pu:abedfadb-4bea-4672-95f5-fd86a222a03b" shortName="Pu=Tp/Tloop" /><rule description="PoK=2*l*tk" id="833625036276158" initId="l:549207159730024;tk:478c281f-8d74-48ac-87ed-cb57ed515049" relation="1004269695762317" resultId="PoK:aa0b3cbb-0915-46c7-a02c-e9262c6d6f16" shortName="PoK=2*l*tk" /><rule description="PoCPU=b*l*Tcpu/C" id="722613910153452" initId="b:473627708087716;l:549207159730024;Tcpu:3340086e-ed00-4a32-b395-ae6372b576c6;C:18bd7b85-adc2-479e-98ee-04aa6e5c98f2" relation="690151726131898" resultId="PoCPU:53e064d4-e1b7-4bba-adc5-2ea619f8572b" shortName="PoCPU=b*l*Tcpu/C" /><rule description="PoDi=b*l*Pi*Tdi" id="1040185643828155" initId="b:473627708087716;l:549207159730024;Pi:8d63fa7f-e2f0-4f42-91c0-961c5bb399a7;Tdi:0ecaf57c-8fff-4986-8416-f49035b3d898" relation="262082675732378" resultId="PoDi:9e8bb8c1-bbeb-4b43-9494-c2a998e0f2df" shortName="PoDi=b*l*Pi*Tdi" /></rules> | |
<constraints /> | |
<classes> | |
<class id="643ba325-9de2-4ea1-819f-ccf9fe24da23" shortName="исходные данные"> | |
<parameters> | |
<parameter id="0c791744-9c82-4f33-96f5-d46336922e67" shortName="G" type="double" /> | |
<parameter id="0ecaf57c-8fff-4986-8416-f49035b3d898" shortName="Tdi" type="double" /> | |
<parameter id="11620d32-fefc-45a2-93af-50cb93939993" shortName="delta" type="double" /> | |
<parameter description="Число процессоров сервера" id="18bd7b85-adc2-479e-98ee-04aa6e5c98f2" shortName="C" type="double" /> | |
<parameter id="3340086e-ed00-4a32-b395-ae6372b576c6" shortName="Tcpu" type="double" /> | |
<parameter id="33ae3033-1a44-44f5-a5eb-b9b51841e313" shortName="N" type="double" /> | |
<parameter id="3e35e46f-c897-4376-93c9-d83d9910942e" shortName="tk2" type="double" /> | |
<parameter id="64bf1047-d735-422a-9ffb-da5c685b3bab" shortName="K2" type="double" /> | |
<parameter id="684d9d5f-a365-42c8-adaa-ef299f2e1731" shortName="M" type="double" /> | |
<parameter id="7e954f2b-1ed2-4273-beeb-993a9f0e7d4c" shortName="T0" type="double" /> | |
<parameter id="c24ac627-80d8-4f31-8ae8-c7beed09de3c" shortName="K1" type="double" /> | |
<parameter id="cb01c927-966b-433a-a53a-30e6b9f5ba51" shortName="tk1" type="double" /> | |
<parameter id="fc34e5e5-a77a-4891-ab01-c15d730ca825" shortName="Tp" type="double" /> | |
</parameters> | |
<rules /> | |
<constraints> | |
<constraint description="К2 принимает значения в диапазоне 10…1000" id="227c7c14-d644-4528-a5f9-7ff93f38c7d3" initId="a:64bf1047-d735-422a-9ffb-da5c685b3bab" relation="51bc4f9f-2380-4029-bfb7-d5017fa25fbf" shortName="К2 >= 10" /> | |
<constraint description="К1 принимает значения в диапазоне 0.995…0.99995." id="3ee78c0a-a4d0-41d2-885c-ab50125109da" initId="a:c24ac627-80d8-4f31-8ae8-c7beed09de3c" relation="9d72dc3b-d8ee-41bb-88a5-a0f488a24c66" shortName="К1 принимает значения в диапазоне 0.995…0.99995." /> | |
<constraint description="К2 принимает значения в диапазоне 10…1000" id="7ac4c662-c708-4564-b1f8-6e2a89a921d5" initId="a:64bf1047-d735-422a-9ffb-da5c685b3bab" relation="e81bc1df-959b-43dc-b612-f107a19e0a8a" shortName="К2<= 10…1000" /> | |
<constraint description="К1 принимает значения в диапазоне 0.995…0.99995." id="c1fb979a-c69c-47f7-af2b-f13c34d74276" initId="a:c24ac627-80d8-4f31-8ae8-c7beed09de3c" relation="1aa44029-4952-4786-afc2-7bc38cb37fc8" shortName="К1 принимает значения в диапазоне 0.995…0.99995." /> | |
<constraint id="e45c47fa-f9f3-4d48-9aac-f4661c599986" initId="a:0c791744-9c82-4f33-96f5-d46336922e67" relation="74e0caea-a84e-4cc1-9938-1a4034b26ec0" shortName="G<1" /> | |
<constraint description="G-вероятность обращения запроса к ЦП после обработки на диске >=0" id="ea73abd6-b7c5-4331-8b5b-25962c91a44b" initId="a:0c791744-9c82-4f33-96f5-d46336922e67" relation="8d674b96-7bf2-4c6f-85b9-9b5cd534dbef" shortName="G >=0" /> | |
</constraints> | |
<classes /> | |
</class> | |
<class id="8792e3e9-ed66-414d-a7f2-47b5ccf7e372" shortName="выходные данные"> | |
<parameters> | |
<parameter id="26ff6ad3-378d-4ed2-813b-9a468930efe1" shortName="Tloop" type="double" /> | |
<parameter id="5398ba9f-0000-4533-a75f-81d9beef799a" shortName="Tr" type="double" /> | |
<parameter id="53e064d4-e1b7-4bba-adc5-2ea619f8572b" shortName="PoCPU" type="double" /> | |
<parameter id="9e8bb8c1-bbeb-4b43-9494-c2a998e0f2df" shortName="PoDi" type="double" /> | |
<parameter id="a29ace9b-8fa4-4225-9640-97f0e37939d3" shortName="Ppc" type="double" /> | |
<parameter id="aa0b3cbb-0915-46c7-a02c-e9262c6d6f16" shortName="PoK" type="double" /> | |
<parameter id="abedfadb-4bea-4672-95f5-fd86a222a03b" shortName="Pu" type="double" /> | |
</parameters> | |
<rules /> | |
<constraints /> | |
<classes /> | |
</class> | |
<class id="e851b32d-f81a-4ac5-b08f-cbb6121012c9" shortName="фоновый поток"> | |
<parameters> | |
<parameter id="478c281f-8d74-48ac-87ed-cb57ed515049" shortName="tk" type="double" /> | |
<parameter id="8d63fa7f-e2f0-4f42-91c0-961c5bb399a7" shortName="Pi" type="double" /> | |
<parameter id="a7537ebe-1ce9-4a81-be70-83a9d865ae61" shortName="Min" type="double" /> | |
<parameter id="c22dd349-c37c-40ba-83c0-4f3041f07b2e" shortName="β" type="double" /> | |
</parameters> | |
<rules /> | |
<constraints /> | |
<classes> | |
<class id="bfb56e94-605d-4fd1-a5ca-1d7d30713bf7" shortName="Работа в цикле"> | |
<parameters> | |
<parameter id="4aa1217f-1dc5-4cba-80e2-8c7506832bfd" shortName="T" type="double" /> | |
<parameter id="5330e86c-2d69-431e-b6e0-975faa5514ac" shortName="Tcpu" type="double" /> | |
<parameter id="a4044004-c43b-4962-80e2-2de5fea1cca1" shortName="Td" type="double" /> | |
<parameter id="eab37a07-3278-4baa-b5d1-e7f3949acc76" shortName="I" type="double" /> | |
</parameters> | |
<rules /> | |
<constraints /> | |
<classes /> | |
</class> | |
</classes> | |
</class> | |
<class id="647222253480327" shortName="intermediate parameters"><parameters><parameter id="549207159730024" shortName="l" type="double" /><parameter id="473627708087716" shortName="b" type="double" /></parameters></class></classes> | |
</class> | |
<relations> | |
<relation description="Tr=Tp+Tk+Tcpu+Td" id="08c7625d-3112-4abb-ba93-9db817818ac2" inObj="x3:double;x1:double;x4:double;x2:double" outObj="y:double" relationType="simple" shortName="y=x1+x2+x3+x4">y=x1+x2+x3+x4</relation> | |
<relation id="1aa44029-4952-4786-afc2-7bc38cb37fc8" inObj="a:double" outObj="flag:double" relationType="constr" shortName="a<=0,99995">if (a<=0,99995) {flag = true;} else {flag = false;}</relation> | |
<relation id="51bc4f9f-2380-4029-bfb7-d5017fa25fbf" inObj="a:double" outObj="flag:double" relationType="constr" shortName="a>=10">if (a>=10) {flag = true;} else {flag = false;}</relation> | |
<relation id="74e0caea-a84e-4cc1-9938-1a4034b26ec0" inObj="a:double" outObj="flag:double" relationType="constr" shortName="a<1">if (a<1) {flag = true;} else {flag = false;}</relation> | |
<relation id="76b74a59-3140-446b-9d37-aabaf7bc4606" inObj="x:double" outObj="y:double" relationType="simple" shortName="y=1/(1-x)">y=1/(1-x)</relation> | |
<relation id="7bb0321e-8f86-4688-b38d-a510a88d9def" inObj="K2:double;tk:double;T0:double;b:double;tdi:double;K1:double;delta:double;Tp:double;min:double;Pi:double;C:double;N:double;tcpu:double" outObj="Td:double;i:double;Tk:double;Tcpu:double" relationType="prog" shortName="slozh_otn_3">var delta, sigma, i, Lf1, Lf2, Lf, K1,K2,min,temp, tk, b, tcpu, C, tdi,Pi,N,T0,Tp,Tk,Tcpu,Td; | |
Lf2=K1*min*(N-1)/N; | |
temp=2; | |
i=0; | |
d=i; | |
while (temp>delta) | |
{ | |
d=i+1; | |
i=d; | |
Tk=2*tk/(1-2*Lf2*tk); | |
Tcpu=b*tcpu/(1-Math.pow(b*Lf2*tcpu/C,C)); | |
Td=b*tdi/(1-b*Pi*Lf2*tdi); | |
Lf=(N-1)/(T0+Tp+Tk+Tcpu+Td); | |
sigma=(Lf2-Lf)/K2; | |
Lf1=Lf2; | |
Lf2=Lf1-sigma; | |
temp=Math.abs((Lf1-Lf)/Lf); | |
} | |
Tk=2*tk/(1-2*Lf1*tk); | |
Tcpu=b*tcpu/(1-Math.pow(b*Lf1*tcpu/C,C)); | |
Td=b*tdi/(1-b*Pi*Lf1*tdi); | |
</relation> | |
<relation id="7bcf58d9-da31-4571-8f92-712ec06dd50c" inObj="x:double" outObj="y:double" relationType="simple" shortName="y=1/x">y=1/x</relation> | |
<relation id="8d674b96-7bf2-4c6f-85b9-9b5cd534dbef" inObj="a:double" outObj="flag:double" relationType="constr" shortName="a>=0">if (a>=0) {flag = true;} else {flag = false;}</relation> | |
<relation id="8e9c3f28-77a4-4176-836a-f14ffba2aa5b" inObj="z1:double;x5:double;x3:double;x7:double;x8:double;x10:double;z:double;b:double;x1:double;x6:double;x9:double;x4:double;x2:double" outObj="y5:double;y1:double;y2:double;y6:double;y3:double;y4:double" relationType="prog" shortName="y1=x1+x2+x3+x4+x5;">var y1, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, y1, y1, y3, y4, y5, y6, z, z1, b; | |
y1=x1+x2+x3+x4+x5; | |
z=z1/y1; | |
y2=(x1+x2)/y1; | |
y3=x2/y1; | |
y4=2*z*x6; | |
y5=b*z*x7/x8; | |
y6=b*z*x9*x10;</relation> | |
<relation id="9d72dc3b-d8ee-41bb-88a5-a0f488a24c66" inObj="a:double" outObj="flag:double" relationType="constr" shortName="a>=0,995">if (a>=0,995) {flag = true;} else {flag = false;}</relation> | |
<relation description="Tloop=T0+Tp+Tk+Tcpu+Td" id="cce0f96c-9f3a-4339-9cdb-b46542c66475" inObj="T0:double;Td:double;Tp:double;Tk:double;Tcpu:double" outObj="Tloop:double" relationType="simple" shortName="Tloop=T0+Tp+Tk+Tcpu+Td">Tloop=T0+Tp+Tk+Tcpu+Td</relation> | |
<relation id="d3ee275e-39ef-4f9f-a644-c10202f65d47" inObj="tk:double;bL:double;Pi:double;td:double;CL:double;tp:double" outObj="D:double" relationType="prog" shortName="slozhnoe_otnosh_2">var tk,CL, bL, Pi, td, tp, D | |
if (tk==0) | |
{a=999999} | |
else a=1/(2*tk); | |
b=CL/(bL*tp); | |
c=1/(bL*Pi*td); | |
if (a<b) {if (a<c) {d=a;} else d=c;} | |
else { if (b<c) {d=b;} else d=c;} elsed=b;</relation> | |
<relation id="dbae2f6c-b823-4e27-9067-080feece5355" inObj="b:double;c:double" outObj="a:double" relationType="simple" shortName="a=(b+c)/2">a=(b+c)/2</relation> | |
<relation id="e81bc1df-959b-43dc-b612-f107a19e0a8a" inObj="a:double" outObj="flag:double" relationType="constr" shortName="a<=1000">if (a<=1000) {flag = true;} else {flag = false;}</relation> | |
<relation id="306511601108597" inObj="N:double;Tloop:double" outObj="l:double" relationType="simple" shortName="l=N/Tloop">l=N/Tloop</relation><relation id="881552089504519" inObj="T0:double;Tp:double;Tloop:double" outObj="Ppc:double" relationType="simple" shortName="Ppc=(T0+Tp)/Tloop">Ppc=(T0+Tp)/Tloop</relation><relation id="1090890814876914" inObj="Tp:double;Tloop:double" outObj="Pu:double" relationType="simple" shortName="Pu=Tp/Tloop">Pu=Tp/Tloop</relation><relation id="1004269695762317" inObj="l:double;tk:double" outObj="PoK:double" relationType="simple" shortName="PoK=2*l*tk">PoK=2*l*tk</relation><relation id="690151726131898" inObj="b:double;l:double;Tcpu:double;C:double" outObj="PoCPU:double" relationType="simple" shortName="PoCPU=b*l*Tcpu/C">PoCPU=b*l*Tcpu/C</relation><relation id="262082675732378" inObj="b:double;l:double;Pi:double;Tdi:double" outObj="PoDi:double" relationType="simple" shortName="PoDi=b*l*Pi*Tdi">PoDi=b*l*Pi*Tdi</relation></relations> | |
</model> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import xml.etree.ElementTree as ET | |
import random, re | |
tree = ET.parse('new-rules.xml') | |
root = tree.getroot() | |
class NoSuchParameter(BaseException): pass | |
def getParams(): | |
els = root.iterfind(".//parameter") | |
return sorted(map(lambda el:el.get("shortName"), els)) | |
def getParam(name): | |
res = root.find(".//parameter[@shortName='%s']" % (name,)) | |
if res==None: res = add_param(name) | |
return res | |
def add_param(name): | |
print("creating param: ", name) | |
pclass = root.find(".//class[@shortName='intermediate parameters']") | |
if pclass==None: | |
pclass=ET.SubElement(root.find("./class/classes"), "class", | |
id=randomId(), | |
shortName="intermediate parameters") | |
parameters=pclass.find("./parameters") | |
if parameters == None: | |
parameters = ET.SubElement(pclass, "parameters") | |
return ET.SubElement(parameters, "parameter", | |
id=randomId(), | |
shortName=name, | |
type="double") | |
def fParam(paramName): | |
return lambda el:el.get(paramName) | |
def parseFormula(f): | |
args = re.split("\W", f) | |
obj = getParam(args[0]) | |
params = [getParam(arg) for arg in args[1:] if re.match("[a-zA-Z]", arg)] | |
return (obj, params) | |
def zipWithProps(objs, propName): | |
os = zip(map(fParam("shortName"), objs), map(fParam(propName), objs)) | |
return ";".join(map(lambda xs:"%s:%s"%xs, os)) | |
def randomId(): | |
return str(random.getrandbits(50)) | |
def makeOfKind(kind, attrs): | |
parent = root.find(".//%ss"%(kind,)) | |
return ET.SubElement(parent, kind, attrs) | |
def makerelation(formula): | |
result, params = parseFormula(formula) | |
relId = randomId() | |
relation = makeOfKind("relation", { | |
"id": relId, | |
"shortName": formula, | |
"relationType": "simple", | |
"outObj": zipWithProps([result], "type"), | |
"inObj": zipWithProps(params, "type") | |
}) | |
relation.text = formula | |
rule = makeOfKind("rule", { | |
"id": randomId(), | |
"shortName": formula, | |
"relation": relId, | |
"resultId": zipWithProps([result], "id"), | |
"initId": zipWithProps(params, "id"), | |
"description": formula | |
}) | |
print("params: ", getParams()) | |
print("relations: ", sorted(el.get("shortName") for el in root.iterfind(".//relation"))) | |
while True: | |
try: formula = input("formula> ") | |
except EOFError: break; | |
try: | |
makerelation(formula) | |
tree.write("new-rules.xml") | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment