This repository has been archived by the owner on May 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #420 from OpenBazaar/stats-collection
Auditing to Database
- Loading branch information
Showing
8 changed files
with
199 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import sqlite3 | ||
|
||
|
||
def migrate(database_path): | ||
print "migrating to db version 7" | ||
conn = sqlite3.connect(database_path) | ||
conn.text_factory = str | ||
cursor = conn.cursor() | ||
|
||
# create new table | ||
cursor.execute('''CREATE TABLE IF NOT EXISTS audit_shopping ( | ||
audit_shopping_id integer PRIMARY KEY NOT NULL, | ||
shopper_guid text NOT NULL, | ||
contract_hash text, | ||
"timestamp" integer NOT NULL, | ||
action_id integer NOT NULL | ||
);''') | ||
cursor.execute('''CREATE INDEX IF NOT EXISTS shopper_guid_index ON audit_shopping (audit_shopping_id ASC);''') | ||
cursor.execute('''CREATE INDEX IF NOT EXISTS action_id_index ON audit_shopping (audit_shopping_id ASC);''') | ||
|
||
# update version | ||
cursor.execute('''PRAGMA user_version = 7''') | ||
conn.commit() | ||
conn.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
__author__ = 'hoffmabc' | ||
|
||
from log import Logger | ||
|
||
|
||
class Audit(object): | ||
""" | ||
A class for handling audit information | ||
""" | ||
|
||
def __init__(self, db): | ||
self.db = db | ||
|
||
self.log = Logger(system=self) | ||
|
||
self.action_ids = { | ||
"GET_PROFILE": 0, | ||
"GET_CONTRACT": 1, | ||
"GET_LISTINGS": 2, # Click Store tab | ||
"GET_FOLLOWING": 3, | ||
"GET_FOLLOWERS": 4, | ||
"GET_RATINGS": 5 | ||
} | ||
|
||
def record(self, guid, action_id, contract_hash=None): | ||
self.log.info("Recording Audit Event [%s]" % action_id) | ||
|
||
if action_id in self.action_ids: | ||
self.db.audit_shopping.set(guid, self.action_ids[action_id], contract_hash) | ||
else: | ||
self.log.error("Could not identify this action id") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.