我正在开发一个允许从 Github 读取特定 JSON 文件的摄入插件。这些 JSON 文件包含有关我们要使用不同模拟软件模拟的系统的基本信息,每个软件都有自己的输入格式。我们有从 JSON 到每种可用格式的转换器。我现在想在我的插件中添加一个类似于“to_dask”方法的方法“to_format”,但我不断收到“RemoteSequenceSource 对象没有属性“to_format”。有没有办法做到这一点?
from latticejson.convert import to_elegant, to_madx
class RemoteLatticejson(RemoteSource):
"""
A lattice json source on the server
"""
name = 'remote-latticejson'
container = 'python'
partition_access = False
def __init__(self,org, repo, filename, parameters= None, metadata=None, **kwargs):
# super().__init__(org, repo, filename, parameters, metadata=metadata, **kwargs)
self._schema = None
self.org = org
self.repo = repo
self.filename = filename
self.metadata = metadata
self._dict = None
def _load(self):
self._dict = read_remote_file(self.org, self.repo, self.filename)
def _get_schema(self):
if self._dict is None:
self._load()
self._dtypes = {
'version': 'str',
'title': 'str',
'root': 'str',
'elements': 'dict',
'lattice': 'dict'
}
return base.Schema(
datashape=None,
dtype=self._dtypes,
shape=(None, len(self._dtypes)),
npartitions=1,
extra_metadata={}
)
def _get_partition(self, i):
if self._dict is None:
self._load_metadata()
data = [self.read()]
return [self._dict]
def read(self):
if self._dict is None:
self._load()
self.metadata = {
'version': self._dict.get('version'),
'title': self._dict.get('title'),
'root': self._dict.get('root')
}
return self._dict
def to_madx(self):
self._get_schema()
return to_madx(self._dict)
def _close(self):
pass
`