Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. def attackList(accessList, m, n):
  2.  
  3.  
  4. #Create a function to return the dates converted to seconds
  5. def tosecond(s):
  6. #Choose 170101000000 as the point of reference
  7. month = {'01':0, '02':2678400, '03':5097600, '04':7776000, '05':10368000, '06':13046400, '07': 15638400, '08':18316800, '09': 20995200, '10':23587200, '11':26265600, '12':28857600}
  8. result = (int(s[:2])-17)*31536000
  9. result += month[s[2:4]]
  10. result += int(s[4:6])*24*60**2
  11. result += int(s[6:8])*60**2
  12. result += int(s[8:10])*60
  13. result += int(s[10:12])
  14. return result
  15.  
  16. #A function calculating if the two dates is within m mins
  17. def iswithin(s1,s2):
  18. difference = abs(s1 - s2)
  19. if difference <= m*60:
  20. return True
  21. else:
  22. return False
  23.  
  24. #A list of distinct usernames
  25. name = []
  26. for e in accessList:
  27. if e[13:] not in name:
  28. name.append(e[13:])
  29.  
  30.  
  31. if n == 1:
  32. return sorted(name)
  33.  
  34. hack = []
  35. for e in name:
  36. accessTime = []
  37. count = 1
  38. for j in accessList:
  39. if j[13:] == e:
  40. accessTime.append(tosecond(j))
  41. sorted(accessTime) #A sorted list of access time of the e user
  42.  
  43. for i in range(len(accessTime) - 1):
  44. if iswithin(accessTime[i],accessTime[i+1]):
  45. count +=1
  46. if count == n and iswithin(accessTime[i+2-n],accessTime[i+1]):
  47. hack.append(e)
  48. break
  49. else:
  50. count = 1
  51.  
  52. return sorted(hack)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement