Exemple #1
0
    def test_update_db(self):
        """Tests to make sure that Sms objects that are stored in the database are storing correctly.
        Tests the functionality of the Sms feedback use case: storing and accessing feedback

        **Passes when**: The system can process Sms data that is sent and update the database. 
        Can query with a date range while rejecting invalid dates. Can correctly read sms data

        **Fails when**: System has errors in processing sms. Cannot read information from the Sms object
        The sms database is not empty when deleted and invalid date ranges are specified

        """
        #TODO: if twilio connection not maintained
        self.assertEqual(
            feedback_controller.update_db(datetime(2016, 3, 21),
                                          update_from="test"), 1)
        self.assertEqual(
            feedback_controller.update_db(datetime(2027, 3, 21),
                                          update_from="test"), 0)
        query = Sms.delete()
        res = query.execute()
        self.assertEqual(len(Sms.select()), 0)
        feedback_controller.update_db(update_from="test")
        self.assertTrue(len(Sms.select()) > 0)
        smss = Sms.select().where(Sms.sid == 1)
        for sms in smss:
            self.assertEqual(sms.phone_num, "+12345678905")
        query = Sms.delete()
        res = query.execute()
        self.assertEqual(len(Sms.select()), 0)
Exemple #2
0
def delete_twilio_feedback():
    """Wipe all message history on twilio since a specified time. Only needs to be called once to clear data.

    Returns:
        res(str): Confirmation string
    """
    smss = Sms.select().where(Sms.submission_time >= datetime(
        2017, 4, 25, 2, 35, 00))  #2017-04-25 02:49:49
    sidd = []
    for sms in smss:
        sidd.append(sms.sid)
    #print(sidd)
    feedback_controller.delete_twilio_feedback(sidd)
    return "Twilio Feedback deleted"
Exemple #3
0
def feedback_table(role):
    """
    By default displays a webpage for user to make feedback DB query.
    Display a table of feedback sent in during a specified date-time range.
    Also, depending on whether category flags are specified, this page will only display that category
    table: table of feedback to display
    form: form that specifies the query instructions.

    Args:
        role(str): correct role of user in this context acquired from the require_role wrapper
    
    Returns:
        template: The template to display with the appropriate parameters
    """
    #get all of the feedback objects and insert it into table
    form = DateSpecifyForm()
    if (request.method == 'POST'):
        pos_col, neg_col, except_col, food_col, service_col = (
            -1, -1, -1, -1, -1)  # -1 is a don't care term
        dtf = datetime.strptime(request.form['datetimefrom'],
                                "%m/%d/%Y %I:%M %p")
        dtt = datetime.strptime(request.form['datetimeto'],
                                "%m/%d/%Y %I:%M %p") + timedelta(minutes=2)
        query_expr = ((Sms.submission_time > dtf) &
                      (Sms.submission_time <= dtt) &
                      (Sms.invalid_field == False))
        if (request.form.get('dropdown') == 'Good'):
            #print('Form Good')
            pos_col, neg_col = (1, 0)
            query_expr = ((query_expr) & (Sms.pos_flag == pos_col) &
                          (Sms.neg_flag == neg_col))
        elif (request.form.get('dropdown') == 'Bad'):
            pos_col, neg_col = (0, 1)
            query_expr = ((query_expr) & (Sms.pos_flag == pos_col) &
                          (Sms.neg_flag == neg_col))
        elif (request.form.get('dropdown') == 'Mixed'):
            pos_col, neg_col = (1, 1)
            query_expr = ((query_expr) & (Sms.pos_flag == pos_col) &
                          (Sms.neg_flag == neg_col))
        elif (request.form.get('dropdown') == 'Food'):
            food_col = 1
            query_expr = ((query_expr) & (Sms.food_flag == food_col))
        elif (request.form.get('dropdown') == 'Service'):
            service_col = 1
            query_expr = ((query_expr) & (Sms.service_flag == service_col))
        elif (request.form.get('dropdown') == 'Exception'):
            except_col = 1
            query_expr = ((query_expr) & (Sms.exception_flag == except_col))
        else:
            pos_col, neg_col, except_col, food_col, service_col = (-1, -1, -1,
                                                                   -1, -1)
        feedback_controller.update_db()
        smss = Sms.select().where(query_expr).order_by(-Sms.submission_time)
        res = []
        all_string_bodies = ""
        for sms in smss:
            #print('pos:{} neg:{} except:{} food:{} service:{}'.format(sms.pos_flag,sms.neg_flag, sms.exception_flag, sms.food_flag, sms.service_flag))
            if (type(sms.submission_time) is str):
                sms_dt = datetime.strptime(
                    sms.submission_time[:-6], "%Y-%m-%d %H:%M:%S"
                )  #removes the +HH:MM offset in datetime
            else:
                sms_dt = sms.submission_time
            sms_str = sms_dt.strftime("%Y-%m-%d %H:%M:%S")
            res.append(dict(time=sms_str, body=sms.body))
            all_string_bodies = all_string_bodies + sms.body + ","
        if (request.form.get('wordcloud')):
            wc = True
            [wordSet, freqs, maxfreq
             ] = feedback_controller.word_freq_counter(all_string_bodies)
            #word cloud output format
            word_freq = []
            n = 0
            for n in range(len(wordSet)):
                word_freq.append(dict(text=wordSet[n], weight=freqs[n]))
        else:
            wc = False
            word_freq = []
            maxfreq = 0  # fix wc error
        table = ItemTable(res)
    else:
        res = []
        table = ItemTable(res)
    if not (res == []):
        return render_template('feedbackM/index.html',
                               logged_in=True,
                               table=table,
                               form=form,
                               word_freq=json.dumps(word_freq),
                               max_freq=maxfreq,
                               role=role,
                               wordcloud=wc)
    else:
        return render_template(
            'feedbackM/index.html',
            logged_in=True,
            form=form,
            role=role,
            wordcloud=False
        )  # allow table to stay until it is cleared manually.