sorting file content by third numbered column

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

sorting file content by third numbered column

Ni Va
Hi,

I don't happen to sort this kind of list by the third float numbered column.



Foo..ctor() 1 10.4901 10.4901
Bar() 2 0.132 0.066
FooBar.set_foo() 173 6.6418 0.038392
Foo.set_bar() 2 0.2234 0.1117
FooBar.Calc() 358 1164.8912 3.253886


--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Timothy Rice
Personally, I would pipe it through an external command, eg:

  :%! sort -n -k3

Within Vim on a Linux box that command results in text roughly like so for
me:

Bar()               2      0.132    0.066
Foo.set_bar()       2      0.2234   0.1117
FooBar.set_foo()  173      6.6418   0.038392
Foo..ctor()         1     10.4901  10.4901
FooBar.Calc()     358   1164.8912   3.253886

(I've manually inserted some space for readability reasons.)

~ Tim


On Mon, Mar 12, 2018 at 01:50:41PM -0700, Ni Va wrote:

> Hi,
>
> I don't happen to sort this kind of list by the third float numbered column.
>
>
>
> Foo..ctor()    1    10.4901    10.4901
> Bar()    2    0.132    0.066
> FooBar.set_foo()    173    6.6418    0.038392
> Foo.set_bar()    2    0.2234    0.1117
> FooBar.Calc()    358    1164.8912    3.253886
>
>
> --
> --
> 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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Ni Va
Le lundi 12 mars 2018 22:19:41 UTC+1, Tim Rice a écrit :

> Personally, I would pipe it through an external command, eg:
>
>   :%! sort -n -k3
>
> Within Vim on a Linux box that command results in text roughly like so for
> me:
>
> Bar()               2      0.132    0.066
> Foo.set_bar()       2      0.2234   0.1117
> FooBar.set_foo()  173      6.6418   0.038392
> Foo..ctor()         1     10.4901  10.4901
> FooBar.Calc()     358   1164.8912   3.253886
>
> (I've manually inserted some space for readability reasons.)
>
> ~ Tim
>
>
> On Mon, Mar 12, 2018 at 01:50:41PM -0700, Ni Va wrote:
> > Hi,
> >
> > I don't happen to sort this kind of list by the third float numbered column.
> >
> >
> >
> > Foo..ctor()    1    10.4901    10.4901
> > Bar()    2    0.132    0.066
> > FooBar.set_foo()    173    6.6418    0.038392
> > Foo.set_bar()    2    0.2234    0.1117
> > FooBar.Calc()    358    1164.8912    3.253886
> >
> >
> > --
> > --
> > 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 [hidden email].
> > For more options, visit https://groups.google.com/d/optout.
Thanks but it's a list content not a buffer content in my case.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Christian Brabandt

On Mo, 12 Mär 2018, Ni Va wrote:

> Thanks but it's a list content not a buffer content in my case.

Write a custom Sort Function, that splits() your content and sorts on
the third field?

BTW: Please provide complete exact examples. Makes it easier to
understand you and test.

Best,
Christian
--
Fast alles, was Menschen erfinden, wird früher oder später zur Waffe.
Ist das wirklich nicht zu verhindern?
                -- Linus Pauling

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Ni Va
Le mardi 13 mars 2018 12:18:31 UTC+1, Christian Brabandt a écrit :

> On Mo, 12 Mär 2018, Ni Va wrote:
>
> > Thanks but it's a list content not a buffer content in my case.
>
> Write a custom Sort Function, that splits() your content and sorts on
> the third field?
>
> BTW: Please provide complete exact examples. Makes it easier to
> understand you and test.
>
> Best,
> Christian
> --
> Fast alles, was Menschen erfinden, wird früher oder später zur Waffe.
> Ist das wirklich nicht zu verhindern?
> -- Linus Pauling
By Total time column for example.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

2018_03_09_11_39_51.981_TracesProfilage_1.csv (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Christian Brabandt

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

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Ni Va
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Erik Christiansen
On 13.03.18 07:41, Ni Va wrote:
> 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

[Miles long inscrutably complex vimscript elided.]

Vim is not emacs, so it does not burden itself with diverse
functionality in the same way - and yet it has an inbuilt sort. OK, that
apparently does not suffice for your requirements.

Then the task is much more efficiently executed by existing tools
designed for it. Have a look at "man sort". In a single short command
line, you can replace all the wasteful complexity of a miles long
inscrutable vimscript, instead handling which field to sort on, field
separator, forward/reverse sort, numeric or alpha, etc. I repeat, one
short line.

A hammer can be used as a screwdriver, but only if you treat the screw
as a nail. Results are likely to be disappointing.

Erik

--
I have yet to see any problem, however complicated, which, when you
looked at it in the right way, did not become still more complicated.          
                                                         - Poul Anderson

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Christian Brabandt
In reply to this post by Ni Va

On Di, 13 Mär 2018, Ni Va wrote:

> > Oh and BTW: please trim your quotes and write your statement below to
> > what you are referring to.

Please trim your quotes.

Have you tried using a custom compare function similar to what is
written to the help at :h sort()?

BTW: please provide a minimal working example of what problem you are
trying to solve. I am not trying to debug your complex script. Sorry.


Best,
Christian
--
Es ist nicht genug, der Natur die Daumenschrauben anzulegen.
Man muß auch hinhören, wenn sie aussagt.
                -- Arthur Schopenhauer

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Ni Va
I have done this explained before. Dict that have total time in key and csv line in value.

Then I can do a  reverse(sort( numerical order but I would like to retrieve values and the code above retrieve keys sorted.....
so I need the last step.

.
.
   let line = funclass.s:sep.string(nOccur).s:sep.sumstr.s:sep.indicateur
   call extend(s:sorted_by_total_time, {sumstr : line})

  endfor
 
let s:results_by_total_time = reverse(sort(keys(s:sorted_by_total_time),'N'))




2018-03-14 8:53 GMT+01:00 Christian Brabandt <[hidden email]>:

On Di, 13 Mär 2018, Ni Va wrote:

> > Oh and BTW: please trim your quotes and write your statement below to
> > what you are referring to.

Please trim your quotes.

Have you tried using a custom compare function similar to what is
written to the help at :h sort()?

BTW: please provide a minimal working example of what problem you are
trying to solve. I am not trying to debug your complex script. Sorry.


Best,
Christian
--
Es ist nicht genug, der Natur die Daumenschrauben anzulegen.
Man muß auch hinhören, wenn sie aussagt.
                -- Arthur Schopenhauer

--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/rjR-W-7MQNc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: sorting file content by third numbered column

Ni Va
Le mercredi 14 mars 2018 09:31:24 UTC+1, Ni Va a écrit :

> I have done this explained before. Dict that have total time in key and csv line in value.
>
>
> Then I can do a  reverse(sort( numerical order but I would like to retrieve values and the code above retrieve keys sorted.....
> so I need the last step.
>
>
> .
> .
>
>    let line = funclass.s:sep.string(nOccur).s:sep.sumstr.s:sep.indicateur
>    call extend(s:sorted_by_total_time, {sumstr : line})
>
>   endfor
>  
>  let s:results_by_total_time = reverse(sort(keys(s:sorted_by_total_time),'N'))
>
>
>
>
>
>
>
>
>
> 2018-03-14 8:53 GMT+01:00 Christian Brabandt <[hidden email]>:
>
>
> On Di, 13 Mär 2018, Ni Va wrote:
>
>
>
> > > Oh and BTW: please trim your quotes and write your statement below to
>
> > > what you are referring to.
>
>
>
> Please trim your quotes.
>
>
>
> Have you tried using a custom compare function similar to what is
>
> written to the help at :h sort()?
>
>
>
> BTW: please provide a minimal working example of what problem you are
>
> trying to solve. I am not trying to debug your complex script. Sorry.
>
>
>
>
>
> Best,
>
> Christian
>
> --
>
> Es ist nicht genug, der Natur die Daumenschrauben anzulegen.
>
> Man muß auch hinhören, wenn sie aussagt.
>
>                 -- Arthur Schopenhauer
>
>
>
>
>
> --
>
> --
>
> 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 a topic in the Google Groups "vim_use" group.
>
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/rjR-W-7MQNc/unsubscribe.
>
> To unsubscribe from this group and all its topics, send an email to [hidden email].
>
> For more options, visit https://groups.google.com/d/optout.
Would like to use map( but this seems to do the job.

  let s:results_by_total_time = []
  for key in reverse(sort(keys(copy(s:sorted_by_total_time  )),'N'))
   call add(s:results_by_total_time, s:sorted_by_total_time[key])
  endfor

Thank you.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.