예제 #1
0
def get_probe_overview():
    """ Returns overview information on all probes in the system

    """
    probe_overview = []

    # Get status information on all probes
    probes_status = db_probe_status.find({})
    for probe_status in probes_status:

        # Create the probe return collection
        probe = {
            "id" : probe_status["_id"],
            "desc" : "Mock probe, generates interesting fake data with Python", # TODO ps["desc"],
            "last_contact" : probe_status["last_contact"],
            "first_contact" : probe_status["first_contact"],
            "last_restart" : probe_status["last_restart"],
            "sync_count" : probe_status["sync_count"],
            "sensors" : []
        }
        
        # Get recent sensor data
        end_time = datetime.now()
        start_time = end_time - timedelta(days=7)
        sensors_data = get_sensor_data_for_probe(
            probe["id"], start_time, end_time)

        for sensor_data in sensors_data:

            sensor = {
                "id" : sensor_data["_id"],
                "desc" : "TODO Sensor Description...",
                "units_label" : "°",  # TODO: Need data type (degrees, etc)
                "curr_value" : sensor_data["data"].values()[-1],
                "min_value" : sensor_data["min_value"],
                "max_value" : sensor_data["max_value"]
            }

            data = bucketize_data(168,
                date_util.get_timestamp(start_time),
                date_util.get_timestamp(end_time),
                sensor_data["data"])

            sensor["data"] = data
            sensor["avg_value"] = average_list_values(data)
            probe["sensors"].append(sensor)

        probe_overview.append(probe)

    return probe_overview
예제 #2
0
    except Exception,e :
        # If there are problems reading the request arguments, then
        # the request is bad.  Return a 400 HTTP Status Code - Bad
        # Request
        if verbose:
            print "  %s" % str(e)
            traceback.print_exc() 
        abort(400)

    # Get term counts for the response
    term_counts, granularity = metrics_service.get_term_counts(
            terms, time_start, time_end, verbose)
    
    #Construct the response body
    response_body = {
        "time_start"  : date_util.get_timestamp(time_start),
        "time_end"    : date_util.get_timestamp(time_end),
        "granularity" : granularity,        
        "terms"       : term_counts
    }

    # Create the response object and setup headers
    response = make_response(jsonify(response_body))

    if is_download:
        response.headers["Content-Disposition"] = \
                "attachment; filename=terms_data.json"

    return response