Skip to content

Fix "similar-code" issue in project/main/data/processed_measurement.py #103

Description

@SabCampos

The processed_measurement.py file contains the endpoints to which our IoT devices (qHAWAX) make their requests. The frequency varies depending on the type of the device. Static devices send between every 25 to 30 seconds, mobile devices send between every 4 to 6 seconds.

CodeClimate has found the following issue:
Similar blocks of code found in 2 locations. Consider refactoring.

  @app.route('/api/measurements_by_pollutant_during_flight/', methods=['GET'])
  def getProcessedByPollutantDuringFlight():
      """ Lists all measurements of processed measurement of the target qHAWAX within the initial and final date """
      qhawax_name = str(request.args.get('name'))
      pollutant = str(request.args.get('pollutant'))
      try:
          start_flight = get_data_helper.qHAWAXIsInFlight(qhawax_name)
          if(start_flight is not None):
              final_timestamp = datetime.datetime.now(dateutil.tz.tzutc())
              processed_measurements = get_data_helper.queryDBProcessedByPollutant(qhawax_name, start_flight, final_timestamp,pollutant)
              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)
  
  @app.route('/api/measurements_by_pollutant_during_trip/', methods=['GET'])
  def getProcessedByPollutantDuringTrip():
      """ Lists all measurements of processed measurement of the target qHAWAX within the initial and final date """
      qhawax_name = str(request.args.get('name'))
      pollutant = str(request.args.get('pollutant'))
      try:
          start_trip = get_data_helper.qHAWAXIsInTrip(qhawax_name)
          if(start_trip is not None):
              final_timestamp = datetime.datetime.now(dateutil.tz.tzutc())
              # verify which sensors
              processed_measurements = get_data_helper.queryDBValidProcessedByPollutantMobile(qhawax_name, start_trip, final_timestamp,pollutant)
              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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions