Statistics
| Branch: | Revision:

peerstreamer-logs-analyzer / lib / utilities.py @ a60088f6

History | View | Annotate | Download (1.09 KB)

1
#from __future__ import print_function
2
import sys,os
3
from pandas import *
4

    
5
def rescale(x,oldmin,oldmax,newmin,newmax):
6
        return newmin+(newmax-newmin)*(x-oldmin)/(oldmax-oldmin)
7

    
8
def warning(msg):
9
        print ("[WARNING] "+msg)
10

    
11
def emptyFile(filename):
12
        return (os.stat(filename).st_size == 0)
13

    
14
def correlateColumns(dataframe,columnA,columnB,columnValue,defaultValue=0,autoValue=None,columns=None,rows=None):
15
                x_keys = sorted(set(dataframe[columnA]))
16
                y_keys = sorted(set(dataframe[columnB]))
17

    
18
                if columns:
19
                        src_slv = columns
20
                else:
21
                        src_slv = x_keys 
22
                if rows:
23
                        dst_slv = rows
24
                else:
25
                        dst_slv =  y_keys
26

    
27

    
28
#                dst_slv = list(set(dst_slv + src_slv))
29
                rttmat = DataFrame(index=src_slv,columns = dst_slv)
30
                for slv in src_slv:
31
                        slvrtt = (dataframe[dataframe[columnA] == slv]).set_index(columnB)[columnValue] 
32
                        for dst in slvrtt.index:
33
                                if dst in dst_slv:
34
                                        rttmat[dst][slv] = slvrtt[dst] #if dst in slvrtt.index.tolist() else defaultValue
35
                        if slv in dst_slv and autoValue != None:
36
                                rttmat[slv][slv] = autoValue
37

    
38
                #fill in the unset values
39
                rttmat = rttmat.fillna(defaultValue)
40
                return rttmat
41