Tuesday, March 13, 2018

Re: sorting file content by third numbered column

Le mardi 13 mars 2018 14:34:20 UTC+1, Christian Brabandt a écrit :
> On Di, 13 Mär 2018, Ni Va wrote:
>
> > By Total time column for example.
>
> Sorry, I find your answers in general too terse to try to figure out
> what exactly you are trying to do now and I do not feel like guessing.
>
> It looks as you'd like to sort buffer content, while you were saying
> before you want to sort lists.
>
> Oh and BTW: please trim your quotes and write your statement below to
> what you are referring to.
>
> Thanks,
> Christian
> --
> Der gesunde Menschenverstand ist blind sowohl für das äußerst Böse
> wie für das höchst Gute.
> -- Karl Jaspers

The csv file attached below it produced from this code particularly by from s:results list of strings.

I import it into excel and then do a sort from max to min spent time by third column.

I would do the same from this vimscript below on in order to sort by numeric float Total time column



fun! helper#ybereportstats_timebyfunc(list) "{{{


"2. Total time by function
"
let totaltimelist = filter(copy(a:list), 'v:val =~ "TOTAL"')
let pattime = '\(\d\+\:\d\+:\d\+\.\d\+\)'
let patfunc = '\(\S\+()\)'
let pattotaltime = '\(\d\+\(,\d\+\)\{0,1}\)'
let linepat = '^.\{-}'.pattime.'.\{-}'.patfunc.'.\{-}'.pattotaltime.'.\{-}$'
let listtotaltimespent = map(copy(totaltimelist)[0:s:nEch], 'substitute(v:val, linepat, "\\2@\\3@\\1", "")')
" echomsg string(listtotaltimespent)
" return

for value in listtotaltimespent
" k : class/func name
" v : total time for the call..
" t : ..at time
" try
let [k,v,t] = split(value,'@')
" catch /.*/
" echomsg 'error ' . string(value)
" endtry
if !has_key(s:dict,k)
let s:dict[k] = { 'values' : [{'totaltime':v, 'time':t}] }
else
call extend(s:dict[k].values, [{'totaltime':v, 'time':t}])
endif
endfor
" echo s:dict

"
" 2. build results
"
let s:results = [join(["Func","Nb Occs", "Total time (ms)","Indicateur (ms/ech)"],s:sep)]
for funclass in keys(s:dict)
" Sum up total time for N occurs
let nOccur = len(s:dict[funclass].values)

" Sum up total time for N occurs
let sum=0.0
for time in s:dict[funclass].values
" echomsg time.totaltime
let sum+=str2float(substitute(time.totaltime, ',', '.', 'g'))
endfor

" let sumstr = tr(printf("%s",sum),'.',',')
let sumstr = printf("%s",sum)

let indicateur=printf("%s",sum/nOccur)

call extend(s:results, [funclass.s:sep.string(nOccur).s:sep.sumstr.s:sep.indicateur])
endfor
" echomsg string(s:results)
endfunction "}}}

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment