示例#1
0
    def __init__(self, parent):
        # GUI init
        self.parent = parent
        self.parent.title("9.3 Crowded Room")
        self.frame = tkinter.Frame(self.parent)
        self.frame.pack(fill=tkinter.BOTH, expand=1)
        tkinter.Label(self.frame, text='Crowded room simulation').pack()
        size = settings.get().canvas_size
        self.canvas = tkinter.Canvas(self.frame, width=size, height=size)
        self.canvas.pack()
        tkinter.Button(self.frame, text='Prepare', command=self.setup_simulation).pack(fill='x')
        tkinter.Button(self.frame, text='Start', command=self.start_simulation).pack(fill='x')
        tkinter.Button(self.frame, text='Stop', command=self.stop_simulation).pack(fill='x')

        self.jitter = tkinter.IntVar(self.frame, value=0)
        tkinter.Checkbutton(
            self.frame, text='Enable jitter', variable=self.jitter, command=self._on_jitter
        ).pack(fill='x')

        self.parent.resizable(width=tkinter.FALSE, height=tkinter.FALSE)

        # create model
        self.party = Party()

        # intermediate logic
        self.person_painters = []  # type: List[PersonPainter]
        self.prepared = False
        self.running = False
示例#2
0
def load_parties(session):
    with open('seed_data/parties.csv', 'rU') as csvfile:
        party_reader = csv.reader(csvfile, delimiter=',')
        next(party_reader, None)
        for party_row in party_reader:
            party             = Party()
            # party.id        = party_row[0]
            party.side        = party_row[1]
            party.grouping    = party_row[2]
            party.addr_1      = party_row[3]
            party.addr_2      = party_row[4]
            party.city        = party_row[5]
            party.state       = party_row[6]
            party.zipcode     = party_row[7]
            party.country     = party_row[8]

            session.add(party)
示例#3
0
def load_votes_matrix(box):
    parties = []
    parties_matrix = zip(PARTIES, VOTES_MATRIX)
    for party, flags in dict(parties_matrix).items():
        kwargs = {}
        for i, flag in enumerate(flags):
            counter = Counter(enabled=bool(flag))
            kwargs[CANDIDATES[i]] = counter
        _votes = Votes(**kwargs)
        _votes.save()
        _party = Party(name=party, votes=_votes)
        _party.save()
        parties.append(_party)
    box.parties = parties
    box.save()
    other_votes = OtherVotes(blank=votes_constructor(),
                             nulled=votes_constructor(),
                             recurrent=votes_constructor(),
                             refuted=votes_constructor()).save()
    box.other_votes = other_votes
    box.save()
示例#4
0
    def post(self):
        if self.params.characters:
            party = Party.get_current()
            characters = []
            for character in self.params.characters:
                c_id = character.get('id')
                clean(character)
                db_char = c_id and Character.get(c_id) or Character(party=party)

                for k, v in character.iteritems():
                    setattr(db_char, k, extract(k, v))
                db_char.put()
                characters.append(db_char)
                
            self.write(json.dumps([c.to_dict() for c in characters]))
        else:
            self.write(json.dumps([]))
示例#5
0
def save_results():
    other_votes = ["blank", "nulled", "recurrent", "refuted"]
    app.logger.debug("Saving results")
    field_id = request.form.get("field_id")
    _value = request.form.get("value")
    _id = field_id.split(".")[0]

    if _id in other_votes:
        other_votes = OtherVotes.objects(id=field_id.split(".")[1]).first()
        votes = other_votes[_id]
        votes[field_id.split(".")[2]].count = _value
        votes.save()
    else:
        party_obj = Party.objects(id=_id).first()
        votes = party_obj.votes
        votes[field_id.split(".")[1]].count = _value
        votes.save()

    return Response(status=200)
示例#6
0
class MainWindow(object):
    def _on_jitter(self):
        settings.get().jitter = self.jitter.get()

    def __init__(self, parent):
        # GUI init
        self.parent = parent
        self.parent.title("9.3 Crowded Room")
        self.frame = tkinter.Frame(self.parent)
        self.frame.pack(fill=tkinter.BOTH, expand=1)
        tkinter.Label(self.frame, text='Crowded room simulation').pack()
        size = settings.get().canvas_size
        self.canvas = tkinter.Canvas(self.frame, width=size, height=size)
        self.canvas.pack()
        tkinter.Button(self.frame, text='Prepare', command=self.setup_simulation).pack(fill='x')
        tkinter.Button(self.frame, text='Start', command=self.start_simulation).pack(fill='x')
        tkinter.Button(self.frame, text='Stop', command=self.stop_simulation).pack(fill='x')

        self.jitter = tkinter.IntVar(self.frame, value=0)
        tkinter.Checkbutton(
            self.frame, text='Enable jitter', variable=self.jitter, command=self._on_jitter
        ).pack(fill='x')

        self.parent.resizable(width=tkinter.FALSE, height=tkinter.FALSE)

        # create model
        self.party = Party()

        # intermediate logic
        self.person_painters = []  # type: List[PersonPainter]
        self.prepared = False
        self.running = False

    def _step_simulation(self):
        if not self.running:
            return

        # only keep running if modifications present
        self.running = self.party.update()

        if self.running:
            for p in self.person_painters:
                p.update()
            self.frame.after(50, self._step_simulation)

    def stop_simulation(self):
        self.running = False

    def start_simulation(self):
        if self.running:
            print('Already running')
            return

        if not self.prepared:
            print('Simulation not ready')
            return

        self.running = True
        self._step_simulation()

    def setup_simulation(self):
        if self.running:
            print('Not while running')
            return

        self.canvas.delete('all')
        self.party.setup()
        self.person_painters = []
        for p in self.party.persons:
            self.person_painters.append(PersonPainter(self.canvas, p))
        self.prepared = True
示例#7
0
 def get(self):
     party = Party.get_current()
     self.render('encounter.html',
         combatants=json.dumps([c.to_dict() for c in party.characters]))