Skip to content

Instantly share code, notes, and snippets.

View ruescasd's full-sized avatar

David Ruescas ruescasd

  • Sequent
View GitHub Profile
@ruescasd
ruescasd / hhhhht.scala
Created October 30, 2012 19:55
HHH, HHT
def base(pattern: String) = Stream.continually(util.Random.nextInt(2)) map { case 0 => 'H'; case 1 => 'T' } indexOfSlice(pattern)
def hhh = base("HHH") + 3
def hht = base("HHT") + 3
println (Seq.fill(10000)(hhh).foldLeft(0.0)(_+_) / 10000)
println (Seq.fill(10000)(hht).foldLeft(0.0)(_+_) / 10000)
import verificatum.eio.ByteTree;
import verificatum.eio.ByteTreeBasic;
import verificatum.eio.ByteTreeReader;
import verificatum.arithm.ModPGroup;
import verificatum.arithm.PGroup;
import verificatum.arithm.PGroupElement;
import verificatum.arithm.PGroupElementArray;
import verificatum.arithm.PPGroup;
import verificatum.arithm.PPGroupElement;
import verificatum.arithm.PRing;
import requests
import json
url = 'https://127.0.0.1:5000/public_api/election'
data = {
'session_id': 'vota1',
'is_recurring': False,
'callback_url': 'https://ec2-54-229-221-33.eu-west-1.compute.amazonaws.com:5000/public_api/receive_election',
'extra': [],
'title': 'New Directive Board',
DEBUG:root:EXEC ACTION handler for MESSAGE id 494b0186-86a3-4f9f-9d98-6c5f1b2a24dd (QUEUE orchestra_director)
DEBUG:requests.packages.urllib3.connectionpool:"POST /api/queues/orchestra_director/ HTTP/1.1" 200 0
ERROR:apscheduler.scheduler:Job "call_action_handler (trigger: now, next run at: None)" raised an exception
Traceback (most recent call last):
File "/home/eorchestra/venv/local/lib/python2.7/site-packages/APScheduler-2.1.1-py2.7.egg/apscheduler/scheduler.py", line 512, in _run_job
retval = job.func(*job.args, **job.kwargs)
File "/home/eorchestra/venv/local/lib/python2.7/site-packages/frestq-0.0.1-py2.7.egg/frestq/api.py", line 49, in call_action_handler
action_handler = ActionHandlers.get_action_handler(msg.action, queue_name)
DEBUG:requests.packages.urllib3.connectionpool:"POST /api/queues/orchestra_director/ HTTP/1.1" 200 0
DEBUG:apscheduler.threadpool:Started worker thread
INFO:apscheduler.scheduler:Running job "call_action_handler (trigger: now, next run at: 2013-10-26 14:58:04.580952)" (scheduled at 2013-10-26 14:58:04.580952)
DEBUG:root:EXEC ACTION handler for MESSAGE id 580e14ee-2f3f-4cc8-a770-07910585ac56 (QUEUE orchestra_director)
INFO:apscheduler.scheduler:Removed job "call_action_handler (trigger: now, next run at: None)"
DEBUG:apscheduler.scheduler:No jobs; waiting until a job is added
ERROR:apscheduler.scheduler:Job "call_action_handler (trigger: now, next run at: None)" raised an exception
Traceback (most recent call last):
File "/home/eorchestra/venv/local/lib/python2.7/site-packages/APScheduler-2.1.1-py2.7.egg/apscheduler/scheduler.py", line 512, in _run_job
retval = job.func(*job.args, **job.kwargs)
DEBUG:root:RECEIVED MESSAGE in queue orchestra_performer
DEBUG:root:The MESSAGE is NOT LOCAL and with id ff8e0521-845f-4e55-8dab-3c20363f7857
INFO:root:adding job in sched for queue orchestra_performer
INFO:apscheduler.scheduler:Added job "call_action_handler (trigger: now, next run at: 2013-10-27 21:17:58.255265)" to job store "default"
DEBUG:apscheduler.scheduler:Looking for jobs to run
DEBUG:apscheduler.threadpool:Started worker thread
[pid: 3807|app: 0|req: 224/224] 172.31.31.70 () {44 vars in 2972 bytes} [Sun Oct 27 21:17:58 2013] POST /api/queues/orchestra_performer/ => generated 0 bytes in 14 msecs (HTTP/1.1 200) 2 headers in 78 bytes (1 switches on core 2)
INFO:apscheduler.scheduler:Removed job "call_action_handler (trigger: now, next run at: None)"
DEBUG:apscheduler.scheduler:No jobs; waiting until a job is added
INFO:apscheduler.scheduler:Running job "call_action_handler (trigger: now, next run at: None)" (scheduled at 2013-10-27 21:17:58.255265)
DEBUG:requests.packages.urllib3.connectionpool:"POST /api/queues/orchestra_director/ HTTP/1.1" 200 0
DEBUG:apscheduler.threadpool:Started worker thread
INFO:apscheduler.scheduler:Running job "call_action_handler (trigger: now, next run at: None)" (scheduled at 2013-10-27 21:17:58.452791)
DEBUG:root:EXEC ACTION handler for MESSAGE id 4f0ae6bd-596e-4d25-ad26-ec5a16ebbcd1 (QUEUE orchestra_director)
DEBUG:root:EXEC TASK with id 34305258-8d51-4821-86f8-3576fcd83048
[pid: 4787|app: 0|req: 234/234] 172.31.47.237 () {44 vars in 2093 bytes} [Sun Oct 27 21:17:58 2013] POST /public_api/tally => generated 51 bytes in 152 msecs (HTTP/1.1 202) 2 headers in 85 bytes (1 switches on core 3)
DEBUG:root:CREATE local PARALLEL TASK with ID b867ff30-7284-4de0-9459-78230ac8b4a9
DEBUG:root:CREATE local TASK for action review_tally with ID df846e82-06ab-4e4f-84f5-73db68165c0e
DEBUG:root:CREATE local TASK for action review_tally with ID 726da413-eccd-4434-9f71-c3fddf18733d
david@david-VirtualBox:~/projects/agora-verifier/dir$ ls
agora_tally do_tally.py openstv tally.tar.gz
david@david-VirtualBox:~/projects/agora-verifier/dir$ python do_tally.py tally.tar.gz
Traceback (most recent call last):
File "do_tally.py", line 6, in <module>
print tally.do_tartally(sys.argv[1])
File "/home/david/projects/agora-verifier/dir/agora_tally/tally.py", line 53, in do_tartally
return do_tally(dir_path, result['counts'])
File "/home/david/projects/agora-verifier/dir/agora_tally/tally.py", line 65, in do_tally
voting_system = get_voting_system_by_id(tally_type)
def do_dirtally(dir_path):
res_path = os.path.join(dir_path, 'result_json')
with codecs.open(res_path, encoding='utf-8', mode='r') as res_f:
result = json.loads(res_f.read())
return do_tally(dir_path, result['counts'])
Podemos enforcarlo como una media ponderada, donde las ponderaciones son una especie de serie geometria, pero con probabilidades que varian. El exito en tiempo T require fracasos para t < T y exito en t = T.
Asi que tenemos que
P(Sucess = T) = Failure(0) * Failure(1) * ... * Failure(t-1) * Sucess(t)
y tambien sabemos que
Failure(t) = 1 - Sucess(t)