Commit 819bce72 authored by Wei Shoulin's avatar Wei Shoulin
Browse files

to proto model

parent 76fa06a5
...@@ -39,4 +39,19 @@ class Result(dict): ...@@ -39,4 +39,19 @@ class Result(dict):
def append(self, k: str, v): def append(self, k: str, v):
self[k] = v self[k] = v
return self
class Request(object):
def __init__(self):
super(Request, self).__init__()
@staticmethod
def from_dict(d: dict):
r = Request()
for k, v in d.items():
r.append(k, v)
return r
def append(self, k: str, v):
self.__setattr__(k, v)
return self return self
\ No newline at end of file
...@@ -4,6 +4,8 @@ def from_proto_model_list(clazz, records): ...@@ -4,6 +4,8 @@ def from_proto_model_list(clazz, records):
return [clazz().from_proto_model(r) for r in records] return [clazz().from_proto_model(r) for r in records]
def from_dict_list(clazz, records): def from_dict_list(clazz, records):
return [clazz().from_dict(r) for r in records] return [clazz().from_dict(r) for r in records]
def to_proto_model_list(protoObjClazz, records):
return [r.to_proto_model(protoObjClazz) for r in records]
@dataclasses.dataclass @dataclasses.dataclass
class BaseModel: class BaseModel:
...@@ -16,6 +18,17 @@ class BaseModel: ...@@ -16,6 +18,17 @@ class BaseModel:
for k in self.__dataclass_fields__.keys(): for k in self.__dataclass_fields__.keys():
self.__setattr__(k, record.__getattribute__(k)) self.__setattr__(k, record.__getattribute__(k))
return self return self
def to_proto_model(self, protoObjClazz):
obj = protoObjClazz()
for k in self.__dataclass_fields__.keys():
v = self.__getattribute__(k)
if v is not None:
if isinstance(v, list) or isinstance(v, tuple) or isinstance(v, dict):
obj.__getattribute__(k).extend(v)
else:
obj.__setattr__(k, v)
return obj
@dataclasses.dataclass @dataclasses.dataclass
class Gaia3Record(BaseModel): class Gaia3Record(BaseModel):
...@@ -123,14 +136,3 @@ class Gaia3Record(BaseModel): ...@@ -123,14 +136,3 @@ class Gaia3Record(BaseModel):
def __init__(self): def __init__(self):
self.AstrometricNObsAc = 0 self.AstrometricNObsAc = 0
UPLOAD_CHUNK_SIZE = 1024*1000*4
STATUS_SUCESS = 0
REF_TYPE_BIAS = "bias"
REF_TYPE_DARK = "dark"
REF_TYPE_FlAT = "flat"
REF_TYPE_ARC = "arc"
REF_TYPE_LAMP = "lamp"
REF_TYPE_SKY = "sky"
REF_TYPES = (REF_TYPE_BIAS, REF_TYPE_DARK, REF_TYPE_FlAT, REF_TYPE_ARC, REF_TYPE_LAMP, REF_TYPE_SKY)
OBS_TYPE_SCI = "sci"
OBS_TYPE_CAL = "cal"
OBS_TYPE_TEST = "test"
OBS_TYPE_JOIN = "join" # joint observation fo IFS and MCI
OBS_TYPES = (OBS_TYPE_SCI, OBS_TYPE_CAL, OBS_TYPE_TEST, OBS_TYPE_JOIN)
MODULE_MSC = "MSC"
MODULE_IFS = "IFS"
MODULE_MCI = "MCI"
MODULE_CPIC = "CPIC"
MODULE_THZ = "HSTDM"
MODULES = (MODULE_MSC, MODULE_IFS, MODULE_MCI, MODULE_CPIC, MODULE_THZ)
PRC_MODULE_QC0 = "QC0"
PRC_MODULE_QC1 = "QC1"
PRC_MODULE_MSC_INSTRUMENT_EFFECT = "MSC-IE"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment