Esempio n. 1
0
    def _display_questfinal(self):
        if not self._le2mserv.gestionnaire_base.is_created():
            QtGui.QMessageBox.warning(
                self._le2mserv.gestionnaire_graphique.screen,
                le2mtrans(u"Warning"),
                le2mtrans(u"There is no database yet. You first need to "
                          u"load at least one part."))
            return
        if not hasattr(self, "_tous"):
            QtGui.QMessageBox.warning(
                self._le2mserv.gestionnaire_graphique.screen,
                le2mtrans(u"Warning"),
                trans_PGGS(u"PGGS has to be run before to "
                         u"start this questionnaire"))
            return

        confirmation = QtGui.QMessageBox.question(
            self._le2mserv.gestionnaire_graphique.screen,
            le2mtrans(u"Confirmation"),
            le2mtrans(u"Start the final questionnaire?"),
            QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Ok)
        if confirmation != QtGui.QMessageBox.Ok:
            return

        yield (self._le2mserv.gestionnaire_experience.run_step(
            trans_PGGS(u"Final questionnaire"), self._tous,
            "display_questfinal"))
    def __init__(self, defered, automatique, parent, text, expec_before=None):
        QtGui.QDialog.__init__(self, parent)

        self._defered = defered
        self._automatique = automatique

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)

        explanation = WExplication(text=text[0])
        layout.addWidget(explanation)

        self._spin_expectation = WSpinbox(parent=self,
                                          minimum=pms.DECISION_MIN,
                                          maximum=pms.DECISION_MAX,
                                          interval=pms.DECISION_STEP,
                                          label=text[1],
                                          automatique=self._automatique)
        if expec_before is not None:
            self._spin_expectation.spinBox.setValue(expec_before)
        layout.addWidget(self._spin_expectation)

        button = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
        button.accepted.connect(self._accept)
        layout.addWidget(button)

        self.setWindowTitle(trans_PGGS(u"Expectation"))
        self.adjustSize()
        self.setFixedSize(self.size())

        if self._automatique:
            self._timer = QtCore.QTimer()
            self._timer.timeout.connect(self._accept)
            self._timer.start(7000)
 def _accept(self):
     if self._countdown.is_running():
         confirmation = QtGui.QMessageBox.question(
             self, "Confirmation",
             trans_PGGS(
                 u"Do you want to quit before the end of the timer?"),
             QtGui.QMessageBox.Cancel | QtGui.QMessageBox.Yes)
         if confirmation != QtGui.QMessageBox.Yes:
             return
         else:
             self._countdown.stop()
     answers = sum([int(g.is_ok()) for g in self._widgets_grilles])
     if not self._automatique:
         QtGui.QMessageBox.information(
             self, "Information",
             trans_PGGS(u"You've found {} grids.").format(answers))
     logger.info("send back {}".format(answers))
     self.accept()
     self._defered.callback(answers)
Esempio n. 4
0
 def _configure(self):
     """
     To make changes in the parameters
     :return:
     """
     screen = DConfig(self._le2mserv.gestionnaire_graphique.screen)
     if screen.exec_():
         params = [
             le2mtrans(u"Treatment") + u": {}".format(
                 pms.TREATMENTS_NAMES[pms.TREATMENT]),
             trans_PGGS(u"Number of periods") + u": {}".format(
                 pms.NOMBRE_PERIODES),
             trans_PGGS(u"Groups' size") + u": {}".format(
                 pms.TAILLE_GROUPES),
             trans_PGGS(u"MPCR (normal)") + u": {}".format(pms.MPCR_NORM),
             trans_PGGS(u"MPCR (solidarity)") + u": {}".format(pms.MPCR_SOL),
             trans_PGGS(u"Expectations") + u": {}".format(pms.EXPECTATIONS)
         ]
         self._le2mserv.gestionnaire_graphique.infoserv(params)
    def __init__(self, defered, automatique, parent, periode, historique,
                 grilles):
        QtGui.QDialog.__init__(self, parent)

        self._defered = defered
        self._automatique = automatique
        self._grilles = grilles
        self._historique = GuiHistorique(self,
                                         historique,
                                         size=(HISTO_WIDTH, 500))

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)

        # period and history button
        wperiod = WPeriod(period=periode,
                          ecran_historique=self._historique,
                          parent=self)
        layout.addWidget(wperiod)

        explanation = WExplication(
            parent=self,
            text=texts_PGGS.get_text_explanation_grilles(),
            size=(600, 100))
        layout.addWidget(explanation)

        self._countdown = WCompterebours(self,
                                         temps=pms.TIME_TO_FILL_GRILLES,
                                         actionfin=self._accept)
        layout.addWidget(self._countdown)

        grid_layout = QtGui.QGridLayout()
        layout.addLayout(grid_layout)

        self._widgets_grilles = list()
        current_line = 0
        for i, g in enumerate(self._grilles):
            self._widgets_grilles.append(WGrid(g, self._automatique))
            grid_layout.addWidget(self._widgets_grilles[-1], current_line,
                                  i - current_line * pms.NB_GRILLES_PER_LINE)
            if i > 0 and (i + 1) % pms.NB_GRILLES_PER_LINE == 0:
                current_line += 1

        buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
        buttons.accepted.connect(self._accept)
        layout.addWidget(buttons)

        self.adjustSize()
        self.setFixedSize(self.size())
        self.setWindowTitle(trans_PGGS(u"Tasks"))
    def __init__(self, defered, automatique, parent, periode, historique,
                 max_decision):
        super(GuiDecision, self).__init__(parent)

        # variables
        self._defered = defered
        self._automatique = automatique
        self._historique = GuiHistorique(self,
                                         historique,
                                         size=(HISTO_WIDTH, 500))
        self._max_decision = max_decision

        layout = QtGui.QVBoxLayout(self)

        # period and history button
        wperiod = WPeriod(period=periode,
                          ecran_historique=self._historique,
                          parent=self)
        layout.addWidget(wperiod)

        wexplanation = WExplication(text=texts_PGGS.get_text_explanation(),
                                    parent=self,
                                    size=(500, 60))
        layout.addWidget(wexplanation)

        self._wcontrib = WSpinbox(minimum=0,
                                  maximum=self._max_decision,
                                  automatique=self._automatique,
                                  parent=self,
                                  label=trans_PGGS(
                                      u"How much do you invest in "
                                      u"the public account?"))
        layout.addWidget(self._wcontrib)

        buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
        buttons.accepted.connect(self._accept)
        layout.addWidget(buttons)

        self.setWindowTitle(le2mtrans(u"Decision"))
        self.adjustSize()
        self.setFixedSize(self.size())

        if self._automatique:
            self._timer_automatique = QtCore.QTimer()
            self._timer_automatique.timeout.connect(
                buttons.button(QtGui.QDialogButtonBox.Ok).click)
            self._timer_automatique.start(7000)
    def __init__(self, defered, automatique, parent, text):
        QtGui.QDialog.__init__(self, parent)

        self._defered = defered
        self._automatique = automatique

        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)

        explanation = WExplication(text[0])
        layout.addWidget(explanation)

        form_layout = QtGui.QFormLayout()
        layout.addLayout(form_layout)

        self._spin_expectation_favor = QtGui.QSpinBox()
        self._spin_expectation_favor.setMinimum(pms.DECISION_MIN)
        self._spin_expectation_favor.setMaximum(pms.DECISION_MAX)
        self._spin_expectation_favor.setButtonSymbols(QtGui.QSpinBox.NoButtons)
        form_layout.addRow(QtGui.QLabel(text[1]), self._spin_expectation_favor)

        self._spin_expectation_against = QtGui.QSpinBox()
        self._spin_expectation_against.setMinimum(pms.DECISION_MIN)
        self._spin_expectation_against.setMaximum(pms.DECISION_MAX)
        self._spin_expectation_against.setButtonSymbols(
            QtGui.QSpinBox.NoButtons)
        form_layout.addRow(QtGui.QLabel(text[2]),
                           self._spin_expectation_against)

        button = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok)
        button.accepted.connect(self._accept)
        layout.addWidget(button)

        self.setWindowTitle(trans_PGGS(u"Expectation"))
        self.adjustSize()
        self.setFixedSize(self.size())

        if self._automatique:
            self._spin_expectation_favor.setValue(randint(0, pms.DECISION_MAX))
            self._spin_expectation_against.setValue(
                randint(0, pms.DECISION_MAX))
            self._timer = QtCore.QTimer()
            self._timer.timeout.connect(self._accept)
            self._timer.start(7000)
    def __init__(self, parent):
        super(DConfig, self).__init__(parent)

        layout = QtGui.QVBoxLayout(self)
        self.setLayout(layout)

        form = QtGui.QFormLayout()
        layout.addLayout(form)

        # treatment
        self._combo_treat = QtGui.QComboBox()
        self._combo_treat.addItems(
            [v for k, v in sorted(pms.TREATMENTS_NAMES.viewitems())])
        form.addRow(QtGui.QLabel(le2mtrans(u"Treatment")), self._combo_treat)

        # periods
        self._spin_periods = QtGui.QSpinBox()
        self._spin_periods.setMinimum(0)
        self._spin_periods.setMaximum(100)
        self._spin_periods.setSingleStep(1)
        self._spin_periods.setButtonSymbols(QtGui.QSpinBox.NoButtons)
        self._spin_periods.setFixedWidth(50)
        self._spin_periods.setValue(pms.NOMBRE_PERIODES)
        form.addRow(QtGui.QLabel(trans_PGGS(u"Number of periods")),
                    self._spin_periods)

        # group size
        self._spin_group_size = QtGui.QSpinBox()
        self._spin_group_size.setMinimum(0)
        self._spin_group_size.setMaximum(100)
        self._spin_group_size.setSingleStep(1)
        self._spin_group_size.setButtonSymbols(QtGui.QSpinBox.NoButtons)
        self._spin_group_size.setFixedWidth(50)
        self._spin_group_size.setValue(pms.TAILLE_GROUPES)
        form.addRow(QtGui.QLabel(trans_PGGS(u"Group size")),
                    self._spin_group_size)

        # mpcr normal
        self._spin_mpcr_normal = QtGui.QDoubleSpinBox()
        self._spin_mpcr_normal.setDecimals(2)
        self._spin_mpcr_normal.setMinimum(0)
        self._spin_mpcr_normal.setMaximum(5)
        self._spin_mpcr_normal.setSingleStep(0.01)
        self._spin_mpcr_normal.setButtonSymbols(QtGui.QSpinBox.NoButtons)
        self._spin_mpcr_normal.setFixedWidth(50)
        self._spin_mpcr_normal.setValue(pms.MPCR_NORM)
        form.addRow(QtGui.QLabel(trans_PGGS(u"MPCR (normal)")),
                    self._spin_mpcr_normal)

        # mpcr solidarity
        self._spin_mpcr_solidarity = QtGui.QDoubleSpinBox()
        self._spin_mpcr_solidarity.setDecimals(2)
        self._spin_mpcr_solidarity.setMinimum(0)
        self._spin_mpcr_solidarity.setMaximum(5)
        self._spin_mpcr_solidarity.setSingleStep(0.01)
        self._spin_mpcr_solidarity.setButtonSymbols(QtGui.QSpinBox.NoButtons)
        self._spin_mpcr_solidarity.setFixedWidth(50)
        self._spin_mpcr_solidarity.setValue(pms.MPCR_SOL)
        form.addRow(QtGui.QLabel(trans_PGGS(u"MPCR (solidarity)")),
                    self._spin_mpcr_solidarity)

        # expectation
        self._checkbox_expectation = QtGui.QCheckBox()
        self._checkbox_expectation.setChecked(pms.EXPECTATIONS)
        form.addRow(QtGui.QLabel(trans_PGGS(u"Expectations")),
                    self._checkbox_expectation)

        # number of grid
        self._spin_nb_grilles = QtGui.QSpinBox()
        self._spin_nb_grilles.setMinimum(0)
        self._spin_nb_grilles.setMaximumWidth(100)
        self._spin_nb_grilles.setSingleStep(1)
        self._spin_nb_grilles.setButtonSymbols(QtGui.QSpinBox.NoButtons)
        self._spin_nb_grilles.setValue(pms.NB_GRILLES)
        self._spin_nb_grilles.setFixedWidth(50)
        form.addRow(QtGui.QLabel(trans_PGGS(u"Number of grids")),
                    self._spin_nb_grilles)

        # grid size
        self._spin_grilles_size = QtGui.QSpinBox()
        self._spin_grilles_size.setMinimum(0)
        self._spin_grilles_size.setMaximumWidth(100)
        self._spin_grilles_size.setSingleStep(1)
        self._spin_grilles_size.setButtonSymbols(QtGui.QSpinBox.NoButtons)
        self._spin_grilles_size.setValue(pms.SIZE_GRILLES)
        self._spin_grilles_size.setFixedWidth(50)
        form.addRow(QtGui.QLabel(trans_PGGS(u"Grid size")),
                    self._spin_grilles_size)

        buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Cancel
                                         | QtGui.QDialogButtonBox.Ok)
        buttons.accepted.connect(self._accept)
        buttons.rejected.connect(self.reject)
        layout.addWidget(buttons)

        self.setWindowTitle(le2mtrans(u"Configure"))
        self.adjustSize()
        self.setFixedSize(self.size())
Esempio n. 9
0
    def _demarrer(self):
        """
        Start the part
        :return:
        """
        # check conditions =====================================================
        if self._le2mserv.gestionnaire_joueurs.nombre_joueurs == 0:
            self._le2mserv.gestionnaire_graphique.display_error(
                le2mtrans(u"No clients connected!"))
            return
        if pms.TREATMENT == pms.BASELINE:
            if self._le2mserv.gestionnaire_joueurs.nombre_joueurs % \
                    pms.TAILLE_GROUPES != 0:
                self._le2mserv.gestionnaire_graphique.display_error(
                    le2mtrans(u"The number of players is not compatible with "
                              u"the groups size"))
                return
        else:
            if self._le2mserv.gestionnaire_joueurs.nombre_joueurs % \
                    (2 * pms.TAILLE_GROUPES) != 0:
                self._le2mserv.gestionnaire_graphique.display_error(
                    le2mtrans(u"The number of players is not compatible with "
                              u"the groups size"))
                return

        confirmation = self._le2mserv.gestionnaire_graphique.\
            question(le2mtrans(u"Start") + u" PublicGoodGameSolidarity?")
        if not confirmation:
            return

        # init part ============================================================
        yield (self._le2mserv.gestionnaire_experience.init_part(
            "PublicGoodGameSolidarity", "PartiePGGS", "RemotePGGS", pms))
        self._tous = self._le2mserv.gestionnaire_joueurs.get_players(
            'PublicGoodGameSolidarity')

        self._currentsequence += 1
        self._le2mserv.gestionnaire_graphique.infoserv(
            trans_PGGS(u"Sequence") + u" {}".format(
                self._currentsequence))

        # configure part (player and remote)
        yield (self._le2mserv.gestionnaire_experience.run_step(
            u"Configure", self._tous, "configure", self._currentsequence))
        
        # form groups
        self._le2mserv.gestionnaire_groupes.former_groupes(
            self._le2mserv.gestionnaire_joueurs.get_players(),
            pms.TAILLE_GROUPES, forcer_nouveaux=False)

        # Start ================================================================
        for period in range(1 if pms.NOMBRE_PERIODES else 0,
                        pms.NOMBRE_PERIODES + 1):

            if self._le2mserv.gestionnaire_experience.stop_repetitions:
                break

            # init period ------------------------------------------------------
            self._le2mserv.gestionnaire_graphique.infoserv(
                [None, le2mtrans(u"Period") + u" {}".format(period)])
            self._le2mserv.gestionnaire_graphique.infoclt(
                [None, le2mtrans(u"Period") + u" {}".format(period)],
                fg="white", bg="gray")
            yield (self._le2mserv.gestionnaire_experience.run_func(
                self._tous, "newperiod", period))

            # SINISTRE & VOTE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            if period == 1 and pms.TREATMENT != pms.BASELINE:

                # the first ones are not sinistred, the seconds ones are
                groups_keys = self._le2mserv.gestionnaire_groupes.\
                    get_groupes("PublicGoodGameSolidarity").keys()
                self._groups_pairs = zip(
                    groups_keys[:len(groups_keys) // 2],
                    groups_keys[len(groups_keys) // 2:])
                self._le2mserv.gestionnaire_graphique.infoserv(
                    u"Group pairs (not sinistred, sinistred)")
                for notsin, sin in self._groups_pairs:
                    self._le2mserv.gestionnaire_graphique.infoserv(
                        u"G" + group_format(notsin) + u"- G" + group_format(
                            sin))

                # set sinistred or not in players' data
                self._not_sinistred_players = list()
                self._sinistred_players = list()
                for notsin, sin in self._groups_pairs:
                    self._not_sinistred_players.extend(
                        self._get_group_players(notsin))
                    self._sinistred_players.extend(self._get_group_players(sin))
                for j in self._not_sinistred_players:
                    j.sinistred = False
                    j.currentperiod.PGGS_sinistred = j.sinistred
                for j in self._sinistred_players:
                    j.sinistred = True
                    j.currentperiod.PGGS_sinistred = j.sinistred

                # display
                yield (self._le2mserv.gestionnaire_experience.run_step(
                    trans_PGGS(u"Information sinistre"), self._tous,
                    "display_infosinistre"))

                # vote ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                if pms.TREATMENT == pms.SOL_VOTE or \
                pms.TREATMENT == pms.SOL_VOTE_CONDITIONAL:

                    # expectation before the vote
                    if pms.EXPECTATIONS:
                        yield (self._le2mserv.gestionnaire_experience.run_step(
                            trans_PGGS(u"Expectations"),
                            self._not_sinistred_players,
                            "display_expectations_vote", before_vote=True))

                    yield (self._le2mserv.gestionnaire_experience.run_step(
                        trans_PGGS(u"Vote"), self._not_sinistred_players,
                        "display_vote"))

                    # result of the vote
                    for notsin, sin in self._groups_pairs:
                        notsin_p = self._get_group_players(notsin)
                        sin_p = self._get_group_players(sin)
                        votes_for = pms.TAILLE_GROUPES - \
                                    sum([j.vote for j in notsin_p])
                        vote_majority = pms.IN_FAVOR if \
                            votes_for > pms.TAILLE_GROUPES / 2 else \
                            pms.AGAINST
                        for j in notsin_p + sin_p:
                            j.set_votes(votesfor=votes_for,
                                        votemajority=vote_majority)
                        self._le2mserv.gestionnaire_graphique.infoserv(
                            u"G{}: {}".format(
                                group_format(notsin),
                                text_PGGS.VOTES.get(vote_majority)))

                    # display info vote
                    yield (self._le2mserv.gestionnaire_experience.run_step(
                        trans_PGGS(u"Info vote"), self._tous,
                        "display_infovote"))

            # expectation ------------------------------------------------------
            if period == 1 and pms.EXPECTATIONS:
                if pms.TREATMENT == pms.SOL_VOTE or \
                pms.TREATMENT == pms.SOL_VOTE_CONDITIONAL:
                    yield (self._le2mserv.gestionnaire_experience.run_step(
                        trans_PGGS(u"Expectations"), self._not_sinistred_players,
                        "display_expectations_vote", before_vote=False))
                else:
                    who = self._not_sinistred_players if \
                        pms.TREATMENT != pms.BASELINE else self._tous
                    yield (self._le2mserv.gestionnaire_experience.run_step(
                        trans_PGGS(u"Expectations"), who,
                        "display_expectations"))

            # decision ---------------------------------------------------------
            # the decision screen is displayed on every screen, even when the
            # player cannot contribute
            # if treatments with conditionality then sinistred players have the
            # effort screen
            yield(self._le2mserv.gestionnaire_experience.run_step(
                le2mtrans(u"Decision"), self._tous, "display_decision"))

            for g, m in self._le2mserv.gestionnaire_groupes.get_groupes(
                    "PublicGoodGameSolidarity").items():
                group_contrib = sum(
                    [j.currentperiod.PGGS_groupaccount for j in m])
                self._le2mserv.gestionnaire_graphique.infoserv(
                    u"G{}: {}".format(group_format(g), group_contrib))
                for j in m:
                    j.currentperiod.PGGS_groupaccountsum = group_contrib

            self._deal_with_decisions()

            # compute difference between expectations and realisations ---------
            if period == 1 and pms.EXPECTATIONS:
                self._le2mserv.gestionnaire_graphique.infoclt(
                    u"EXPECTATION PAYOFFS")
                who = self._tous if pms.TREATMENT == pms.BASELINE else \
                    self._not_sinistred_players
                yield (self._le2mserv.gestionnaire_experience.run_func(
                 who, "compute_expectations_payoffs"))

            # period payoffs ---------------------------------------------------
            self._le2mserv.gestionnaire_experience.compute_periodpayoffs(
                "PublicGoodGameSolidarity")
        
            # summary ----------------------------------------------------------
            yield(self._le2mserv.gestionnaire_experience.run_step(
                le2mtrans(u"Summary"), self._tous, "display_summary"))
        
        # End of part ==========================================================
        yield (self._le2mserv.gestionnaire_experience.finalize_part(
            "PublicGoodGameSolidarity"))