mardi 25 août 2015

Groupby time stamp in java, translate from python code?

[Demo-Site, 10.227.147.98, CustomerDetailsByRegion, 17:05:15, 2015-08-19]
[Demo-Site, 10.152.114.217, TableauCustomers, 08:03:32, 2015-08-20]
[Demo-Site, 10.208.213.179, TableauCustomers, 10:14:55, 2015-08-20]
[poc, 10.237.232.199, App, 11:06:36, 2015-08-20]
[poc, 10.237.232.199, blah, 11:07:18, 2015-08-20]

Is there a way in java to get the site name aggregated by time interval of 30 mins?

Output should be

[[Demo-site, 17-1730, 1, 2015-08-19], 
[Demo-site, 8-830, 1, 2015-08-20],
[Demo-site, 10-1030, 1, 2015-08-20], 
[Poc, 11-11:30, 2, 2015-08-20]]

I did it in python using a groupby and itemgetter, I am new to java so not too sure. If it helps here is the python code.

def join_array(data):
    out = []
    for _, v in groupby(sorted(data, key=itemgetter(0, 3)),key=itemgetter(0,3)):
        v = list(v)    
        ips = ", ".join([sub[1] for sub in v])
        tmes = ", ".join([sub[2] for sub in v])
        out.append([v[0][0], ips, tmes, v[0][-1]])
    return out



from Newest questions tagged java - Stack Overflow http://ift.tt/1WQDzur
via IFTTT

Aucun commentaire:

Enregistrer un commentaire