-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats_client_ravelled_blocking
More file actions
executable file
·42 lines (37 loc) · 1.24 KB
/
stats_client_ravelled_blocking
File metadata and controls
executable file
·42 lines (37 loc) · 1.24 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
#!/usr/bin/python3
#+
# DBussy/Ravel example -- demo client for communicating with the stats_server.
#
# Copyright 2017 by Lawrence D'Oliveiro <ldo@geek-central.gen.nz>. This
# script is licensed CC0
# <https://creativecommons.org/publicdomain/zero/1.0/>; do with it
# what you will.
#-
import sys
import random
import ravel
stats_bus_name = "com.example.stats"
stats_path_name = "/com/example/stats"
stats_iface_name = "com.example.stats"
nr_nums = random.randint(10, 20)
nums = list(random.random() for i in range(nr_nums))
server = ravel.session_bus()[stats_bus_name][stats_path_name] \
.get_interface(stats_iface_name)
sys.stdout.write("nums = %s\n" % repr(nums))
results = {}
for key, val in zip(["mean", "stdev", "pstdev"], server.mean_and_deviation(nums)) :
results[key] = val
#end for
if hasattr(server, "harmonic_mean") :
results["harmonic_mean"] = server.harmonic_mean(nums)[0]
else :
sys.stdout.write("harmonic_mean not available\n")
#end if
for key, val in zip(["median", "max", "min"], server.hi_lo(nums)) :
results[key] = val
#end for
for key in sorted(results) :
sys.stdout.write("%s = %.3g\n" % (key, results[key]))
#end for
choice = server.pick_one("i_win", "you_lose")
sys.stdout.write("pick_one choice = %s\n" % choice)