Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html output dummy instr #644

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,43 @@
return p_value, query_out


class ReturnProgressHtmlDataServerQuery(DataServerQuery):
def __init__(self, config=None, instrument=None):
super().__init__()

Check warning on line 243 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L243

Added line #L243 was not covered by tests

def get_progress_run(self, **kwargs):

query_out = QueryOutput()

Check warning on line 247 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L247

Added line #L247 was not covered by tests

html_content = ReturnProgressHtmlProductQuery.get_progress_html_output()

Check warning on line 249 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L249

Added line #L249 was not covered by tests

query_out.set_status(

Check warning on line 251 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L251

Added line #L251 was not covered by tests
0,
message=f"current p value is {html_content}",
debug_message="no debug message really",
job_status="submitted",
comment="mock comment",
warning="mock warning")

return html_content, query_out

Check warning on line 259 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L259

Added line #L259 was not covered by tests

def run_query(self, *args, **kwargs):
logger.warn('fake run_query in %s with %s, %s', self, args, kwargs)
query_out = QueryOutput()

Check warning on line 263 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L262-L263

Added lines #L262 - L263 were not covered by tests

html_content = ReturnProgressProductQuery.get_progress_html_output()

Check warning on line 265 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L265

Added line #L265 was not covered by tests

query_out.set_status(

Check warning on line 267 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L267

Added line #L267 was not covered by tests
0,
message=f"current p value is {html_content}",
debug_message="no debug message really",
job_status="done",
comment="mock comment",
warning="mock warning")

return html_content, query_out

Check warning on line 275 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L275

Added line #L275 was not covered by tests


class ReturnProgressProductQuery(ProductQuery):

p_value_fn = "ReturnProgressProductQuery-current_p_value.out"
Expand Down Expand Up @@ -287,6 +324,49 @@
p_value = res
return [p_value]

class ReturnProgressHtmlProductQuery(ReturnProgressProductQuery):

html_output_fn = "progress_html_output.html"
def __init__(self, name):
super().__init__(name)

@classmethod
def set_progress_html_output(cls, html_output_content):
with open(cls.html_output_fn, "w") as progress_html_f:
progress_html_f.write(str(html_output_content))

Check warning on line 336 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L335-L336

Added lines #L335 - L336 were not covered by tests

@classmethod
def get_progress_html_output(cls):
if os.path.exists(cls.html_output_fn):
with open(cls.html_output_fn) as html_output_f:
html_output = html_output_f.read()
return html_output

Check warning on line 343 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L340-L343

Added lines #L340 - L343 were not covered by tests
else:
return ""

Check warning on line 345 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L345

Added line #L345 was not covered by tests

def get_dummy_progress_run(self, instrument, config=None,**kwargs):
html_output = self.get_progress_html_output()
prod_list = QueryProductList(prod_list=[html_output])
return prod_list

Check warning on line 350 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L348-L350

Added lines #L348 - L350 were not covered by tests

def get_dummy_products(self, instrument, config=None, **kwargs):
html_output = self.get_progress_html_output()
prod_list = QueryProductList(prod_list=[html_output])
return prod_list

Check warning on line 355 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L353-L355

Added lines #L353 - L355 were not covered by tests

def process_product_method(self, instrument, prod_list, api=False, **kw):
query_out = QueryOutput()
query_out.prod_dictionary['progress_product_html_output'] = prod_list.prod_list[0]
return query_out

Check warning on line 360 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L358-L360

Added lines #L358 - L360 were not covered by tests

def get_data_server_query(self,instrument,config=None,**kwargs):
if instrument.data_server_query_class:
q = ReturnProgressHtmlDataServerQuery(instrument=instrument, config=config)

Check warning on line 364 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L363-L364

Added lines #L363 - L364 were not covered by tests
else:
q = DataServerQuery()
return q

Check warning on line 367 in cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py

View check run for this annotation

Codecov / codecov/patch

cdci_data_analysis/plugins/dummy_plugin/data_server_dispatcher.py#L366-L367

Added lines #L366 - L367 were not covered by tests


class EmptyProductQuery(ProductQuery):

def __init__(self, name='unset-name', config=None, instrument=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cdci_data_analysis.analysis.instrument import Instrument
from cdci_data_analysis.analysis.queries import SourceQuery, InstrumentQuery, Float

from .data_server_dispatcher import ReturnProgressDataServerQuery, ReturnProgressProductQuery
from .data_server_dispatcher import ReturnProgressDataServerQuery, ReturnProgressProductQuery, ReturnProgressHtmlProductQuery


def my_instr_factory():
Expand All @@ -20,11 +20,14 @@ def my_instr_factory():
return_progress_query = ReturnProgressProductQuery('empty_parameters_dummy_query_return_progress',
parameters_list=[p])

query_dictionary = {'dummy': 'empty_parameters_dummy_query_return_progress'}
return_progress_html_query = ReturnProgressHtmlProductQuery('empty_parameters_dummy_query_return_progress_html')

query_dictionary = {'dummy': 'empty_parameters_dummy_query_return_progress',
'dummy_html': 'empty_parameters_dummy_query_return_progress_html'}

return Instrument('empty-async-return-progress',
src_query=src_query,
instrumet_query=instr_query,
product_queries_list=[return_progress_query],
product_queries_list=[return_progress_query, return_progress_html_query],
query_dictionary=query_dictionary,
data_server_query_class=ReturnProgressDataServerQuery)
Loading