-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
123 lines (97 loc) · 3.22 KB
/
main.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
from matplotlib import pyplot as plt
import csv
import random
import time
import os
def create_data():
# 10 group data / 10 value per group
# range of number of x from 10 to 25
data_list = [x_random() for i in range(1, 11)]
data_list = data_list + data_list
return data_list
def x_random():
num_x = random.randint(10, 20)
x_list = []
# randomly arrange the range of x
for i in range(0, num_x + 1):
x_list.append(random.randint(1, 21))
num_random = random.randint(1, 5)
# randomly give graph data None
for i in range(1, num_random + 1):
chose_x = random.randint(0, num_x)
while (x_list[chose_x] is None):
chose_x = random.randint(0, num_x)
x_list[chose_x] = None
return x_list
def save_data_as_csv(record_list):
exist = os.path.exists('info_record.csv')
with open("info_record.csv", "a+") as csv_file:
writer = csv.writer(csv_file)
# 先写入columns_name
if not exist:
writer.writerow(["username", "chart_type", "gounp_number", "missing_value", "number of y", "answer", "response_time"])
# 写入多行用writerows
writer.writerows(record_list)
def create_line_chart(data):
x = range(len(data))
plt.plot(x, data, linestyle='-')
answer, response_time = answer_question(data)
plt.clf()
plt.pause(1)
return answer, response_time
def create_plot_chart(data):
x = range(len(data))
plt.scatter(x, data)
answer, response_time = answer_question(data)
plt.clf()
plt.pause(1)
return answer, response_time
def create_graph(username, data_list):
plt.ion()
data_indexes = []
for i in range(0, 20):
data_indexes.append(i)
random.shuffle(data_indexes)
record_list = []
for index in data_indexes:
single_record = []
single_record.append(username)
missing_number = 0
for y_data in data_list[index]:
if y_data is None:
missing_number += 1
if index > 9:
answer, response_time = create_line_chart(data_list[index])
single_record.append('line chart')
single_record.append(index-10)
else:
answer, response_time = create_plot_chart(data_list[index])
single_record.append('plot chart')
single_record.append(index)
single_record.append(missing_number)
single_record.append(len(data_list[index]))
single_record.append(answer)
single_record.append(response_time)
record_list.append(single_record)
plt.close()
plt.ioff()
plt.show()
return record_list
def answer_question(data):
start_time = time.time()
number = input("How many missing value in this chart:")
response_time = time.time() - start_time
response_time = round(response_time, 2)
correct_number = 0
answer = False
for y_data in data:
if y_data is None:
correct_number += 1
if int(number) == correct_number:
answer = True
return answer, response_time
if __name__ == '__main__':
username = input("Input your user name: ")
data_list = create_data()
record_list = create_graph(username, data_list)
save_data_as_csv(record_list)