In [137]:
import numpy as np
import pandas as pd
import scipy.stats as stats
from matplotlib import pyplot as plt
import matplotlib.pylab as pylab
import seaborn as sns
import json
pylab.rcParams['figure.figsize'] = 16, 12
%matplotlib inline

In [136]:
y = np.random.randn(100)
plt.plot(y)
plt.autoscale(tight='x')
plt.tight_layout()



In [21]:
df = pd.read_json('/tmp/1.json', orient='index')
df


Out[21]:
endTime groupBy helpOpenedFromPopup markTabFromHotkey markTabFromPanelTree markTabFromPopup markTabFromVisualization openFrequentFromPopup openRecentFromPopup popupOpened startTime switchToMarkedTabFromHotkey switchToMarkedTabFromPopup switchToTabFromPanelTree switchToTabFromVisualization tabsActivated tabsClosed tabsCreated tabsMarked tabsMoved
s_on_off 1398983689204 {u'id': [], u'time': []} 1 12 0 0 0 0 0 {u'numOpenTabs': [17, 17], u'time': [139898367... 1398981819812 11 0 0 0 {u'index': [2, 1, 0, 2, 3, 2, 3, 0, 1, 4, 1, 4... {u'window': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... {u'index': [2, 3, 1, 5, 4, 5, 6, 9, 7, 5, 10, ... {u'numMarkedTabs': [3, 4, 5, 6, 7, 8, 9, 10, 1... {u'window': [1, 1, 1, 1, 1, 1], u'numOpenTabs'... ...

1 rows × 26 columns


In [16]:
j = json.load(open('1_on.json'))

In [17]:
j


Out[17]:
{u'endTime': 1398983689204,
 u'groupBy': {u'id': [], u'time': []},
 u'helpOpenedFromPopup': 1,
 u'markTabFromHotkey': 12,
 u'markTabFromPanelTree': 0,
 u'markTabFromPopup': 0,
 u'markTabFromVisualization': 0,
 u'openFrequentFromPopup': 0,
 u'openRecentFromPopup': 0,
 u'popupOpened': {u'numOpenTabs': [17, 17],
  u'time': [1398983679443, 1398983679444]},
 u'startTime': 1398981819812,
 u'switchToMarkedTabFromHotkey': 11,
 u'switchToMarkedTabFromPopup': 0,
 u'switchToTabFromPanelTree': 0,
 u'switchToTabFromVisualization': 0,
 u'tabsActivated': {u'id': [381,
   345,
   155,
   385,
   387,
   385,
   387,
   155,
   389,
   387,
   389,
   387,
   391,
   385,
   387,
   391,
   387,
   393,
   395,
   397,
   393,
   395,
   397,
   401,
   397,
   387,
   393,
   403,
   389,
   385,
   405,
   385,
   387,
   405,
   385,
   387,
   407,
   387,
   407,
   389,
   403,
   395,
   409,
   411,
   405,
   413,
   415,
   385,
   393,
   417,
   393,
   417,
   419,
   387,
   407,
   391,
   425,
   391,
   425,
   427,
   421,
   423,
   399,
   423,
   399,
   405,
   423,
   421,
   429,
   421,
   423,
   405,
   395,
   407,
   391,
   431,
   413,
   415,
   405,
   423,
   443,
   445,
   447,
   423,
   395,
   449,
   407,
   451,
   407,
   451,
   407,
   451,
   449,
   453],
  u'index': [2,
   1,
   0,
   2,
   3,
   2,
   3,
   0,
   1,
   4,
   1,
   4,
   5,
   3,
   7,
   8,
   7,
   5,
   6,
   7,
   4,
   5,
   6,
   7,
   6,
   6,
   4,
   5,
   1,
   3,
   10,
   3,
   7,
   10,
   3,
   7,
   8,
   7,
   8,
   1,
   5,
   5,
   11,
   12,
   10,
   11,
   12,
   3,
   4,
   4,
   3,
   3,
   4,
   6,
   6,
   7,
   8,
   7,
   8,
   9,
   10,
   11,
   12,
   11,
   12,
   12,
   11,
   10,
   15,
   10,
   10,
   11,
   5,
   6,
   7,
   7,
   17,
   17,
   16,
   15,
   16,
   16,
   16,
   15,
   5,
   6,
   7,
   8,
   7,
   8,
   7,
   7,
   6,
   17],
  u'numOpenTabs': [3,
   2,
   2,
   3,
   4,
   4,
   4,
   4,
   5,
   5,
   5,
   5,
   6,
   6,
   9,
   9,
   10,
   10,
   10,
   10,
   10,
   10,
   10,
   11,
   10,
   9,
   9,
   10,
   10,
   10,
   11,
   11,
   11,
   11,
   11,
   11,
   12,
   12,
   12,
   12,
   12,
   11,
   12,
   13,
   11,
   12,
   13,
   13,
   13,
   13,
   13,
   12,
   13,
   13,
   12,
   12,
   15,
   15,
   16,
   16,
   16,
   16,
   16,
   16,
   16,
   15,
   15,
   15,
   16,
   15,
   14,
   14,
   14,
   14,
   14,
   19,
   19,
   18,
   17,
   16,
   17,
   18,
   17,
   16,
   16,
   17,
   17,
   18,
   18,
   18,
   18,
   17,
   17,
   18],
  u'time': [1398981822639,
   1398981823140,
   1398981830755,
   1398981900976,
   1398981907841,
   1398981909160,
   1398981911471,
   1398981916833,
   1398981921066,
   1398981923086,
   1398981928554,
   1398981958215,
   1398981961014,
   1398981964124,
   1398982036553,
   1398982042641,
   1398982110459,
   1398982113253,
   1398982114913,
   1398982116361,
   1398982118336,
   1398982118978,
   1398982120077,
   1398982174190,
   1398982176570,
   1398982177728,
   1398982178570,
   1398982194514,
   1398982291897,
   1398982298988,
   1398982308295,
   1398982329569,
   1398982330167,
   1398982335362,
   1398982340532,
   1398982341239,
   1398982357702,
   1398982360237,
   1398982364035,
   1398982428260,
   1398982439883,
   1398982571100,
   1398982593399,
   1398982594859,
   1398982598605,
   1398982652837,
   1398982753261,
   1398982791912,
   1398982822561,
   1398982839462,
   1398982841165,
   1398982863926,
   1398982878054,
   1398982883688,
   1398982891874,
   1398982907527,
   1398983005421,
   1398983006883,
   1398983052831,
   1398983058049,
   1398983062064,
   1398983067434,
   1398983070333,
   1398983073411,
   1398983090610,
   1398983116015,
   1398983116938,
   1398983155616,
   1398983177339,
   1398983192403,
   1398983201087,
   1398983204742,
   1398983205091,
   1398983205423,
   1398983207705,
   1398983339080,
   1398983344227,
   1398983346904,
   1398983348987,
   1398983352159,
   1398983352837,
   1398983387828,
   1398983403063,
   1398983424049,
   1398983427056,
   1398983544697,
   1398983552847,
   1398983570056,
   1398983570987,
   1398983573073,
   1398983575257,
   1398983575868,
   1398983576688,
   1398983683072],
  u'window': [1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1]},
 u'tabsClosed': {u'numOpenTabs': [3,
   2,
   10,
   9,
   11,
   12,
   11,
   12,
   12,
   12,
   15,
   15,
   14,
   19,
   18,
   17,
   16,
   18,
   17,
   16,
   17],
  u'time': [1398981822624,
   1398981823077,
   1398982176563,
   1398982177719,
   1398982571098,
   1398982598130,
   1398982598568,
   1398982829861,
   1398982863920,
   1398982891872,
   1398983116009,
   1398983192377,
   1398983201078,
   1398983339073,
   1398983346894,
   1398983348985,
   1398983352156,
   1398983387826,
   1398983403061,
   1398983424028,
   1398983575858],
  u'window': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]},
 u'tabsCreated': {u'index': [2,
   3,
   1,
   5,
   4,
   5,
   6,
   9,
   7,
   5,
   10,
   8,
   11,
   12,
   11,
   12,
   4,
   4,
   8,
   9,
   8,
   9,
   15,
   8,
   9,
   10,
   11,
   12,
   13,
   16,
   17,
   18,
   6,
   8,
   17],
  u'numOpenTabs': [3,
   4,
   5,
   6,
   7,
   8,
   9,
   10,
   11,
   10,
   11,
   12,
   12,
   13,
   12,
   13,
   13,
   13,
   13,
   14,
   15,
   16,
   16,
   15,
   16,
   17,
   18,
   19,
   20,
   17,
   18,
   19,
   17,
   18,
   18],
  u'time': [1398981900973,
   1398981907833,
   1398981921066,
   1398981961011,
   1398982001111,
   1398982002593,
   1398982007145,
   1398982099141,
   1398982174185,
   1398982194507,
   1398982308270,
   1398982357696,
   1398982593368,
   1398982594800,
   1398982640623,
   1398982731533,
   1398982839461,
   1398982878047,
   1398982953312,
   1398982973781,
   1398983005420,
   1398983039624,
   1398983177335,
   1398983233814,
   1398983245131,
   1398983280422,
   1398983309150,
   1398983327518,
   1398983335534,
   1398983352816,
   1398983381405,
   1398983385673,
   1398983542870,
   1398983570054,
   1398983683058],
  u'window': [1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1,
   1]},
 u'tabsMarked': {u'numMarkedTabs': [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
  u'numOpenTabs': [6, 9, 11, 12, 11, 13, 12, 16, 16, 16, 16, 17],
  u'time': [1398981979026,
   1398982039669,
   1398982338887,
   1398982367215,
   1398982575494,
   1398982828142,
   1398982930899,
   1398983054105,
   1398983059514,
   1398983065613,
   1398983068570,
   1398983582421]},
 u'tabsMoved': {u'numOpenTabs': [10, 10, 10, 10, 10, 10],
  u'time': [1398982111512,
   1398982111550,
   1398982111690,
   1398982113690,
   1398982115063,
   1398982116469],
  u'window': [1, 1, 1, 1, 1, 1]},
 u'tabsOpen': {u'1': {u'numOpenTabs': [3,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    11,
    10,
    9,
    10,
    11,
    12,
    11,
    12,
    13,
    12,
    11,
    12,
    13,
    12,
    13,
    12,
    13,
    12,
    13,
    14,
    15,
    16,
    15,
    16,
    15,
    14,
    15,
    16,
    17,
    18,
    19,
    20,
    19,
    18,
    17,
    16,
    17,
    18,
    19,
    18,
    17,
    16,
    17,
    18,
    17,
    18],
   u'time': [1398981822641,
    1398981823142,
    1398981900979,
    1398981907852,
    1398981921072,
    1398981961019,
    1398982001114,
    1398982002600,
    1398982007157,
    1398982099143,
    1398982174213,
    1398982176580,
    1398982177742,
    1398982194540,
    1398982308311,
    1398982357734,
    1398982571106,
    1398982593426,
    1398982594865,
    1398982598175,
    1398982598612,
    1398982640627,
    1398982731549,
    1398982829879,
    1398982839469,
    1398982863947,
    1398982878073,
    1398982891878,
    1398982953315,
    1398982973788,
    1398983005423,
    1398983039635,
    1398983116023,
    1398983177358,
    1398983192405,
    1398983201097,
    1398983233817,
    1398983245134,
    1398983280428,
    1398983309157,
    1398983327521,
    1398983335537,
    1398983339086,
    1398983346911,
    1398983349004,
    1398983352178,
    1398983352849,
    1398983381408,
    1398983385717,
    1398983387834,
    1398983403066,
    1398983424055,
    1398983542874,
    1398983570097,
    1398983575876,
    1398983683133]}},
 u'urlsRevisited': 25,
 u'urlsVisited': 98,
 u'visualizationOpened': {u'numOpenTabs': [11, 12],
  u'time': [1398982593327, 1398982594756]},
 u'visualizationOpenedFromHotkey': 2,
 u'visualizationOpenedFromPopup': 0}

In [25]:
s = pd.Series([[1,2],[3,4]], index=['a', 'b'])
s


Out[25]:
a    [1, 2]
b    [3, 4]
dtype: object

In [ ]:


In [129]:
df = pd.read_json('/tmp/combined.json', orient='records')
pd.DataFrame(df, columns=['tabsActivated'])


Out[129]:
tabsActivated
0 {u'index': [2, 1, 0, 2, 3, 2, 3, 0, 1, 4, 1, 4...
1 {u'index': [16, 5, 6, 5, 6, 7, 7, 6, 7, 8, 9, ...
2 {u'index': [16, 15, 14, 13, 14, 13, 14, 13, 14...
3 {u'index': [1, 0, 1, 2, 3, 2, 3, 6, 11, 6, 4, ...
4 {u'index': [7, 8, 15, 9, 16, 10, 17, 11, 18, 1...
5 {u'index': [3, 2, 3, 2, 3, 2, 3, 3, 4, 3, 2, 1...
6 {u'index': [2, 1, 0, 0, 1, 2, 3, 2, 1, 2, 1, 2...
7 {u'index': [0, 0, 1, 2, 1, 4, 3, 3, 2, 2, 3, 3...

8 rows × 1 columns


In [89]:
df['startTime'].keys()


Out[89]:
Int64Index([0, 1, 2, 3], dtype='int64')

In [90]:
def to_time_delta(start=None, timestamps=None):
    return (np.array(timestamps) - start) / (1 * 1000) # ms to s

def scalarxy(ycol=None):
    """Get x and y arrays with one data point for each row.
    
    x axis represents the row index.
    y axis represents one scalar value for each row.
    
    Args:
      ycol: Column to be used as y (scalar data type).
      
    Returns:
      x, y: Arrays with x and y values.
      
    """
    x, y = df.index, df[ycol]
    return x, y

def xy(index=None, xcol=None, ycol=None):
    """Get x and y from values in columns.
    
    Args:
      index: Index of the row.
      xcol: Column to be used as x.
      ycol: Column to be used as y.
      
    Returns:
      x, y: Arrays with x and y values.
      
    """
    x, y = df[xcol][index], df[ycol][index]
    return x,y

def nestedxy(index=None, maincol=None, xcol=None, ycol=None):
    """Get x and y from values in nested columns.
    
    Args:
      index: Index of the row.
      maincol: Main column name.
      xcol: Nested column to be used as x.
      ycol: Nested column to be used as y.
      
    Returns:
      x, y: Arrays with x and y values.
      
    """
    series = df[maincol][index] # Values from the main column
    x, y = series[xcol], series[ycol]
    
    start_time = df['startTime'][index]
    if xcol == 'time':
        x = to_time_delta(start=start_time, timestamps=series['time'])
    if ycol == 'time':
        y = to_time_delta(start=start_time, timestamps=series['time'])
    return x, y

In [143]:
# Pattern of tab switching over time
fig = plt.figure(figsize=(16, 8))
nrows, ncols = len(df.index) / 2, 2
for index in df.index:
    x, y = nestedxy(index=index, maincol='tabsActivated', xcol='time', ycol='index')
    plt.subplot(nrows, ncols, index + 1)
    plt.hold(True)
    plt.plot(x, y, 'ro', markersize=3)
    plt.plot(x, y)
    plt.xlabel('Time (s)')
    plt.ylabel('Active tab index')
    plt.title('Run %d' % (index))
plt.autoscale(tight='x')
plt.tight_layout()



In [134]:
x, y = scalarxy(ycol='startTime')
plt.scatter(x, y)


Out[134]:
<matplotlib.collections.PathCollection at 0x6c61310>

In [ ]: