Beispiel #1
0
def get_graph_context():
    date_start_end = lambda d, s=True: \
        datetime.datetime(int(d.year), int(d.month), int(d.day),
                          0 if s else 23, 0 if s else 59, 0 if s else 59)

    try:
        start = HotlineEvent.objects.order_by('received_on')[0].received_on
    except IndexError:
        start = datetime.datetime.today()

    requests = []
    responses = []

    for date in datetime_range(start):
        ts = int(to_timestamp(date)) * 1000
        qcount = HotlineEvent.objects.filter(
            received_on__gte=date_start_end(date),
            received_on__lt=date_start_end(date, False)).count()
        scount = HotlineResponse.objects.filter(
            response_date__gte=date_start_end(date),
            response_date__lt=date_start_end(date, False)).count()
        requests.append((ts, qcount))
        responses.append((ts, scount))
    data_event = {'requests': requests, 'responses': responses}

    return data_event
Beispiel #2
0
def get_graph_context():
    date_start_end = lambda d, s=True: datetime.datetime(
        int(d.year), int(d.month), int(d.day), 0 if s else 23, 0 if s else 59, 0 if s else 59
    )

    try:
        start = HotlineEvent.objects.order_by("received_on")[0].received_on
    except IndexError:
        start = datetime.datetime.today()

    requests = []
    responses = []

    for date in datetime_range(start):
        ts = int(to_timestamp(date)) * 1000
        qcount = HotlineEvent.objects.filter(
            received_on__gte=date_start_end(date), received_on__lt=date_start_end(date, False)
        ).count()
        scount = HotlineResponse.objects.filter(
            response_date__gte=date_start_end(date), response_date__lt=date_start_end(date, False)
        ).count()
        requests.append((ts, qcount))
        responses.append((ts, scount))
    data_event = {"requests": requests, "responses": responses}

    return data_event
Beispiel #3
0
def make_ushahidi_request(event):

    params = {'from': event.identity,
              'message': event.sms_message,
              'message_id': event.id,
              'sent_to': event.hotline_number,
              'secret': settings.USHAHIDI_SECRET,
              'sent_timestamp': int(to_timestamp(event.received_on) * 1000)}

    req = requests.get(settings.USHAHIDI_URL, params=params)

    try:
        req.raise_for_status()
    except requests.exceptions.HTTPError:
        return False

    response = json.loads(req.text)
    if response.get('payload', {}).get('success', False) in (True, "true"):
        event.processed = True
        event.save()
        return True
    return False
Beispiel #4
0
def get_graph_context():
    date_start_end = lambda d, s=True: \
        datetime.datetime(int(d.year), int(d.month), int(d.day),
                          0 if s else 23, 0 if s else 59, 0 if s else 59)

    try:
        start = TextSMS.incoming.order_by('event_on')[0].event_on
    except IndexError:
        start = datetime.datetime.today()

    nb_incomingsms = []
    nb_outgoingsms = []
    for date in datetime_range(start):
        ts = int(to_timestamp(date)) * 1000
        sms_in_count = TextSMS.incoming.filter(event_on__gte=date_start_end(date),
                                           event_on__lt=date_start_end(date, False)).count()
        nb_incomingsms.append((ts, sms_in_count))
        sms_out_count = TextSMS.outgoing.filter(event_on__gte=date_start_end(date),
                                           event_on__lt=date_start_end(date, False)).count()
        nb_outgoingsms.append((ts, sms_out_count))
    data_event = {'nb_incomingsms': nb_incomingsms, 'nb_outgoingsms': nb_outgoingsms}
    return data_event
Beispiel #5
0
def make_ushahidi_request(event):

    params = {
        "from": event.identity,
        "message": event.sms_message,
        "message_id": event.id,
        "sent_to": event.hotline_number,
        "secret": settings.USHAHIDI_SECRET,
        "sent_timestamp": int(to_timestamp(event.received_on) * 1000),
    }

    req = requests.get(settings.USHAHIDI_URL, params=params)

    try:
        req.raise_for_status()
    except requests.exceptions.HTTPError:
        return False

    response = json.loads(req.text)
    if response.get("payload", {}).get("success", False) in (True, "true"):
        event.processed = True
        event.save()
        return True
    return False