Example #1
0
 def create(cls, scope, user, action, subject=None, with_vote=False):
     from tally import Tally
     from vote import Vote
     from adhocracy.lib.democracy import Decision
     poll = Poll(scope, user, action, subject=subject)
     meta.Session.add(poll)
     meta.Session.flush()
     if with_vote:
         decision = Decision(user, poll)
         decision.make(Vote.YES)
     Tally.create_from_poll(poll)
     meta.Session.flush()
     return poll
Example #2
0
File: poll.py Project: whausen/part
 def create(cls, scope, user, action, subject=None, with_vote=False):
     from tally import Tally
     from vote import Vote
     from adhocracy.lib.democracy import Decision
     poll = Poll(scope, user, action, subject=subject)
     meta.Session.add(poll)
     meta.Session.flush()
     if with_vote:
         decision = Decision(user, poll)
         decision.make(Vote.YES)
     Tally.create_from_poll(poll)
     meta.Session.flush()
     return poll
Example #3
0
File: poll.py Project: whausen/part
 def tally(self):
     if self._tally is None:
         if len(self.tallies):
             self._tally = self.tallies[0]
         else:
             from tally import Tally
             self._tally = Tally.create_from_poll(self)
     return self._tally
Example #4
0
 def tally(self):
     if self._tally is None:
         if len(self.tallies):
             self._tally = self.tallies[0]
         else:
             from tally import Tally
             self._tally = Tally.create_from_poll(self)
     return self._tally
Example #5
0
 def check_stable(self, at_time):
     from tally import Tally
     end = datetime.utcnow() if at_time is None else at_time
     start = end - self.scope.instance.activation_timedelta
     tallies = Tally.all_samples(self, start, end)
     if not len(tallies):
         return False
     if tallies[0].create_time > start:
         return False
     for tally in tallies:
         if not (tally.has_participation() and tally.has_majority()):
             return False
     return True
Example #6
0
File: poll.py Project: whausen/part
 def check_stable(self, at_time):
     from tally import Tally
     end = datetime.utcnow() if at_time is None else at_time
     start = end - self.scope.instance.activation_timedelta
     tallies = Tally.all_samples(self, start, end)
     if not len(tallies):
         return False
     if tallies[0].create_time > start:
         return False
     for tally in tallies:
         if not (tally.has_participation() and
                 tally.has_majority()):
             return False
     return True
Example #7
0
from tally import Tally
from time import sleep
"""
Script to quickly check if all lights are working correctly
Also, for situations where michael needs kit2000
"""
t = Tally()
up = True
i = 0
while True:
    if up:
        i = i + 1
        if i > 2:
            up = False
    else:
        i = i - 1
        if i < 1:
            up = True
    t.send_activation(i)
    sleep(0.8)
Example #8
0
 def variant_tally(self, variant):
     from tally import Tally
     polls = self.variant_polls(variant)
     return Tally.combine_polls(polls)
Example #9
0
 def variant_tally(self, variant):
     from tally import Tally
     polls = self.variant_polls(variant)
     return Tally.combine_polls(polls)
Example #10
0
	multiFields = getMultiValueFields (rp)
	if not multiFields.isEmpty():
		print "\n%s" % rp.recId
		if multiFields.webcat:
			print "webcat multifields"
			for field in multiFields.webcat.keys():
				print "\t%s (%d)" % (field, multiFields.webcat[field])
		if multiFields.library_dc:
			print "library_dc multifields"
			for field in multiFields.library_dc.keys():
				print "\t%s (%d)" % (field, multiFields.library_dc[field])

		
## -------- Tally stuff --------------
""" which webcat fields had multiple values?? """
webcatMultiFieldTally = Tally ("webcatMultiFields")

def tallyMultiFields (rp):
	multiFields = getMultiValueFields (rp)
	if not multiFields.webcat: return
	for field in multiFields.webcat.keys():
		webcatMultiFieldTally.tally (field)
		
def webCatMultiFieldTally ():
	cp ("technotes", tallyMultiFields)
	mp(tallyMultiFields)
	for key in webcatMultiFieldTally.keys():
		print "\t%s (%d)" % (key, webcatMultiFieldTally[key])
				
if __name__ == "__main__":
	# cp ("technotes", showMultiValueFields)
Example #11
0
def test_new_tally(token, api_url, dataset_data, dataset_meta):
    tally = Tally(api_key=token, host=api_url, ssl=True)
    assert True
Example #12
0
from tally import Tally
from more_itertools import repeatfunc, first
from itertools import islice
import silly
import random

t = Tally()


def print_results(t):
    for i, namevotes in enumerate(islice(t.descending(), 0, 3)):
        name, votes = namevotes
        print("#{} is {} with {} votes. ".format(i + 1, name, votes), end='\t')
    print()

an_infinite_stream_of_random_names = repeatfunc(silly.firstname)
for num in an_infinite_stream_of_random_names:
    t.tally(num)
    print_results(t)

    if random.random() < .01:
        name, votes = first(t.descending())
        t.remove(name)
        print('OH NO!!! {} JUST GOT BLUE-SHELLED'.format(name))
Example #13
0
def showInstName(rp):
    print "\n%s" % rp.recId
    print "\tinstName: %s" % getInstName(rp)
    print "\tinstDivision: %s" % getInstDivision(rp)


def showInstName(rp):
    print "\n%s" % rp.recId
    print "\tinstName: %s" % getInstName(rp)
    print "\tinstDivision: %s" % getInstDivision(rp)


# ---------------------------

instNames = Tally("instNames")
instDivisions = Tally("instDivisions")
publishers = Tally("publishers")
scientificDivisions = Tally("scientificDivisions")


def tally(rp):
    """
	for each record processed, tallies the following fields
	"""
    instNames.tally(getInstName(rp))
    instDivisions.tally(getInstDivision(rp))
    publishers.tally(getPublisher(rp))
    scientificDivisions.tally(getScientificDivision(rp))