diff --git a/.gitignore b/.gitignore index 4aa0a2c7b7965bef8c476dfbf60f3aa25ebdc23e..91b0291ce1ed5407df42d9c3739d32366b353320 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .idea results -src/__* +src/__*__ *.zip \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d01dc8274b72bab0e40deb641932fa225a7599e8..b24c06ef817e69bad66ee61023034f86a2dc2107 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,9 +1,17 @@ stages: - lint + - test pylint: image: "python:latest" stage: lint script: - pip install pylint + - pylint src/main.py + +tests: + image: "python:latest" + stage: test + script: + - pip install -r requirements.txt - pylint src/main.py \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e85f1ca30b770f895347a7e68cf4aeb468f68a..79ea20634cbdbe29fd06c234d00ce39a3b2ef024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * add CI/CD * with PyLint * comment every method +* added tests ## 0.0.1 (2023-04-11) Publish to review in MuC 23 diff --git a/data/scales.json b/data/scales.json new file mode 100644 index 0000000000000000000000000000000000000000..778a8816e39e0b3e74b5ed5d2ecaa20cb823057d --- /dev/null +++ b/data/scales.json @@ -0,0 +1,182 @@ +{ + "01": { + "german": { + "long": "Inhaltsqualität" + }, + "english": { + "long": "Quality of Content", + "short": "Qua" + } + }, + "02": { + "german": { + "long": "Anpassbarkeit" + }, + "english": { + "long": "Adaptability", + "short": "Ada" + } + }, + "03": { + "german": { + "long": "Durchschaubarkeit" + }, + "english": { + "long": "Dependability", + "short": "Dep" + } + }, + "04": { + "german": { + "long": "Effizienz" + }, + "english": { + "long": "Efficiency", + "short": "Eff" + } + }, + "05": { + "german": { + "long": "Immersion" + }, + "english": { + "long": "Immersion", + "short": "Imm" + } + }, + "06": { + "german": { + "long": "Intuitive Bedienung" + }, + "english": { + "long": "Intuitive use", + "short": "Int" + } + }, + "07": { + "german": { + "long": "Nützlichkeit" + }, + "english": { + "long": "Usefulness", + "short": "Use" + } + }, + "08": { + "german": { + "long": "Originalität" + }, + "english": { + "long": "Novelty", + "short": "Nov" + } + }, + "09": { + "german": { + "long": "visuelle Ästhetik" + }, + "english": { + "long": "Aesthetics", + "short": "Aes" + } + }, + "10": { + "german": { + "long": "Identität" + }, + "english": { + "long": "Identity", + "short": "Id" + } + }, + "11": { + "german": { + "long": "Steuerbarkeit" + }, + "english": { + "long": "Clarity", + "short": "Cla" + } + }, + "12": { + "german": { + "long": "Stimulation" + }, + "english": { + "long": "Stimulation", + "short": "Sti" + } + }, + "13": { + "german": { + "long": "Übersichtlichkeit" + }, + "english": { + "long": "Perspicuity", + "short": "Per" + } + }, + "14": { + "german": { + "long": "Verbundenheit" + }, + "english": { + "long": "Attachment", + "short": "Atm" + } + }, + "15": { + "german": { + "long": "Vertrauen" + }, + "english": { + "long": "Trust", + "short": "Tru" + } + }, + "16": { + "german": { + "long": "Wertigkeit" + }, + "english": { + "long": "Value", + "short": "Val" + } + }, + "17": { + "german": { + "long": "Attraktivität" + }, + "english": { + "long": "Attractiveness", + "short": "Att" + } + }, + "18": { + "german": { + "long": "Haptik" + }, + "english": { + "long": "Haptics", + "short": "Hap" + } + }, + "19": { + "german": { + "long": "Akustik" + }, + "english": { + "long": "Acoustics", + "short": "Aco" + } + }, + "20": { + "german": { + "long": "Inhaltsseriosität" + }, + "english": { + "long": "Trustworthiness of Content", + "short": "ToC" + } + } +} diff --git a/requirements.txt b/requirements.txt index 32e9f56e0da3942878a4f860fbce195e3ec1e593..585537ba3915bacfec43e798117f378fd8fa780d 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/main.py b/src/main.py index d090159ee0eca24693b105b45662f8e474290fd0..2a886e79ec4d8e12500c9bccbd303a10115a5f84 100644 --- a/src/main.py +++ b/src/main.py @@ -1,5 +1,5 @@ """ Main file to compute findings in the raw data """ - +import json import os.path import time @@ -15,7 +15,6 @@ from kPOD import k_pod ROOT_DIR = os.path.dirname(os.path.abspath(__file__)) - class Categories(Enum): """ Enum for all product categories evaluated in this study @@ -280,111 +279,32 @@ def replace_cryptic_names(columns): :param columns: columns with cryptics_names :return: a list with human-readable scales """ + result_columns = [] + with open(os.path.join(ROOT_DIR, '..', 'data', 'scales.json'), 'r', encoding='utf-8') as file: + scales = json.load(file) + for element in columns: + result_columns.append(scales[element.split('_')[1]]['german']['long']) + return result_columns - new_columns = list(columns) - for i in range(len(columns)): - if "_01" in new_columns[i]: - new_columns[i] = 'Inhaltsqualität' # thirteenth scale in handbook - IN in Paper - elif "_02" in new_columns[i]: - new_columns[i] = 'Anpassbarkeit' # eigth scale in handbook - AN in Paper - elif "_03" in new_columns[i]: - new_columns[i] = 'Durchschaubarkeit' # third scale in handbook - DU in Paper - elif "_04" in new_columns[i]: - new_columns[i] = 'Effizienz' # second scale in handbook - EF in Paper - elif "_05" in new_columns[i]: - new_columns[i] = 'Immersion' # second left out scale in handbook - IM in Paper - elif "_06" in new_columns[i]: - new_columns[i] = 'Intuitive Bedienung' # tenth scale in handbook - IB in Paper - elif "_07" in new_columns[i]: - new_columns[i] = 'Nützlichkeit' # nineth scale in handbook - NÜ in Paper - elif "_08" in new_columns[i]: - new_columns[i] = 'Originalität' # sixth scale in handbook - OR in Paper - elif "_09" in new_columns[i]: - # seventh scale in handbook - SC (Schönheit) in Paper - new_columns[i] = 'visuelle Ästhetik' - elif "_10" in new_columns[i]: - new_columns[i] = 'Identität' # first left out scale in handbook - ID in Paper - elif "_11" in new_columns[i]: - new_columns[i] = 'Steuerbarkeit' # fourth scale in handbook - ST in Paper - elif "_12" in new_columns[i]: - new_columns[i] = 'Stimulation' # fifth scale in handbook - SL in Paper - elif "_13" in new_columns[i]: - new_columns[i] = 'Übersichtlichkeit' # seventeenth scale in handbook - ÜB in Paper - elif "_14" in new_columns[i]: - new_columns[i] = 'Verbundenheit' # not in handbook - VB in Paper - elif "_15" in new_columns[i]: - new_columns[i] = 'Vertrauen' # fourteenth scale in handbook - VT in Paper - elif "_16" in new_columns[i]: - new_columns[i] = 'Wertigkeit' # eleventh scale in handbook - WE in Paper - elif "_17" in new_columns[i]: - new_columns[i] = 'Attraktivität' # first scale in handbook - not in Paper - elif "_18" in new_columns[i]: - new_columns[i] = 'Haptik' # fifteenth scale in handbook - not in Paper - elif "_19" in new_columns[i]: - new_columns[i] = 'Akustik' # sixteenth scale in handbook - not in Paper - elif "_20" in new_columns[i]: - new_columns[i] = 'Inhaltsseriosität' # twelth scale in handbook - not in Paper - - return new_columns - - -def translate_scales(scales, short=False): + +def translate_scales(untranslated_scales, short=False): """ translate german scales into english - :param scales: german scales + :param untranslated_scales: german scales :param short: if a shortform of a scale is needed :return: translated scales """ - scales = list(scales) - result = scales - translations = { - 'Inhaltsqualität': "Quality \n of Content", - 'Anpassbarkeit': "Adapt-\nability", - 'Durchschaubarkeit': "Depend- \n ability", - 'Effizienz': "Efficiency", - 'Immersion': "Immersion", - 'Intuitive Bedienung': "Intuitive \n use", - 'Nützlichkeit': "Usefulness", - 'Originalität': "Novelty", - 'visuelle Ästhetik': "Aesthetics", - 'Identität': "Identity", - 'Steuerbarkeit': "Clarity", - 'Stimulation': "Stimulation", - 'Übersichtlichkeit': "Perspicuity", - 'Verbundenheit': "Attachment", - 'Vertrauen': "Trust", - 'Wertigkeit': "Value", - 'Attraktivität': "Attrac-\n tiveness", - 'Haptik': "Haptics", - 'Akustik': "Acoustics", - 'Inhaltsseriosität': "Trustworth-\niness of \nContent" - } - if short: - translations = { - 'Inhaltsqualität': "Qua", - 'Anpassbarkeit': "Ada", - 'Durchschaubarkeit': "Dep", - 'Effizienz': "Eff", - 'Immersion': "Imm", - 'Intuitive Bedienung': "Int", - 'Nützlichkeit': "Use", - 'Originalität': "Nov", - 'visuelle Ästhetik': "Aes", - 'Identität': "Id", - 'Steuerbarkeit': "Cla", - 'Stimulation': "Sti", - 'Übersichtlichkeit': "Per", - 'Verbundenheit': "Atm", - 'Vertrauen': "Tru", - 'Wertigkeit': "Val", - 'Attraktivität': "Att", - 'Haptik': "Hap", - 'Akustik': "Aco", - 'Inhaltsseriosität': "ToC" - } - for i, scala in enumerate(scales): - result[i] = translations[scala] + result = [] + with open(os.path.join(ROOT_DIR, '..', 'data', 'scales.json'), 'r', encoding='utf-8') as file: + scales = json.load(file) + for u_scale in untranslated_scales: + for _, value in scales.items(): + if value["german"]["long"] == u_scale: + if short: + result.append(value["english"]["short"]) + else: + result.append(value["english"]["long"]) return result diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/test/test_main.py b/test/test_main.py new file mode 100644 index 0000000000000000000000000000000000000000..813c890da95f13ce89be325d7570d914a5737626 --- /dev/null +++ b/test/test_main.py @@ -0,0 +1,88 @@ +import unittest + +from src.main import replace_cryptic_names, translate_scales + + +class TestDataAnalyzer(unittest.TestCase): + def test_replace_cryptic_name(self): + columns = [f"EX_{i:02d}" for i in range(1, 21)] + expected_columns = ['Inhaltsqualität', + 'Anpassbarkeit', + 'Durchschaubarkeit', + 'Effizienz', + 'Immersion', + 'Intuitive Bedienung', + 'Nützlichkeit', + 'Originalität', + 'visuelle Ästhetik', + 'Identität', + 'Steuerbarkeit', + 'Stimulation', + 'Übersichtlichkeit', + 'Verbundenheit', + 'Vertrauen', + 'Wertigkeit', + 'Attraktivität', + 'Haptik', + 'Akustik', + 'Inhaltsseriosität'] + + replaced = replace_cryptic_names(columns) + self.assertListEqual(replaced, expected_columns) + + def test_translation_long(self): + columns = [f"EX_{i:02d}" for i in range(1, 21)] + replaced = replace_cryptic_names(columns) + translated_scales = translate_scales(replaced) + expected_translated_scales = ['Quality of Content', + 'Adaptability', + 'Dependability', + 'Efficiency', + 'Immersion', + 'Intuitive use', + 'Usefulness', + 'Novelty', + 'Aesthetics', + 'Identity', + 'Clarity', + 'Stimulation', + 'Perspicuity', + 'Attachment', + 'Trust', + 'Value', + 'Attractiveness', + 'Haptics', + 'Acoustics', + 'Trustworthiness of Content'] + + self.assertListEqual(translated_scales, expected_translated_scales) + + def test_translation_short(self): + columns = [f"EX_{i:02d}" for i in range(1, 21)] + replaced = replace_cryptic_names(columns) + translated_scales = translate_scales(replaced, True) + expected_translated_scales = ['Qua', + 'Ada', + 'Dep', + 'Eff', + 'Imm', + 'Int', + 'Use', + 'Nov', + 'Aes', + 'Id', + 'Cla', + 'Sti', + 'Per', + 'Atm', + 'Tru', + 'Val', + 'Att', + 'Hap', + 'Aco', + 'ToC'] + self.assertListEqual(translated_scales, expected_translated_scales) + + +if __name__ == '__main__': + unittest.main()