-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
160 lines (137 loc) · 4.7 KB
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
f = open("./data/data.csv", "r+")
lines = []
import numpy
from geopy.geocoders import Nominatim
from geopy.distance import vincenty
from itertools import groupby
for line in f:
lines.append(line.strip().split(","))
"""
parses into separate lists
"""
descriptions= [line[0] for line in lines if line[0] != ""]
withdrawals = [float(line[1]) for line in lines if line[1] != ""]
deposits= [float(line[2]) for line in lines if line[2] != ""]
dates=[line[3] for line in lines if line[3] != ""]
cities= [line[4] for line in lines if line[4] != ""]
states= [line[5] for line in lines if line[5] != ""]
location=[]
for x in range(0, len(cities)):
location.append(cities[x]+states[x])
transaction= []
def createTransaction(descriptions):
counter =0
for desc in descriptions:
transaction.append(desc +"+" + str(withdrawals[counter])+"+"+ str(deposits[counter])+"+" +dates[counter] +"+" + location[counter])
counter+=1
createTransaction(descriptions)
homeLoc = "Kearny NJ"
geolocator= Nominatim()
myloc = geolocator.geocode(homeLoc)
myHome= (myloc.latitude, myloc.longitude)
def median(lst):
return numpy.median(numpy.array(lst))
def mean(lst):
return numpy.mean(numpy.array(lst))
def std(lst):
return numpy.mean(numpy.array(lst))
"""
different lists
"""
statStrange=[]
locStrange=[]
categoryStrange=[]
locList=[]
uniqueLocation=[]
categoryStrange=[]
"""
finds quantatitive oddities in withdrawals
"""
def withdrawal_strange(lst):
for trans in lst:
desc, withd, dep,dates, loc= trans.split("+")
if (abs(float(withd)-median(withdrawals)) > std(withdrawals)):
statStrange.append(trans)
"""
find location oddities
"""
def distanceList(lst):
for loc in lst:
geolocator= Nominatim()
transLoc= geolocator.geocode(loc)
coord=(transLoc.latitude, transLoc.longitude)
locList.append(vincenty(coord, myHome).miles)
def loc_strange(lst):
distanceList(location)
for trans in lst:
desc, withd, dep, dates,loc= trans.split("+")
geolocator= Nominatim()
transLoc= geolocator.geocode(loc)
coord=(transLoc.latitude, transLoc.longitude)
distance= vincenty(coord, myHome).miles
if (abs(distance - median(locList) > std(locList))):
locStrange.append(trans)
"""
Finds strange locations based on frequency of transaction
"""
def frequency(lst):
uniqueLocations= set(location)
for loc in uniqueLocations:
if (location.count(loc)==1):
for trans in lst:
desc, withd, dep, dates,loc2= trans.split("+")
if loc==loc2:
uniqueLocation.append(trans)
"""
Finds strange categories based on profile
"""
def categories(lst):
transportation=["Plane", "Air","Car","Train","Subway","Airpot","Airlines","Station","Cruise","Boat","Ship"]
for trans in lst:
desc, withd, dep,dates,loc2=trans.split("+")
splitDesc= desc.split(" ")
for buzzword in transportation:
if buzzword in splitDesc:
categoryStrange.append(trans)
transactionDictionary=[]
"""
All the algo calls and consolidation
"""
uniqueTransactions=[]
def consolidate(lst):
transactionDictionary= []
withdrawal_strange(lst)
loc_strange(lst)
frequency(lst)
categories(lst)
consolidatedList= statStrange+locStrange+categoryStrange+uniqueLocation+categoryStrange
uniqueTransactions= list(set(consolidatedList))
for trans in uniqueTransactions:
desc, withd, dep,dates,loc=trans.split("+")
dict={'description': desc, 'withdrawal': withd, 'deposit': dep,'date': dates, 'location':loc}
transactionDictionary.append(dict)
return transactionDictionary
def account(name):
if name=="Don":
dict1={'name': '360 CHECKING', 'balance': 300.86, 'account_number': 4512}
dict2={'name': '360 SAVINGS', 'balance': 3124.86, 'account_number': 8512}
return [dict1, dict2]
if name=="Agnes":
dict1={'name': 'CHECKING', 'balance': 3892.86, 'account_number': 4982}
dict2={'name': 'SAVINGS', 'balance': 890.86, 'account_number': 1212}
return [dict1,dict2]
def transactionHistory(name):
transactionDict=[]
if name=="Don" or name=="Agnes":
for trans in transaction:
desc, withd, dep,dates,loc=trans.split("+")
dict={'description': desc, 'withdrawal': withd, 'deposit': dep,'date': dates, 'location':loc}
transactionDict.append(dict)
return transactionDict
def weirdTransaction(name):
if name=="Don" or name=="Agnes":
return consolidate(transaction)
if __name__ == "__main__":
print account("Don")
print transactionHistory("Don")
print weirdTransaction("Don")