/
test_conversion.py
95 lines (80 loc) · 3.65 KB
/
test_conversion.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
# For a GUI, better performance, more functions, and easiness to use... Check out: www.unisoftdev.tech
'''
* @ Automated website conversion rate testing tool example
* Created By: Juraj Vysvader
* Author's profile: https://www.linkedin.com/in/jurajvysvader
https://www.linkedin.com/company/unisoftdev
* Creation date: 10.3.2019
* Business website: https://www.unisoftdev.tech
* @license http://www.gnu.org/copyleft/lgpl.html GNU/GPL
* @Copyright (C) 2019 Juraj Vysvader. All rights reserved.
'''
#! /usr/bin/python
import json
from json import loads
from json import dumps
import global_variable
def display_element(something_to_display):
# handle this variable for a server rendering HTML
global_variable.color = something_to_display
def Write(_color):
# gets all of our data from the config file.
with open('con.json', 'r') as nnn:
config_data = json.load(nnn)
config_data[_color]["prices_list_visits"] =+ 1
with open('con.json', 'w') as f:
f.write(json.dumps(config_data))
def Start(test_referer):
# gets all of our data from the config file.
with open('con.json', 'r') as nnn:
config_data = json.load(nnn)
test_result = config_data["test_result"]
#check that the test didn't finish:
if not len(test_result) < 1:
print("The result: " + str(test_result))
something_to_display = config_data["winning_color"]
display_element(something_to_display)
else:
#sets a number of visitors that will be tested against each one design scheme
number_of_visits_per_each = 100 #At this time, it's 100 people for each one color
#this checks which one color is currently tested, which this data are picked up about
# and later tests conversion rate of 100 visitors per each design scheme
if config_data["green"]["prices_list_visits"] < number_of_visits_per_each:
if test_referer > 0:
something_to_display = config_data["green"]["color"]
config_data["results"]["green"] =+ 1 # this counts clicks
else:
_color = 'green'
Write(_color)
elif config_data["orange"]["prices_list_visits"] < number_of_visits_per_each:
if test_referer > 0:
something_to_display = config_data["orange"]["color"]
config_data["results"]["orange"] =+ 1 # this counts clicks
else:
_color = 'orange'
Write(_color)
elif config_data["red"]["prices_list_visits"] < number_of_visits_per_each:
if test_referer > 0:
something_to_display = config_data["red"]["color"]
config_data["results"]["red"] =+ 1 # this counts clicks
else:
_color = 'red'
Write(_color)
elif config_data["blue"]["prices_list_visits"] < number_of_visits_per_each:
if test_referer > 0:
something_to_display = config_data["blue"]["color"]
config_data["results"]["color"] =+ 1 # this counts clicks
else:
_color = 'blue'
Write(_color)
#if it's the end of the test:
else:
find_the_highest = config_data["results"]
event_finish = max(find_the_highest, key=find_the_highest.get)
#event = max(config_data, key=lambda ev: ev['price_list_clicks'])
print(event_finish)
config_data["test_result"] = event_finish
config_data["winning_color"] = config_data[event_finish]["color"]
something_to_display = config_data["winning_color"]
with open('con.json', 'w') as f:
f.write(json.dumps(config_data))