Statistics
| Branch: | Revision:

peerstreamer-logs-analyzer / lib / peerstreamer_logs.py @ 1a481d7b

History | View | Annotate | Download (2.06 KB)

1
import os
2
from pandas import * 
3

    
4
def hostname_from_filename(filename):
5
        return filename[:17]
6

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

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

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

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

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

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

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

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