-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrender.py
55 lines (40 loc) · 997 Bytes
/
Trender.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
#!/usr/bin/python
# Usage: python popular new_vector
import os, sys, math
path = "#your path for trenders"
old_vector = sys.argv[1]
f1 = open(path + old_vector)
new_vector = sys.argv[2]
f2 = open(path + new_vector)
old_s = {}
for line1 in f1:
val = line1.strip()
val = line1.split(" ")
val[1] = val[1].strip("\n")
old_s[val[1]] = int(val[0])
new_s = {}
usernum2 = 0
for line2 in f2:
val = line2.split("\t")
if len(val) == 3:
stocks = val[2].strip("\n")
user = val[0]
if stocks not in new_s:
new_s[stocks] = []
if user not in new_s[stocks]:
new_s[stocks].append(user)
f1.close()
f2.close()
trenders = {}
for (stocks, users) in new_s.items():
new_s[stocks] = len(users)
num = new_s[stocks]
if num > 10:
if stocks not in trenders:
trenders[stocks] = num * 1.0
if stocks not in old_s:
old_s[stocks] = 50.0
ratio = 1.0 * num / old_s[stocks]
trenders[stocks] = ratio * math.sqrt(old_s[stocks])
for entry in trenders:
print (entry, trenders[entry])