Skip to content

Commit

Permalink
better code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
LeviBorodenko committed Apr 6, 2019
1 parent 380fce2 commit 24bca24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 12 additions & 7 deletions Logation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ class Log(object):
"""

def __init__(self, access_log_file="access.log",
clean_dir="./cleanData/", raw_dir="./rawData/", asset_dir="./map/assets/"):
clean_dir="./cleanData/", raw_dir="./rawData/",
asset_dir="./map/assets/"):
super(Log, self).__init__()

# creating all file and directory names
self.clean_dir = clean_dir
self.raw_dir = raw_dir
self.asset_dir = asset_dir
self.data_file = raw_dir + access_log_file
self.data = self.clean_dir + "data.json"
self.responseJson = self.clean_dir + "response.json"
self.data = self.clean_dir + "analysis.json"
self.responseJson = self.clean_dir + "locations.json"
self.locationsJS = self.asset_dir + "locations.js"

# object that gathers miscellaneous information
Expand All @@ -38,7 +39,7 @@ def getIP(self, line):
return line.split(" ")[0]

def removeDublicates(self):
"""Scans the log file and removes doublicate ips"""
"""Scans the log file for visits by the same ip and removes them."""
with open(self.data_file, "r") as f:

# storing all already added IPs
Expand Down Expand Up @@ -76,7 +77,7 @@ def getLine(self):
return(line)

def getContext(self, line):
"""Helper"""
"""Method to isolate OS data from a log line"""
return(line.rsplit("\"")[5])

def getOS(self, line):
Expand Down Expand Up @@ -238,11 +239,15 @@ def rasterizeData(self, resLat=200, resLong=250):
"raster": raster}, json_dump)

def createJs(self):
"""creating the js-file that we feed to the website inside the
./map/ folder to create the map."""
with open(self.responseJson, "r") as response:

dataString = "const LOCATIONS = " + str(json.load(response))
with open(self.locationsJS, "w") as f:
f.write(dataString)


test = Log()
test.analyseLog()
if __name__ == '__main__':
log = Log()
log.analyseLog()
2 changes: 1 addition & 1 deletion map/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<link rel="stylesheet" href="./css/style.css">


<title> Traffic Map| Levi B.</title>
<title> Traffic Map | Levi B.</title>
</head>
<body>
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion rawData/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*
!.gitignore
!.gitignore

0 comments on commit 24bca24

Please sign in to comment.