-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (43 loc) · 1.89 KB
/
main.py
File metadata and controls
59 lines (43 loc) · 1.89 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
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
from random import randrange
from functools import partial
from threading import Thread
from bokeh.layouts import column
from bokeh.plotting import figure, curdoc
from bokeh.models import Button, ColumnDataSource
import time
# TODO: 2. sorting and searching - write the sorting algorithms and searching algorithms
# TODO:- check how to visualize those..
# TODO: visualize the selection sort
# data = {'x_values': [1, 2, 3, 4, 5], 'y_values': [6, 7, 2, 3, 6]}
# {'x_values': [1, 2, 3, 4, 5], 'y_values': [6, 7, 2, 3, 6]}
arr = [11, 32, 311, 14, 5, 16, 17, 8, 19, 10]
data = dict(x=range(len(arr)), top=arr)
# only modify from a Bokeh session callback
source = ColumnDataSource(data=data)
# This is important! Save curdoc() to make sure all threads
# see the same document.
doc = curdoc()
async def update(new_data):
source.data = new_data
def blocking_task():
for i in range(len(arr)):
time.sleep(1.1)
new_data = dict(x=range(len(arr)), top=arr)
doc.add_next_tick_callback(partial(update, new_data))
print(arr)
min_index = i
for j in range(i, len(arr)):
if arr[min_index] > arr[j]:
min_index = j
arr[i], arr[min_index] = arr[min_index], arr[i] # swap
p = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
# line = p.line(x='x_values', y='y_values', legend_label="Temp.", line_width=2, source=source)
p.vbar(x='x', top="top", bottom=0, legend_label="Rate", width=0.5, color="red", source=source)
doc.add_root(p)
#WARNING when you provide parameter to blocking_task nothing will be shown before the blocking task is finished
# TODO: why? what is the reason?
thread = Thread(target=blocking_task)
thread.start()