Ejemplo n.º 1
0
def get_ds_info(conn: Connection, run_id: int,
                get_structure: bool = True) -> Dict[str, str]:
    """
    Get some info on a run in dict form from a db connection and runId.

    if get_structure is True: return the datastructure in that dataset
    as well (key is `structure' then).
    """
    ds = DataSet(conn=conn, run_id=run_id)

    ret = {}
    ret['experiment'] = ds.exp_name
    ret['sample'] = ds.sample_name

    _complete_ts = ds.completed_timestamp()
    if _complete_ts is not None:
        ret['completed date'] = _complete_ts[:10]
        ret['completed time'] = _complete_ts[11:]
    else:
        ret['completed date'] = ''
        ret['completed time'] = ''

    _start_ts = ds.run_timestamp()
    ret['started date'] = _start_ts[:10]
    ret['started time'] = _start_ts[11:]

    if get_structure:
        ret['structure'] = get_ds_structure(ds)

    ret['records'] = ds.number_of_results

    return ret
Ejemplo n.º 2
0
def _add_metadata_to_xarray(
        dataset: DataSet, xrdataset: Union[xr.Dataset, xr.DataArray]) -> None:
    xrdataset.attrs.update({
        "ds_name":
        dataset.name,
        "sample_name":
        dataset.sample_name,
        "exp_name":
        dataset.exp_name,
        "snapshot":
        dataset.snapshot_raw or "null",
        "guid":
        dataset.guid,
        "run_timestamp":
        dataset.run_timestamp() or "",
        "completed_timestamp":
        dataset.completed_timestamp() or "",
        "captured_run_id":
        dataset.captured_run_id,
        "captured_counter":
        dataset.captured_counter,
        "run_id":
        dataset.run_id,
        "run_description":
        serial.to_json_for_storage(dataset.description)
    })
    if dataset.run_timestamp_raw is not None:
        xrdataset.attrs["run_timestamp_raw"] = dataset.run_timestamp_raw
    if dataset.completed_timestamp_raw is not None:
        xrdataset.attrs[
            "completed_timestamp_raw"] = dataset.completed_timestamp_raw
    if len(dataset.metadata) > 0:
        for metadata_tag, metadata in dataset.metadata.items():
            xrdataset.attrs[metadata_tag] = metadata
Ejemplo n.º 3
0
def test_integer_timestamps_in_database_are_supported():
    ds = DataSet()

    ds.mark_started()
    ds.mark_completed()

    with atomic(ds.conn) as conn:
        _rewrite_timestamps(conn, ds.run_id, 42, 69)

    assert isinstance(ds.run_timestamp_raw, float)
    assert isinstance(ds.completed_timestamp_raw, float)
    assert isinstance(ds.run_timestamp(), str)
    assert isinstance(ds.completed_timestamp(), str)
Ejemplo n.º 4
0
    def process(self, **kw):
        if None not in self._pathAndId:
            path, runId = self._pathAndId
            ds = DataSet(path_to_db=path, run_id=runId)
            guid = ds.guid
            if ds.number_of_results > self.nLoadedRecords:
                title = f"{os.path.split(path)[-1]} | " \
                        f"run ID: {runId} | GUID: {guid}"
                info = """Started: {}
Finished: {}
GUID: {}
DB-File [ID]: {} [{}]""".format(ds.run_timestamp(), ds.completed_timestamp(),
                                guid, path, runId)

                data = ds_to_datadict(ds)
                data.add_meta('title', title)
                data.add_meta('info', info)
                data.add_meta('qcodes_guid', guid)
                data.add_meta('qcodes_db', path)
                data.add_meta('qcodes_runId', runId)
                data.add_meta('qcodes_completedTS', ds.completed_timestamp())
                data.add_meta('qcodes_runTS', ds.run_timestamp())
                self.nLoadedRecords = ds.number_of_results
                return dict(dataOut=data)
Ejemplo n.º 5
0
def _get_timestamp_button(ds: DataSet) -> Box:
    try:
        total_time = str(
            datetime.fromtimestamp(ds.run_timestamp_raw)  # type: ignore
            -
            datetime.fromtimestamp(ds.completed_timestamp_raw)  # type: ignore
        )
    except TypeError:
        total_time = "?"
    start = ds.run_timestamp()
    body = _yaml_dump({
        ".run_timestamp": start,
        ".completed_timestamp": ds.completed_timestamp(),
        "total_time": total_time,
    })
    return button_to_text(start or "", body)