From 1350e6ddd6f7a94bfd2a9a35c81064fee577cf82 Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Thu, 30 Apr 2020 14:45:54 +0200 Subject: [PATCH] Add metadata object on analysis --- app/corpora/events.py | 19 +++++++++++-------- app/static/js/nopaque.Results.js | 20 ++++++++------------ app/static/js/nopaque.callbacks.js | 19 ++++++++++++------- app/templates/corpora/analyse_corpus.html.j2 | 4 ++-- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/app/corpora/events.py b/app/corpora/events.py index f02e1ac3..7683d7b9 100644 --- a/app/corpora/events.py +++ b/app/corpora/events.py @@ -8,6 +8,7 @@ from ..models import Corpus, User import cqi import math from app import logger +from datetime import datetime ''' @@ -47,16 +48,18 @@ def corpus_analysis_get_meta_data(corpus_id): metadata['corpus_properties'] = client_corpus.attrs['properties'] metadata['corpus_size_tokens'] = client_corpus.attrs['size'] - texts = {} text_attr = client_corpus.structural_attributes.get('text') - for text_id in range(0, (text_attr.attrs['size'])): - texts[text_id] = {} - logger.warning('Text ID: {}'.format(text_id)) - struct_attrs = client_corpus.structural_attributes.list(filters={'part_of': text_attr}) + struct_attrs = client_corpus.structural_attributes.list(filters={'part_of': text_attr}) + text_ids = range(0, (text_attr.attrs['size'])) + texts_metadata = {} + for text_id in text_ids: + texts_metadata[text_id] = {} for struct_attr in struct_attrs: - logger.warning(struct_attr) - for struct_id in list(range(0, struct_attr.attrs['size'])): - logger.warning(struct_attr.values_by_ids([struct_id])) + texts_metadata[text_id][struct_attr.attrs['name'][(len(text_attr.attrs['name']) + 1):]] = struct_attr.values_by_ids(list(range(struct_attr.attrs['size'])))[text_id] + metadata['corpus_all_texts'] = texts_metadata + metadata['corpus_analysis_date'] = datetime.utcnow().isoformat() + metadata['corpus_cqi_py_version'] = cqi.version + metadata['corpus_cqpserver_version'] = 'CQPserver v3.4.22' # TODO: make this dynamically payload = metadata response = {'code': 200, 'desc': 'Corpus meta data', 'msg': 'OK', 'payload': payload} diff --git a/app/static/js/nopaque.Results.js b/app/static/js/nopaque.Results.js index 2358ec18..d8a89682 100644 --- a/app/static/js/nopaque.Results.js +++ b/app/static/js/nopaque.Results.js @@ -1,15 +1,15 @@ class Results { - constructor(resultsJSON, resultsList , metaDataJSON) { + constructor(resultsJSON, resultsList , resultsMetaData) { this.resultsJSON = resultsJSON; this.resultsList = resultsList; - this.metaDataJSON = metaDataJSON + this.resultsMetaData = resultsMetaData } clearAll() { this.resultsList.clear(); this.resultsList.update(); this.resultsJSON.init(); - this.metaDataJSON.init(); + this.resultsMetaData.init(); } } @@ -77,14 +77,10 @@ class ResultsJSON { } } -class MetaDataJSON { - // Sets empty object structure. Also usefull to delete old results. - init() { - this["corpus_name"] = undefined; - this["corpus_description"] = undefined; - this["corpus_creation_date"] = undefined; - this["corpus_last_edited_date"] = undefined; - this["corpus_properties"] = undefined; - this["corpus_size_tokens"] = undefined; +class ResultsMetaData { + // Sets empty object structure when no input is given. + // Else it works like a delete. + init(json = {}) { + Object.assign(this, json); } } \ No newline at end of file diff --git a/app/static/js/nopaque.callbacks.js b/app/static/js/nopaque.callbacks.js index 4341472c..40fd3758 100644 --- a/app/static/js/nopaque.callbacks.js +++ b/app/static/js/nopaque.callbacks.js @@ -1,11 +1,16 @@ function recvMetaData(payload) { - results.metaDataJSON.corpus_name = payload.corpus_name; - results.metaDataJSON.corpus_description = payload.corpus_description; - results.metaDataJSON.corpus_creation_date = payload.corpus_creation_date; - results.metaDataJSON.corpus_last_edited_date = payload.corpus_last_edited_date; - results.metaDataJSON.corpus_properties = payload.corpus_properties; - results.metaDataJSON.corpus_size_tokens = payload.corpus_size_tokens; - console.log(results.metaDataJSON); + results.resultsMetaData.init(payload) + // results.metaDataJSON.corpus_name = payload.corpus_name; + // results.metaDataJSON.corpus_description = payload.corpus_description; + // results.metaDataJSON.corpus_creation_date = payload.corpus_creation_date; + // results.metaDataJSON.corpus_last_edited_date = payload.corpus_last_edited_date; + // results.metaDataJSON.corpus_properties = payload.corpus_properties; + // results.metaDataJSON.corpus_size_tokens = payload.corpus_size_tokens; + // results.metaDataJSON.corpus_all_texts = payload.corpus_all_texts; + // results.metaDataJSON.corpus_analysis_date = payload.corpus_analysis_date; + // results.metaDataJSON.corpus_cqi_py_version = payload.corpus_cqi_py_version; + // results.metaDataJSON.corpus_cqpserver_version = payload.corpus_cqpserver_version; + console.log(results.resultsMetaData); } function querySetup(payload) { diff --git a/app/templates/corpora/analyse_corpus.html.j2 b/app/templates/corpora/analyse_corpus.html.j2 index 1441126b..edebe1d3 100644 --- a/app/templates/corpora/analyse_corpus.html.j2 +++ b/app/templates/corpora/analyse_corpus.html.j2 @@ -365,8 +365,8 @@ // Init corpus analysis components resultsJSON = new ResultsJSON(); resultsList = new ResultsList("result-list", resultsListOptions); - metaDataJSON = new MetaDataJSON(); - results = new Results(resultsJSON, resultsList, metaDataJSON); + resultsMetaData = new ResultsMetaData(); + results = new Results(resultsJSON, resultsList, resultsMetaData); initDisplay = new CorpusAnalysisDisplay(initDisplayElement); queryDisplay = new CorpusAnalysisDisplay(queryDisplayElement); client = new CorpusAnalysisClient({{ corpus_id }}, nopaque.socket);