#
# Collective Knowledge (WA results)
#
# See CK-WA LICENSE.txt for licensing details
# See CK-WA COPYRIGHT.txt for copyright details
#
# Developer: dividiti, grigori@dividiti.com, http://dividiti.com
#
cfg={} # Will be updated by CK (meta description of this module)
work={} # Will be updated by CK (temporal data)
ck=None # Will be updated by CK (initialized CK kernel)
# Local settings
form_name='wa_web_form'
onchange='document.'+form_name+'.submit();'
hextra='
\n'
hextra+='This is an on-going long-term project. Please check our vision [ '
hextra+='ARM TechCon\'16, \n'
hextra+='DATE\'16, \n'
hextra+='CPC\'15, \n'
hextra+='JSP\'14, \n'
hextra+='YouTube ]\n'
hextra+=' and CK-WA GitHub repo for more details!'
hextra+='
\n'
hextra+=' \n'
selector=[{'name':'Scenario', 'key':'scenario'},
{'name':'Workload', 'key':'workload_name'},
{'name':'Platform', 'key':'plat_name'},
{'name':'CPU', 'key':'cpu_name', 'new_line':'yes'},
{'name':'OS', 'key':'os_name'},
{'name':'GPU', 'key':'gpu_name'}]
##############################################################################
# Initialize module
def init(i):
"""
Input: {}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""
return {'return':0}
##############################################################################
# WA dashboard (show results)
def show(i):
"""
Input: {
(crowd_module_uoa) - if rendered from experiment crowdsourcing
(crowd_key) - add extra name to Web keys to avoid overlapping with original crowdsourcing HTML
(crowd_on_change) - reuse onchange doc from original crowdsourcing HTML
}
Output: {
return - return code = 0, if successful
> 0, if error
(error) - error text if return > 0
}
"""
import os
st=''
cmuoa=i.get('crowd_module_uoa','')
ckey=i.get('crowd_key','')
conc=i.get('crowd_on_change','')
if conc=='':
conc=onchange
h='\n'
h+='
\n'
h+='\n\n\n\n'
h+='
All WA results
\n'
h+=hextra
# Check host URL prefix and default module/action
rx=ck.access({'action':'form_url_prefix',
'module_uoa':'wfe',
'host':i.get('host',''),
'port':i.get('port',''),
'template':i.get('template','')})
if rx['return']>0: return rx
url0=rx['url']
template=rx['template']
url=url0
action=i.get('action','')
muoa=i.get('module_uoa','')
st=''
url+='action=index&module_uoa=wfe&native_action='+action+'&'+'native_module_uoa='+muoa
url1=url
# List entries
ii={'action':'search',
'module_uoa':work['self_module_uid'],
'add_meta':'yes'}
if cmuoa!='':
ii['module_uoa']=cmuoa
r=ck.access(ii)
if r['return']>0: return r
lst=r['lst']
# Check unique entries
choices={}
wchoices={}
for q in lst:
d=q['meta']
meta=d.get('meta',{})
for kk in selector:
kx=kk['key']
k=ckey+kx
if k not in choices:
choices[k]=[]
wchoices[k]=[{'name':'','value':''}]
v=meta.get(kx,'')
if v!='':
if v not in choices[k]:
choices[k].append(v)
wchoices[k].append({'name':v, 'value':v})
# Prepare query div ***************************************************************
if cmuoa=='':
# Start form + URL (even when viewing entry)
r=ck.access({'action':'start_form',
'module_uoa':cfg['module_deps']['wfe'],
'url':url1,
'name':form_name})
if r['return']>0: return r
h+=r['html']
for kk in selector:
k=ckey+kk['key']
n=kk['name']
nl=kk.get('new_line','')
if nl=='yes':
h+=' \n\n'
v=''
if i.get(k,'')!='':
v=i[k]
kk['value']=v
# Show hardware
ii={'action':'create_selector',
'module_uoa':cfg['module_deps']['wfe'],
'data':wchoices.get(k,[]),
'name':k,
'onchange':conc,
'skip_sort':'no',
'selected_value':v}
r=ck.access(ii)
if r['return']>0: return r
h+=''+n+': '+r['html'].strip()+'\n'
h+='
'
# Prune list
plst=[]
for q in lst:
d=q['meta']
meta=d.get('meta',{})
# Check selector
skip=False
for kk in selector:
k=kk['key']
n=kk['name']
v=kk.get('value','')
if v!='' and meta.get(k,'')!=v:
skip=True
if not skip:
plst.append(q)
# Check if too many
lplst=len(plst)
if lplst==0:
h+='No results found!'
return {'return':0, 'html':h, 'style':st}
elif lplst>50:
h+='Too many entries to show ('+str(lplst)+') - please, prune list further!'
return {'return':0, 'html':h, 'style':st}
# Prepare table
h+='
\n'
# Dictionary to hold target meta
tm={}
ix=0
bgraph={"0":[]} # Just for graph demo
for q in sorted(plst, key=lambda x: x.get('meta',{}).get('meta',{}).get('workload_name','')):
ix+=1
duid=q['data_uid']
path=q['path']
d=q['meta']
meta=d.get('meta',{})
params=d.get('choices',{}).get('params',{}).get('params',{})
pname=meta.get('program_uoa','')
wname=meta.get('workload_name','')
wuid=meta.get('program_uid','')
apk_name=meta.get('apk_name','')
apk_ver=meta.get('apk_version','')
wa_ver=meta.get('wa_version','')
scenario=meta.get('scenario','')
ltarget_uoa=meta.get('local_target_uoa','')
ltarget_uid=meta.get('local_target_uid','')
if ltarget_uid!='' and ltarget_uid not in tm:
# Load machine meta
rx=ck.access({'action':'load',
'module_uoa':cfg['module_deps']['machine'],
'data_uoa':ltarget_uid})
if rx['return']==0:
tm[ltarget_uid]=rx['dict']
plat_name=meta.get('plat_name','')
cpu_name=meta.get('cpu_name','')
os_name=meta.get('os_name','')
gpu_name=meta.get('gpu_name','')
adb_id=tm.get(ltarget_uid,{}).get('device_id','')
sn=meta.get('serial_number','')
te=d.get('characteristics',{}).get('run',{})
tet=te.get('total_execution_time',0)
bgc='afffaf'
fail=d.get('state',{}).get('fail','')
fail_reason=d.get('state',{}).get('fail_reason','')
if fail=='yes':
if fail_reason=='': fail_reason='yes'
bgc='ffafaf'
else:
if i.get(ckey+'workload_name','')!='' and i.get(ckey+'scenario','')!='':
bgraph['0'].append([ix,tet])
bg=' style="background-color:#'+bgc+';"'
h+='
\n'
x=work['self_module_uid']
if cmuoa!='': x=cmuoa
h+='
\n'
x=plat_name
if ltarget_uid!='':
x=''+x+''
h+='
'+x+'
\n'
x=sn
if adb_id!='' and adb_id!=sn: x+=' / '+adb_id
h+='
'+x+'
\n'
h+='
'+cpu_name+'
\n'
h+='
'+gpu_name+'
\n'
h+='
'+os_name+'
\n'
# APK
x=apk_name
if apk_ver!='': x+=' (V'+apk_ver+')'
# x=x.replace("'","\'").replace('"',"\\'").replace('\n','\\n')
x=x.replace("\'","'").replace("'","\\'").replace('\"','"').replace('"',"\\'").replace('\n','\\n')
x1=''
if x!='':
x1=''
h+='
'+x1+'
\n'
h+='
'+wa_ver+'
\n'
x=fail_reason
if x=='':
x='No'
else:
fail_reason=fail_reason.replace("\'","'").replace("'","\\'").replace('\"','"').replace('"',"\\'").replace('\n','\\n')
x='Yes '
h+='
'+x+'
\n'
# Params
# x='
\n'
x=''
for k in sorted(params):
v=params[k]
x+=str(k)+'='+str(v)+'\n'
# x+='
'+str(k)+'=
'+str(v)+'
\n'
# x+='
\n'
# x=x.replace("'","\'").replace('"',"\\'").replace('\n','\\n')
x=x.replace("\'","'").replace("'","\\'").replace('\"','"').replace('"',"\\'").replace('\n','\\n')
x1=''
if x!='':
x1=''
h+='
'+x1+'
\n'
# Characteristics
# Check if has statistics
dstat={}
fstat=os.path.join(path,'ck-stat-flat-characteristics.json')
if os.path.isfile(fstat):
r=ck.load_json_file({'json_file':fstat, 'dict':dstat})
if r['return']>0: return r
dstat=r['dict']
x=''
if tet>0: x=('%.1f'%tet)+' sec.'
# Check if has stats
x1=dstat.get("##characteristics#run#total_execution_time#center",None)
x2=dstat.get("##characteristics#run#total_execution_time#halfrange",None)
if x1!=None and x2!=None:
x=('%.1f'%x1)+' ± '+('%.1f'%x2)+' sec.'
# Check all
x5=''
for k in sorted(te):
v=te[k]
kx="##characteristics#run#"+k
kx1=dstat.get(kx+'#center',None)
kx2=dstat.get(kx+'#halfrange',None)
x6=''
if type(v)==int:
if kx1!=None and kx2!=None:
x6=str(kx1)+' +- '+str(kx2)
else:
x6=str(v)
elif type(v)==float:
if kx1!=None and kx2!=None:
x6=('%.1f'%kx1)+' +- '+('%.1f'%kx2)
else:
x6=('%.1f'%v)
if x6!='':
x5+=str(k)+'='+x6+'\n'
# x5=x5.replace("'","\'").replace('"',"\\'").replace('\n','\\n')
x5=x5.replace("\'","'").replace("'","\\'").replace('\"','"').replace('"',"\\'").replace('\n','\\n')
if x5!='':
x+=' '
h+='
'+x+'
\n'
# Check directories with results
x=''
xf1='wa-output'
xf2='results.json'
xf=xf1+'/'+xf2
for d0 in os.listdir(path):
found=False
brk=False
d1=os.path.join(d0,xf)
d2=os.path.join(path,d1)
if os.path.isfile(d2):
found=True
else:
d1=xf
d2=os.path.join(path,d1)
if os.path.isfile(d2):
d0=xf1
found=True
brk=True
if found:
if x!='': x+=' \n'
x1=work['self_module_uid']
if cmuoa!='':
x1=cmuoa
x+='[ '+d0+' ]\n'
if brk:
break
h+='
'+x+'
\n'
h+='
\n'
h+='
\n'
h+='
\n'
h+='
\n'
if cmuoa=='':
h+='\n'
if len(bgraph['0'])>0:
ii={'action':'plot',
'module_uoa':cfg['module_deps']['graph'],
"table":bgraph,
"h_lines":[1.0],
"ymin":0,
"ignore_point_if_none":"yes",
"plot_type":"d3_2d_bars",
"display_y_error_bar":"no",
"title":"Powered by Collective Knowledge",
"axis_x_desc":"Platform",
"axis_y_desc":"Execution time (sec.)",
"plot_grid":"yes",
"d3_div":"ck_interactive",
"image_width":"900",
"image_height":"400",
"wfe_url":url0}
r=ck.access(ii)
if r['return']==0:
x=r.get('html','')
if x!='':
st+=r.get('style','')
h+=' \n'
h+='