Skip to content

Instantly share code, notes, and snippets.

@petrolmer
Created November 24, 2014 23:46
Show Gist options
  • Save petrolmer/39b12187e710da7688d3 to your computer and use it in GitHub Desktop.
Save petrolmer/39b12187e710da7688d3 to your computer and use it in GitHub Desktop.
Logr - features
import sys
import os
import csv
filename = 'opportunity_history.csv'
infile = csv.DictReader(open(filename))
stagehistory={}
for row in infile:
if row["Id"] == "Id":
continue
if row["OpportunityId"] not in stagehistory:
stagehistory[row["OpportunityId"]] = {}
stagehistory[row["OpportunityId"]][row["StageName"]] = 1
filename = 'opportunity.csv'
infile = csv.DictReader(open(filename))
outfilename = 'dataset.csv'
outfile = csv.DictWriter(open(outfilename, 'w'), [
"Opportunity","ReachedStage1",
], extrasaction = 'ignore', quoting = csv.QUOTE_MINIMAL, delimiter = ',', lineterminator = '\n')
header = {}
for field in outfile.fieldnames:
header[field] = field
outfile.writerow(header)
line = {}
for row in infile:
if row["Id"] == "Id":
continue
closedate = row["CloseDate"]
if closedate < "2013-10-01" or closedate > "2014-12-31":
continue
line["Opportunity"] = row["Id"] + " " + row["Name"]
if "1 - Discovery" in stagehistory[row["Id"]]:
line["ReachedStage1"] = "yes"
else:
line["ReachedStage1"] = "no"
outfile.writerow(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment