def test_list_splitting(self):
        """Test list splitting"""

        given_list = [("Contact1", 2, 3, 0)]
        result = sentiment_analysis.break_list(given_list)

        self.assertEqual(result[0], ["Contact1"])
        self.assertEqual(result[1], [2])
        self.assertEqual(result[2], [3])
        self.assertEqual(result[3], [0])
    def test_list_splitting(self):
        """Test list splitting"""

        given_list = [('Contact1', 2, 3, 0)]
        result = sentiment_analysis.break_list(given_list)

        self.assertEqual(result[0], ['Contact1'])
        self.assertEqual(result[1], [2])
        self.assertEqual(result[2], [3])
        self.assertEqual(result[3], [0])
Beispiel #3
0
def contact_messages_data(user_id):
    """Return contact's messages data."""

    if 'user_id' not in session:
        return redirect("/")
    elif session['user_id'] != user_id:
        return redirect("/users/%s" % session['user_id'])

    contact_msgs = sentiment_analysis.get_contacts_msgs(user_id)
    sentiment_list = sentiment_analysis.get_contacts(contact_msgs)
    arranged_list = sentiment_analysis.break_list(sentiment_list)
    print arranged_list

    data_dict = {
        "labels": arranged_list[0],
        "datasets": [
            {
                "label": "Positive messages",
                "fillColor": "#F7464A",
                "strokeColor": "rgba(220,220,220,0.8)",
                "highlightFill": "rgba(151,187,205,0.75)",
                "highlightStroke": "rgba(220,220,220,1)",
                "data": arranged_list[1]
            },
            {
                "label": "Negative messages",
                "fillColor": "#46BFBD",
                "strokeColor": "rgba(151,187,205,0.8)",
                "highlightFill": "rgba(151,187,205,0.75)",
                "highlightStroke": "#46BFBD",
                "data": arranged_list[2]
            },
            {
                "label": "Neutral messages",
                "fillColor": "#FDB45C",
                "strokeColor": "rgba(151,187,205,0.8)",
                "highlightFill": "rgba(151,187,205,0.75)",
                "highlightStroke": "#C0C0C0",
                "data": arranged_list[3]
            }
        ]
    };
    return jsonify(data_dict)