Exemplo n.º 1
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())
Exemplo n.º 2
0
def due_command():
    c = ado.commands.conn()
    for survey in Survey.all_due(c):
        take_survey(survey.id)
    for metric in Metric.all_due(c):
        record_metric(metric.id)
    for recipe in Recipe.all_due(c):
        ado.commands.recipe.do_command(recipe.id)
Exemplo n.º 3
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."
Exemplo n.º 4
0
def values_command(m=-1, s=-1):  # The metric id to print data for.  # The survey id to print data for.
    """
    Returns space-separated data for a metric, or longer form data for a survey.
    
    Metric output can be piped to spark. https://github.com/holman/spark
    """
    c = conn()
    if m > 0:
        metric = Metric.get(c, m)
        datetimes, values = metric.ts(c)
        print " ".join("%s" % v for v in values)
    elif s > 0:
        survey = Survey.get(c, s)
        for row in survey.data(c):
            print row["created_at"]
            print row["value"]
            print ""
Exemplo n.º 5
0
def ok_command(debug=False):
    c = ado.commands.conn()
    surveys_due = bool(Survey.all_due(c))
    metrics_due = bool(Metric.all_due(c))
    recipes_due = bool(Recipe.all_due(c))

    if debug:
        print "Are surveys due?", surveys_due
        print "Are metrics due?", metrics_due
        print "Are recipes due?", recipes_due

    ok = (not surveys_due) and (not metrics_due) and (not recipes_due)
    if ok:
        if debug:
            print "nothing is due"
        sys.exit(0)
    else:
        print "something is due"
        sys.exit(1)
Exemplo n.º 6
0
def create_survey(name, frequency, description):
    c = ado.commands.conn()
    survey = Survey.create(c, name=name, frequency=frequency, description=description, created_at=datetime.now())
    print survey.id