QutBioacoustics/baw-server

View on GitHub

Showing 257 of 257 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  module Jobs
    module Media
      # Cuts audio files and generates spectrograms.
      class SpectrogramJob < MediaJob
        queue_as Settings.actions.media.queue
lib/gems/baw-workers/lib/baw_workers/jobs/media/audio_job.rb on lines 4..59

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 103.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

  module Jobs
    module Media
      # Cuts audio files and generates spectrograms.
      class AudioJob < MediaJob
        queue_as Settings.actions.media.queue
Severity: Major
Found in lib/gems/baw-workers/lib/baw_workers/jobs/media/audio_job.rb and 1 other location - About 2 hrs to fix
lib/gems/baw-workers/lib/baw_workers/jobs/media/spectrogram_job.rb on lines 4..60

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 103.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Class AudioBase has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

  class AudioBase
    attr_reader :audio_defaults, :logger, :temp_dir, :timeout_sec,
                :audio_ffmpeg, :audio_mp3splt, :audio_sox,
                :audio_wavpack, :audio_shntool, :audio_waveform,
                :audio_wac2wav
Severity: Minor
Found in lib/gems/baw-audio-tools/lib/baw_audio_tools/audio_base.rb - About 2 hrs to fix

    Method check_request_parameters has 69 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def check_request_parameters(audio_recording, request_params)
          original_duration = audio_recording.duration_seconds
    
          # offsets
          start_offset = nil
    Severity: Major
    Found in app/modules/api/media_metadata.rb - About 2 hrs to fix

      Method show_results has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def show_results(is_head_request, analysis_job_item, results_path, api_opts)
          # assertion: audio_recordings must be in the specified job - authorization should filter out those that aren't
      
          # extract parameters for analysis response
          audio_recording = analysis_job_item.audio_recording
      Severity: Minor
      Found in app/controllers/analysis_jobs_results_controller.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Method create has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          #do_new_resource - custom new audio_recording
          #do_set_attributes(audio_recording_params) - custom set attributes
          @audio_recording = AudioRecording.build_by_file_hash(audio_recording_params)
          get_project_site
      Severity: Minor
      Found in app/controllers/audio_recordings_controller.rb - About 2 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      File audio_event.rb has 280 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      class AudioEvent < ApplicationRecord
        # relations
        belongs_to :audio_recording, inverse_of: :audio_events
        belongs_to :audio_event_import, inverse_of: :audio_events, optional: true
        has_many :taggings, inverse_of: :audio_event, strict_loading: false
      Severity: Minor
      Found in app/models/audio_event.rb - About 2 hrs to fix

        Method download has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def download
            params_cleaned = CleanParams.perform(audio_event_download_params)
        
            is_authorized = false
        
        
        Severity: Major
        Found in app/controllers/audio_events_controller.rb - About 2 hrs to fix

          Method filter_settings has 67 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.filter_settings(is_system = false)
              fields = [
                :id, :analysis_job_id, :audio_recording_id,
                :created_at, :queued_at, :work_started_at, :completed_at,
                :queue_id,
          Severity: Major
          Found in app/models/analysis_jobs_item.rb - About 2 hrs to fix

            Method filter_settings has 65 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.filter_settings
                {
                  valid_fields: [:id, :audio_recording_id,
                                 :start_time_seconds, :end_time_seconds,
                                 :low_frequency_hertz, :high_frequency_hertz,
            Severity: Major
            Found in app/models/audio_event.rb - About 2 hrs to fix

              Method annotation_download has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
              Open

                def annotation_download
                  selected_params = annotation_download_params
              
                  selected_project_id = selected_params[:selected_project_id]
                  selected_site_id = selected_params[:selected_site_id]
              Severity: Minor
              Found in app/controllers/public_controller.rb - About 2 hrs to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              File validate.rb has 272 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              require 'active_support/concern'
              
              # Provides common validations for composing queries.
              module Filter
                module Validate
              Severity: Minor
              Found in app/modules/filter/validate.rb - About 2 hrs to fix

                File schema.rb has 270 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                module Api
                  # The OpenAPI schema for the API.
                  module Schema
                    extend Helpers
                
                
                Severity: Minor
                Found in app/modules/api/schema.rb - About 2 hrs to fix

                  File media_metadata.rb has 268 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  module Api
                    class MediaMetadata
                      # accepts '111', '11.123', not '.11'
                      OFFSET_REGEXP = /^-?(\d+\.)?\d+$/
                  
                  
                  Severity: Minor
                  Found in app/modules/api/media_metadata.rb - About 2 hrs to fix

                    Method check_uploader has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def check_uploader
                        #do_authorize_class - not used, this action does a custom auth
                        get_project_site
                    
                        # current user should be the harvester
                    Severity: Minor
                    Found in app/controllers/audio_recordings_controller.rb - About 2 hrs to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Method filter_settings has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def self.filter_settings
                        {
                          valid_fields: [:id, :name, :description, :creator_id,
                                         :created_at,
                                         :updater_id,
                    Severity: Minor
                    Found in app/models/project.rb - About 2 hrs to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Class Config has 22 methods (exceeds 20 allowed). Consider refactoring.
                    Open

                      class Config
                        class << self
                          @is_resque_worker = false
                          # Is this a resque_worker?
                          # @return [Boolean]
                    Severity: Minor
                    Found in lib/gems/baw-workers/lib/baw_workers/config.rb - About 2 hrs to fix

                      Method registered has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                            def self.registered(app)
                      
                      
                              app.get '/statuses' do
                                @start = params[:start].to_i
                      Severity: Major
                      Found in lib/gems/baw-workers/lib/resque/status_server.rb - About 2 hrs to fix

                        Method filter_settings has 57 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def self.filter_settings(priority_algorithm = nil)
                            result = {
                              valid_fields: [
                                :id, :dataset_id, :audio_recording_id, :start_time_seconds,
                                :end_time_seconds, :order, :creator_id, :created_at, :priority
                        Severity: Major
                        Found in app/models/dataset_item.rb - About 2 hrs to fix

                          File audio_ffmpeg.rb has 261 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          module BawAudioTools
                            # Used to manipulate the ffmpeg command line tool
                            class AudioFfmpeg
                              ERROR_FRAME_SIZE_1 = 'Could not find codec parameters for stream [0-9]+ \\(Audio\\: [a-zA-Z0-9]+\\, [0-9]+ channels\\, [a-zA-Z0-9]+\\)\\: unspecified frame size'
                              ERROR_FRAME_SIZE_2 = 'Failed to read frame size: Could not seek to [0-9]+\\.'
                          Severity: Minor
                          Found in lib/gems/baw-audio-tools/lib/baw_audio_tools/audio_ffmpeg.rb - About 2 hrs to fix
                            Severity
                            Category
                            Status
                            Source
                            Language