Exemple #1
0
    def latest(self, conn=None):
        """
        Returns most recent SurveyData point available.
        """
        if not conn:
            conn = self.conn

        sql = "select * from %s where survey_id = %s ORDER BY created_at DESC LIMIT 1"
        rows = conn.execute(sql % (SurveyData.table_name(), self.id))
        row = rows.fetchone()
        if row:
            return SurveyData.load(conn, row)
Exemple #2
0
def take_survey(s):
    c = ado.commands.conn()
    if s < 0:
        Survey.printall(c)
        raw_s = ado.commands.clean_input("Choose a survey number: ")
        if raw_s:
            s = int(raw_s)
        else:
            sys.stderr.write("No survey chosen.\n")
            sys.exit(1)

    survey = Survey.get(c, s)
    print "Taking Survey %s) %s" % (survey.id, survey.name)
    print survey.description
    value = ado.commands.clean_input("> ")

    SurveyData.create(c, survey_id=s, value=value, created_at=datetime.now())
Exemple #3
0
    def data(self, conn=None):
        """
        Returns iterator of all data points.
        """
        sql = "select * from %s where survey_id = %s ORDER BY created_at"

        rows = conn.execute(sql % (SurveyData.table_name(), self.id))
        for row in rows:
            yield row
Exemple #4
0
def test_survey():
    conn = Model.setup_db()
    Survey.create_table(conn)
    survey = Survey.create(conn,
            created_at = datetime.now(),
            name = "how do you feel",
            description = "How do you feel?")

    assert survey.id > 0

    SurveyData.create_table(conn)
    a1 = SurveyData.create(conn,
            survey_id = survey.id,
            value = "I feel fine."
            )

    assert a1.id > 0

    latest = survey.latest()
    assert latest.id == a1.id
    assert latest.value == "I feel fine."