<jupyter_start><jupyter_text>Subscriber with JSON export<jupyter_code>import logging
import copy
logging.basicConfig(level="INFO")
from qcodes import Publisher
import numpy as np
import json
from qcodes.dataset.data_set import new_data_set, ParamSpec
from qcodes.dataset.json_exporter import json_template_heatmap, json_template_linear
from qcodes.dataset.json_exporter import export_data_as_json_heatmap, export_data_as_json_linear
from qcodes.dataset.sqlite_base import new_experiment, connect, length
dataSet = new_data_set("test", specs=[ParamSpec("x", "numeric"), ParamSpec("y", "numeric")])
mystate = {}
mystate['json'] = copy.deepcopy(json_template_linear)
mystate['json']['x']['name'] = 'xname'
mystate['json']['x']['unit'] = 'xunit'
mystate['json']['x']['full_name'] = 'xfullname'
mystate['json']['y']['name'] = 'yname'
mystate['json']['y']['unit'] = 'yunit'
mystate['json']['y']['full_name'] = 'yfullname'
sub_id = dataSet.subscribe(export_data_as_json_linear, min_wait=0, min_count=20,
                           state=mystate, callback_kwargs={'location': 'foo'})
s = dataSet.subscribers[sub_id]
mystate
for x in range(100):
    y = x
    dataSet.add_result({"x":x, "y":y})
dataSet.mark_complete()
mystate
mystate = {}
xlen = 5
ylen = 10
mystate['json'] = json_template_heatmap.copy()
mystate['data'] = {}
mystate['data']['xlen'] = xlen
mystate['data']['ylen'] = ylen
mystate['data']['x'] = np.zeros((xlen*ylen), dtype=np.object)
mystate['data']['x'][:] = None
mystate['data']['y'] = np.zeros((xlen*ylen), dtype=np.object)
mystate['data']['y'][:] = None
mystate['data']['z'] = np.zeros((xlen*ylen), dtype=np.object)
mystate['data']['z'][:] = None
mystate['data']['location'] = 0
dataSet_hm = new_data_set("test", specs=[ParamSpec("x", "numeric"),
                                         ParamSpec("y", "numeric"),
                                         ParamSpec("z", "numeric")])
sub_id = dataSet_hm.subscribe(export_data_as_json_heatmap, min_wait=0, min_count=20,
                              state=mystate, callback_kwargs={'location': './foo'})
for x in range(xlen):
    for y in range(ylen):
        z = x+y
        dataSet_hm.add_result({"x":x, "y":y, 'z':z})
dataSet_hm.mark_complete()
mystate['json']<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1850044365572316, 'fraction_numerical': 0.005767524401064774, 'mean_word_length': 5.195054945054945, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '106758', 'license': 'MIT', 'n_tokens_mistral': 816, 'n_tokens_neox': 782, 'n_words': 139, 'path': 'docs/examples/DataSet/subscriber json exporter.ipynb', 'repo_name': 'qSaevar/Qcodes', 'size': '2254'}