Esempio n. 1
0
 def test_query_processed_valid(self):
     initial_timestamp = "02-09-2010 00:00:00"
     last_timestamp = "02-09-2010 00:01:00"
     date_format = '%d-%m-%Y %H:%M:%S'
     self.assertAlmostEqual(
         get_data_helper.queryDBProcessed("qH001", initial_timestamp,
                                          last_timestamp, date_format), [])
     self.assertAlmostEqual(
         get_data_helper.queryDBProcessed("qH100", initial_timestamp,
                                          last_timestamp, date_format),
         None)
Esempio n. 2
0
 def test_query_processed_valid(self):
     naive_time = datetime.time(5, 0, 21)
     date = datetime.date(2020, 12, 20)
     naive_datetime = datetime.datetime.combine(date, naive_time)
     timezone = pytz.timezone('UTC')
     initial_timestamp = timezone.localize(naive_datetime)
     date = datetime.date(2020, 12, 21)
     naive_datetime = datetime.datetime.combine(date, naive_time)
     timezone = pytz.timezone('UTC')
     last_timestamp = timezone.localize(naive_datetime)
     self.assertAlmostEqual(
         get_data_helper.queryDBProcessed("qH057", initial_timestamp,
                                          last_timestamp), [])
     self.assertAlmostEqual(
         get_data_helper.queryDBProcessed("qH100", initial_timestamp,
                                          last_timestamp), None)
def getProcessedDataFromAndeanDrone():
    """ Lists all measurements of processed measurement of the target drone within the initial and final date """
    qhawax_name = request.args.get('qhawax_name')
    initial_timestamp = datetime.datetime.strptime(
        request.args.get('initial_timestamp'), '%d-%m-%Y %H:%M:%S')
    final_timestamp = datetime.datetime.strptime(
        request.args.get('final_timestamp'), '%d-%m-%Y %H:%M:%S')
    try:
        processed_measurements = get_data_helper.queryDBProcessed(
            qhawax_name, initial_timestamp, final_timestamp)
        if processed_measurements is not None:
            return make_response(jsonify(processed_measurements), 200)
        return make_response(jsonify('Measurements not found'), 200)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
def getProcessedData():
    """ Lists all measurements of processed measurement of the target qHAWAX within the initial and final date """
    qhawax_name = request.args.get('name')
    try:
        interval_minutes = int(request.args.get('interval_minutes')) \
            if request.args.get('interval_minutes') is not None else 60
        final_timestamp = datetime.datetime.now(dateutil.tz.tzutc())
        initial_timestamp = final_timestamp - datetime.timedelta(
            minutes=interval_minutes)
        processed_measurements = get_data_helper.queryDBProcessed(
            qhawax_name, initial_timestamp, final_timestamp)
        if processed_measurements is not None:
            return make_response(jsonify(processed_measurements), 200)
        return make_response(jsonify('Measurements not found'), 200)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
def getProcessedMeasurementsTimePeriod():
    """
    To list all measurement of processed measurement table in a define period of time

    """
    try:
        qhawax_name = request.args.get('name')
        initial_timestamp = request.args.get('initial_timestamp')
        final_timestamp = request.args.get('final_timestamp')
        date_format = '%d-%m-%Y %H:%M:%S'
        processed_measurements = get_data_helper.queryDBProcessed(qhawax_name, \
                                                 initial_timestamp, final_timestamp,date_format)
        if processed_measurements is not None:
            return make_response(jsonify(processed_measurements), 200)
        return make_response(jsonify('Measurements not found'), 200)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
def getProcessedData():
    """
    To list all measurement of processed measurement table record the last N minutes
    """
    try:
        qhawax_name = request.args.get('name')
        interval_minutes = int(request.args.get('interval_minutes')) \
            if request.args.get('interval_minutes') is not None else 60

        final_timestamp = datetime.datetime.now(dateutil.tz.tzutc())
        initial_timestamp = final_timestamp - datetime.timedelta(
            minutes=interval_minutes)
        date_format = '%Y-%m-%d %H:%M:%S.%f%z'
        processed_measurements = get_data_helper.queryDBProcessed(qhawax_name, str(initial_timestamp), \
                                                                  str(final_timestamp),date_format)
        if processed_measurements is not None:
            return make_response(jsonify(processed_measurements), 200)
        return make_response(jsonify('Measurements not found'), 200)
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return make_response(json_message, 400)
def _getProcessedDataCommon(is_valid):
    """ Returns a json that lists all measurements of processed measurement 
    of the target drone within the initial and final date """

    qhawax_name = request.args.get('qhawax_name')
    initial_timestamp = datetime.datetime.strptime(
        request.args.get('initial_timestamp'), '%d-%m-%Y %H:%M:%S')
    final_timestamp = datetime.datetime.strptime(
        request.args.get('final_timestamp'), '%d-%m-%Y %H:%M:%S')
    try:
        processed_measurements = None
        if is_valid:
            processed_measurements = get_data_helper.queryDBValidProcessed(
                qhawax_name, initial_timestamp, final_timestamp)
        else:
            processed_measurements = get_data_helper.queryDBProcessed(
                qhawax_name, initial_timestamp, final_timestamp)
        if processed_measurements is not None:
            return jsonify(processed_measurements), 200
        return jsonify('Measurements not found'), 200
    except TypeError as e:
        json_message = jsonify({'error': '\'%s\'' % (e)})
        return json_message, 400