def json_info(self) -> dict: if self._json_info is None: if not os.path.exists(self.json_fn): self._json_info = attr() with open(self.json_fn, encoding='utf-8') as r: self._json_info = attr(json.load(r)) self._json_info["test_dir"] = self.test_dir self._json_info['visible'] = self.visible self._json_info['fav'] = self.fav_state return self._json_info.jsonify()
def __str__(self): if self._zip: from thexp.base_classes.attr import attr res = attr() if self._add_id: res['ids'] = 'ids' for ph in chain(self._placeholds['x'], self._placeholds['y']): # type:_placehold res[ph.name] = ph.source for dph in self._delegates: # type: _delegate_placehold res[dph.name] = dph.delegate.__class__.__name__ return str(res) else: ids = [] xs = [] ys = [] deles = [] if self._add_id: ids.append('ids') for ph in self._placeholds['x']: xs.append(ph.name) for ph in self._placeholds['y']: ys.append(ph.name) for dph in self._delegates: # type: _delegate_placehold deles.append(dph.name) return str("{}: ({}, {}, {}, {})".format( self._name, ', '.join(ids), ', '.join(xs), ', '.join(ys), ', '.join(deles)))
def json_info(self) -> dict: if self._json_info is None: if not os.path.exists(self.fn_global_info): self._json_info = attr() res = self._json_info with open(self.fn_global_info, encoding='utf-8') as r: try: self._json_info = attr(json.load(r)) res = self._json_info except json.JSONDecodeError as je: print('Error when decoding test {}, path = {}'.format( self.name, self.root)) res = attr() res["test_dir"] = self.root res['visible'] = self.visible res['fav'] = self.isfav res['states'] = self.states return res.jsonify() return self._json_info.jsonify()
""" """ from thexp.base_classes.attr import attr dic = attr() dic.b.d = "asd" dic.a = "asd" print(dic.items()) # print(dic["b"]) # print("g" in dic) print(dic.hash()) # c5e72bde733e687ce89c9798f825e04c
def _sample__getitem__(self, index: int): if self._re_indices is not None: if index >= self.real_num: index = index - self.real_num self._re_indices[index] = (self._re_indices[index] + self.vitu_num) % self.real_num index = self._re_indices[index] if self._indices is not None: index = self._indices[index] ids = [] xs = [] ys = [] for ph in self._placeholds['x']: # type:_placehold source = self._ipts[ph.source] x = source[index] if ph.transform is not None: x = ph.transform(x) ph.value = x xs.append(ph) for ph in self._placeholds['y']: source = self._ipts[ph.source] y = source[index] if ph.transform is not None: y = ph.transform(y) ph.value = y ys.append(ph) for dph in self._delegates: # type:_delegate_placehold if isinstance(dph.delegate, BatchDelegate): continue items = dph.delegate(index, self) if isinstance(items, _Value): items = [items] if isinstance(items, CIterable): for item in items: assert isinstance(item, _Value), 'want instance of _Value, but {}'.format(item) if self._zip: assert item.name is not None, 'value must have name in zip mode' if isinstance(item, X): if dph.transform is not None: item.value = dph.transform(item.value) xs.append(_placehold(name=item.name, value=item.value)) if isinstance(item, Y): if dph.target_transform is not None: item.value = dph.target_transform(item.value) ys.append(_placehold(name=item.name, value=item.value)) if isinstance(item, ID): ids.append(_placehold(name=item.name, value=item.value)) if self._zip: from thexp.base_classes.attr import attr res = attr() if self._add_id: res['_indexs'] = index for ph in ids: res[ph.name] = ph.value for ph in xs: res[ph.name] = ph.value for ph in ys: res[ph.name] = ph.value return res else: ids = [i.value for i in ids] xs = [i.value for i in xs] ys = [i.value for i in ys] if self._add_id: ids.insert(0, index) return [ids, xs, ys]