From 148e2b68ae1d1bbe8e55323314cdea8994c2f909 Mon Sep 17 00:00:00 2001 From: tooyosi Date: Tue, 5 Nov 2024 16:18:37 +0000 Subject: [PATCH] remove shared class implementation --- .../galaxy_zoo/base_extractor.rb | 8 +++- .../galaxy_zoo/cosmic_dawn.rb | 2 +- .../label_extractors/galaxy_zoo/euclid.rb | 2 +- .../shared/cosmic_dawn_and_euclid.rb | 22 ---------- .../shared/cosmic_dawn_and_euclid_spec.rb | 44 ------------------- 5 files changed, 8 insertions(+), 70 deletions(-) delete mode 100644 app/modules/label_extractors/shared/cosmic_dawn_and_euclid.rb delete mode 100644 spec/modules/label_extractors/shared/cosmic_dawn_and_euclid_spec.rb diff --git a/app/modules/label_extractors/galaxy_zoo/base_extractor.rb b/app/modules/label_extractors/galaxy_zoo/base_extractor.rb index 73f98a2..38af556 100644 --- a/app/modules/label_extractors/galaxy_zoo/base_extractor.rb +++ b/app/modules/label_extractors/galaxy_zoo/base_extractor.rb @@ -36,9 +36,13 @@ def self.data_labels self::TASK_KEY_DATA_LABELS end - # Base version of question_answers_schema method to be customized by subclasses + # provide a flat task question and answers list for the decals mission catalogues def self.question_answers_schema - raise NotImplementedError, "Subclass must define `question_answers_schema`" + label_prefixes.map do |task_key, question_prefix| + data_labels[task_key].values.map do |answer_suffix| + "#{question_prefix}-#{data_release_suffix}_#{answer_suffix}" + end + end.flatten end private diff --git a/app/modules/label_extractors/galaxy_zoo/cosmic_dawn.rb b/app/modules/label_extractors/galaxy_zoo/cosmic_dawn.rb index 9cbb96a..2169a12 100644 --- a/app/modules/label_extractors/galaxy_zoo/cosmic_dawn.rb +++ b/app/modules/label_extractors/galaxy_zoo/cosmic_dawn.rb @@ -2,7 +2,7 @@ module LabelExtractors module GalaxyZoo - class CosmicDawn < LabelExtractors::Shared::CosmicDawnAndEuclid + class CosmicDawn < BaseExtractor # GZ decision tree task schema and lable tables # diff --git a/app/modules/label_extractors/galaxy_zoo/euclid.rb b/app/modules/label_extractors/galaxy_zoo/euclid.rb index 81e0f0d..49cd948 100644 --- a/app/modules/label_extractors/galaxy_zoo/euclid.rb +++ b/app/modules/label_extractors/galaxy_zoo/euclid.rb @@ -2,7 +2,7 @@ module LabelExtractors module GalaxyZoo - class Euclid < LabelExtractors::Shared::CosmicDawnAndEuclid + class Euclid < BaseExtractor attr_reader :task_lookup_key, :task_prefix_label diff --git a/app/modules/label_extractors/shared/cosmic_dawn_and_euclid.rb b/app/modules/label_extractors/shared/cosmic_dawn_and_euclid.rb deleted file mode 100644 index 3f00c65..0000000 --- a/app/modules/label_extractors/shared/cosmic_dawn_and_euclid.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module LabelExtractors - module Shared - class CosmicDawnAndEuclid < LabelExtractors::GalaxyZoo::BaseExtractor - - def self.data_release_suffix - raise NotImplementedError, "Subclass must define `data_release_suffix`" - end - - # provide a flat task question and answers list for the decals mission catalogues - def self.question_answers_schema - label_prefixes.map do |task_key, question_prefix| - data_labels[task_key].values.map do |answer_suffix| - "#{question_prefix}-#{data_release_suffix}_#{answer_suffix}" - end - end.flatten - end - - end - end -end diff --git a/spec/modules/label_extractors/shared/cosmic_dawn_and_euclid_spec.rb b/spec/modules/label_extractors/shared/cosmic_dawn_and_euclid_spec.rb deleted file mode 100644 index 89a5388..0000000 --- a/spec/modules/label_extractors/shared/cosmic_dawn_and_euclid_spec.rb +++ /dev/null @@ -1,44 +0,0 @@ - -# spec/label_extractors/galaxy_zoo/cosmic_dawn_and_euclid_spec.rb -class TestClass < LabelExtractors::Shared::CosmicDawnAndEuclid - TASK_KEY_LABEL_PREFIXES = { task_key_example: "example_prefix" } - TASK_KEY_DATA_LABELS = { task_key_example: { "T0" => "example_label" } } - - def self.data_release_suffix - "v1" - end -end - -RSpec.describe LabelExtractors::Shared::CosmicDawnAndEuclid do - let(:task_lookup_key) { :task_key_example } - - # Define a dynamic subclass of CosmicDawnAndEuclid for testing - let(:test_class) do - Class.new(described_class) do - TASK_KEY_LABEL_PREFIXES = { task_key_example: "example_prefix" } - TASK_KEY_DATA_LABELS = { task_key_example: { "T0" => "example_label" } } - - def self.data_release_suffix - "v1" - end - end - end - - let(:instance) { test_class.new(task_lookup_key) } - - describe 'question_answers_schema' do - it 'constructs the correct question and answers schema' do - result = TestClass.question_answers_schema - expected_result = ["example_prefix-v1_example_label"] - expect(result).to eq(expected_result) - end - end - - describe 'data_release_suffix' do - it 'raises NotImplementedError when not overridden' do - # We directly call the described class here without using the test_class - expect { described_class.data_release_suffix }.to raise_error(NotImplementedError) - end - end -end -