Repository: spyder-ide/spyder

Issue:
Sorting order of profiler is wrong
## Description of your problem

**What steps will reproduce the problem?**

1. Run the profiler
2. Look at the results

**What is the expected output? What do you see instead?**

![grafik](https://cloud.githubusercontent.com/assets/1866703/22251819/6d414aa4-e24c-11e6-83f3-5b65f4be1c28.png)

I would expect that the ```test_big``` function is the first entry as it takes 10 sec.

**Please provide any additional information below**


## Versions and main components

* Spyder Version: 3.1.1
* Python Version: 3.5.2 
* Operating system: Ubuntu 16.04


## Dependencies

jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.3 (OK)
nbconvert >=4.0  :  5.1.1 (OK)
numpy >=1.7      :  1.12.0 (OK)
pandas >=0.13.1  :  0.18.1 (OK)
pep8 >=0.6       :  1.7.0 (OK)
psutil >=0.3     :  5.0.1 (OK)
pyflakes >=0.6.0 :  1.5.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.6.5 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
sphinx >=0.6.6   :  1.5.2 (OK)
sympy >=0.7.3    :  None (NOK)



Discussion:
@mariacamilaremolinagutierrez, please work on this one.
Can confirm in 3.1.4: The sort order of Total Time and Local Time is alphabetical instead of numerical.
Thanks, we'll take a look at this after we release Spyder 3.2 (in a couple of weeks).

Resolving patch:
diff --git a/spyder_profiler/widgets/profilergui.py b/spyder_profiler/widgets/profilergui.py
--- a/spyder_profiler/widgets/profilergui.py
+++ b/spyder_profiler/widgets/profilergui.py
@@ -19,6 +19,7 @@
 import os.path as osp
 import sys
 import time
+import re
 
 # Third party imports
 from qtpy.compat import getopenfilename, getsavefilename
@@ -351,6 +352,30 @@ def show_data(self, justanalyzed=False):
                                                time.localtime())
         self.datelabel.setText(date_text)
 
+def gettime_s(text):
+    """Parse text and returns a time in seconds
+    
+    The text is of the format 0h : 0.min:0.0s:0 ms:0us:0 ns. 
+    Spaces are not taken into account and any of the specifiers can be ignored"""
+    pattern = '([+-]?\d+\.?\d*) ?([munsecinh]+)'
+    matches = re.findall(pattern, text)
+    if len(matches) == 0:
+        return None
+    time = 0.
+    for res in matches:
+        tmp = float(res[0])
+        if res[1] == 'ns':
+            tmp *= 1e-9
+        elif res[1] == 'us':
+            tmp *= 1e-6
+        elif res[1] == 'ms':
+            tmp *= 1e-3
+        elif res[1] == 'min':
+            tmp *= 60
+        elif res[1] == 'h':
+            tmp *= 3600
+        time += tmp
+    return time
 
 class TreeWidgetItem( QTreeWidgetItem ):
     def __init__(self, parent=None):
@@ -359,11 +384,16 @@ def __init__(self, parent=None):
     def __lt__(self, otherItem):
         column = self.treeWidget().sortColumn()
         try:
+            if column == 1 or column == 3: #TODO: Hardcoded Column
+                t0 = gettime_s(self.text(column))
+                t1 = gettime_s(otherItem.text(column))
+                if t0 is not None and t1 is not None:
+                    return t0 > t1
+            
             return float( self.text(column) ) > float( otherItem.text(column) )
         except ValueError:
             return self.text(column) > otherItem.text(column)
 
-
 class ProfilerDataTree(QTreeWidget):
     """
     Convenience tree widget (with built-in model) 


Test patch: