def run_test():
    """"
    psql -h localhost -U postgres -d ureport -c "select r1.message_id, m1.date, r1.id, r1.date, c1.identity
    from rapidsms_httprouter_message AS m1, poll_response AS r1, rapidsms_connection AS c1
    where m1.id=r1.message_id and m1.connection_id = c1.id and r1. poll_id=$POLL_ID
    and r1.id>$FIRST_RESPONSE and r1.id<$LAST_RESPONSE and
    m1.connection_id not in
    (select  m.connection_id from rapidsms_httprouter_message AS m, poll_response AS r
    where m.id=r.message_id and r. poll_id=$POLL_ID and r.id>$FIRST_RESPONSE and r.id<$LAST_RESPONSE
    group by m.connection_id having count(m.connection_id) >1);" > data_for_responses_to_a_national_poll.txt
    """""
    ini = 3
    limit = 33
    list_throttle_msg_db = []
    list_throttle_response_db = []
    list_throttle_end = []
    list_response_end = []

    with open('data_for_responses_to_a_national_poll.txt') as response_data:
        for index, line in enumerate(response_data):
            if index >= ini :
                times = getting_times_for_line(line)
                list_throttle_msg_db.append(get_diff(times['throttle_start'],times['message_in_db']))
                list_throttle_response_db.append(get_diff(times['throttle_start'],times['response_in_db']))
                if times['response_finish_handled'] is not None:
                    list_throttle_end.append(get_diff(times['throttle_start'],times['response_finish_handled']))
                    list_response_end.append(get_diff(times['response_in_db'],times['response_finish_handled']))
            #if index == limit:
            #    break


    statistic_for("Throttle send to router receive until msg is store in db:", list_throttle_msg_db)
    statistic_for("Throttle send to router receive until response is store in db:", list_throttle_response_db)
    statistic_for("Throttle send to router receive until response get categorized:", list_throttle_end)
    statistic_for("Since Response is created until its Categorization:", list_response_end)
def run_test():
    """"
    psql -h localhost -U postgres -d ureport -c
    "select m.id, m.date, m.connection_id, c.identity
    from rapidsms_httprouter_message AS m, rapidsms_connection AS c
    where m.connection_id=c.id and m.connection_id in ($CONNECTION_ID for unsolicited messages)" > data_for_unsolicited_msgs.txt;
    """""
    ini = 3
    time_diff_msg_receive_to_db = []

    with open('data_for_unsolicited_msgs.txt') as response_data:
        for index, line in enumerate(response_data):
            if index >= ini :
                times = getting_times_for(line)
                if(not_empty(times['message_in_db']) and not_empty(times['sms_received'])):
                    time_diff_msg_receive_to_db.append(get_diff(times['sms_received'],times['message_in_db']))

    statistic_for("Time that individual messages from yo to db", time_diff_msg_receive_to_db)
def run_test():
    """
    We would need:
    1.- Filter individual messages from db -> get id, connection_id and date
    psql -U postgres -h localhost -d ureport -c "select id, connection_id, date
    from rapidsms_httprouter_message where direction='O' and
    id in ($MESSAGE_IDs THAT ARE NOT ASSOCIATED TO A POLL);" > individual_messages_dates.txt
    2.- Get send_message logs from the time that a big poll was sent out. E.g. messenger.log
    """
    ini = 3
    time_diff_msg_db_to_send_out = []

    with open("individual_messages_dates.txt") as response_data:
        for index, line in enumerate(response_data):
            if index >= ini:
                times = getting_times_for(line)
                time_diff_msg_db_to_send_out.append(get_diff(times["message_in_db"], times["sms_sent_out_time"]))

    statistic_for("Time that individual messages take to be sent out", time_diff_msg_db_to_send_out)