Revision a60088f6 lib/utilities.py

View differences:

lib/utilities.py
1
import os
1
#from __future__ import print_function
2
import sys,os
2 3
from pandas import *
3 4

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

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

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

  
10 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

  
11 18
		if columns:
12 19
			src_slv = columns
13 20
		else:
14
			src_slv = sorted(set(dataframe[columnA]))
21
			src_slv = x_keys 
15 22
		if rows:
16 23
			dst_slv = rows
17 24
		else:
18
			dst_slv = sorted(set(dataframe[columnB]))
25
			dst_slv =  y_keys
26

  
19 27

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

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

  

Also available in: Unified diff