Skip to content

Instantly share code, notes, and snippets.

@alpocr
Last active August 29, 2015 14:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save alpocr/99738a65e0760b54ba17 to your computer and use it in GitHub Desktop.
"""
Author: Allan Porras
Emil: alpocr@gmail.com
June 3, 2015
"""
import csv
from collections import defaultdict
class Helper(object):
@classmethod
def get_score_product(self, event):
"""
Returns the 'product' according event type
"""
event = str(event).strip()
if event == "web":
return float(1.0)
elif event == "email":
return float(1.2)
elif event == "social":
return float(1.5)
elif event == "webinar":
return float(2.0)
@classmethod
def get_label(self, norm_score):
"""
Returns the label
"""
norm_score=float(norm_score)
if norm_score < 25:
return str("bronze")
elif norm_score >= 25 and norm_score <= 49:
return str("silver")
elif norm_score >= 50 and norm_score <= 74:
return str("gold")
elif norm_score >= 75 and norm_score <= 100:
return str("platinum")
@classmethod
def get_normalized_score(self, score):
return float(score) * 0.1
class Main(object):
@classmethod
def run(self):
csv_path=raw_input( "Hi, please put the csv path here and PRESS ENTER: ")
data = defaultdict(list)
for i, row in enumerate(csv.reader(open(csv_path, 'rb'))):
if not i or not row:
continue
customerid, event, score = row
score = float(score) * Helper.get_score_product(event)
data[customerid].append(float(score))
for customerid, score in data.iteritems():
sum_score=sum(score)
norm_score = Helper.get_normalized_score(sum_score)
norm_score = round(norm_score, 2)
print str(customerid) +", "+ str(Helper.get_label(norm_score)) +", "+ str(norm_score)
if __name__ == "__main__":
Main.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment