-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunUsers.py
More file actions
104 lines (83 loc) · 2.62 KB
/
RunUsers.py
File metadata and controls
104 lines (83 loc) · 2.62 KB
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
import subprocess
import random
from flask_pymongo import PyMongo
from pymongo import MongoClient
import matplotlib.pyplot as plt
from datetime import datetime, timedelta
# 10k fake users
# 63% have a bias for light
# 37% for dark
# 23% for small
# 77% for large
# in this case the obvious best version is light + large
class User:
def __init__(self):
self.layout = ""
self.colour = ""
self.font = ""
def setLayout(self, layout):
self.layout = layout
def setColour(self, colour):
self.colour = colour
def setFont(self, font):
self.font = font
def writeStats(filename, date):
with open(filename, "a") as file:
file.write(str(date) + ",")
versions = db.Clicks.find()
for i, v in enumerate(versions):
file.write(str(v.get("percentage")) + ",") if i != versions.count() - 1 else file.write(str(v.get("percentage")))
file.write("\n")
file.close()
# Set MongoDB details
client = MongoClient('localhost:27017')
db = client.ClickData
horizon = 16
simulations = 5
cumulative_rewards =[0.0 for i in range(horizon * simulations)]
rewards = [0.0 for i in range(horizon * simulations)]
sim_no = 0
stats_file = "static/dashboard/data/data.csv"
dt = datetime.now()
stats_date = dt.date()
# open file
# file = open(stats_file, "w")
# headers = "date,"
# versions = db.Clicks.find().count()
# for i in range(versions):
# headers += "version" + str(i + 1) if i == versions - 1 else "version" + str(i + 1) + ","
# file.write(headers + '\n')
# file.close()
for i in range(simulations):
for j in range(horizon):
# create user object
user = User()
# Set colour scheme preference
if random.random() < 0.6:
# bias for light colour schemes
user.setColour("light")
else:
# bias for dark colour schemes
user.setColour("dark")
# Set font preference
if random.random() < 0.23:
# bias for small fonts
user.setFont("small")
else:
# bias for large fonts
user.setFont("large")
clicks = random.randint(1, 4)
# Time spent on the website
time = random.randint(2, 15)
# Take version screenshot or not
# capture = True if (i == 0 and j < 8) else False
capture = False
# call CasperJS process
casper_script = subprocess.Popen(["casperjs", "button-click.js", user.layout, user.colour, user.font, str(clicks), str(time), str(capture), str(j + 1)], stdout=subprocess.PIPE)
output = casper_script.stdout.read().strip()
print "output :", output
# subprocess.call(["casperjs", "button-click.js", user.layout, user.colour, user.font, str(clicks)])
# write to Stats file - considering each horizon iteration to be one day
writeStats(stats_file, stats_date)
# increment date
stats_date += timedelta(days=1)