Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (2.13 KB)

1
import os
2
from pandas import * 
3

    
4
def hostname_from_filename(filename):
5
        return filename.split('_')[0]
6
#        return filename[:17]  
7

    
8
def time_from_filename(filename):
9
        return filename.split('.')[0][-10:]
10
#        if is_source_from_filename(filename):
11
#                return filename[25:35]
12
#        else:
13
#                return filename[31:41]
14

    
15
def is_source_from_filename(filename):
16
        if "source" in filename:
17
                return True
18
        else:
19
                return False
20

    
21
nicks = {}
22
#                '0000000000c5_0058': 's0',\
23
#                '0000000000c5_0068': 's1',\
24
#                '0000000000c5_0066': 's2',\
25
#                '0000000000c5_0055': 's3',\
26
#                '0000000000c5_0067': 's4',\
27
#                '0000000000c5_0065': 's5',\
28
#                '0000000000c5_0057': 's6',\
29
#                '0000000000c5_0056': 's7',\
30
#                '0000000000c5_00ab': 's8',\
31
#                '0000000000c5_00aa': 's9',\
32
#                '0000000000c5_0082': 's10',\
33
#                '0000000000c5_008c': 's11',\
34
#                '0000000000c5_0080': 's12',\
35
#                '0000000000c5_00c6': 's13',\
36
#                '0000000000c5_0097': 's14',\
37
#                '0000000000c5_0096': 's15',\
38
#}
39
def purify_hostname(name):
40
# 00000000008e_0034
41
        if name:
42
                if name not in nicks.keys():
43
                        return 's'+name.split('_')[0] 
44
#                        return ("s"+name[-2:]+name[10:12]).lower()
45
                else:
46
                        return nicks[name]
47
        else:
48
                return str(name)
49

    
50
def purify_address(folder,name):
51
        mapfile = read_csv(folder+"/hostnames2address.exp").set_index('address')
52
        hostname = mapfile['hostname'][name]
53
        return purify_hostname(hostname)
54
##        "fdf5:5351:1dfd:52:1001::8e:15517"
55
#        sliverid=name.split(":")[3]
56
#        sliceid=name.split(":")[6]
57
#        if len(sliverid)<2:
58
#                sliverid = "0"+sliverid
59
#        return ("s"+sliverid+sliceid).lower()
60

    
61
def session_id_shortner(sid):
62
        return "r"+str(sid)[5:8]
63

    
64
def source_hostname(folder):
65
        for logfile in os.listdir(folder):
66
                if logfile.endswith(".log.csv") and "_source_" in logfile:
67
                        return logfile[:17]
68
        return None
69

    
70
def source_addr(folder):
71
        for logfile in os.listdir(folder):
72
                if logfile.endswith(".log.csv") and "_source_" in logfile:
73
                        sourcedata = read_csv(folder+'/'+logfile)
74
                        if len(sourcedata) > 0:
75
                                return ''.join(sourcedata['sender'][0].split(':')[:-1])
76
        return None
77

    
78
def timespread_filename(folder, peer_hostname):
79
        for logfile in os.listdir(folder):
80
                if logfile.startswith(peer_hostname+"_timespread_"):
81
                        return (folder+"/"+logfile)
82
        return None
83