文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit 5b9f8a70 by 李景熙

Merge branch 'develop' of https://gitlab.redhtc.com/Berlincen/DA-Platform into develop

parents 9062d943 323dd92f
# from peewee import *
import traceback import traceback
import json import json
from flask_mongoengine import MongoEngine from flask_mongoengine import MongoEngine
...@@ -19,7 +18,7 @@ class Result: ...@@ -19,7 +18,7 @@ class Result:
# 像素点 # 像素点
class Point(db.EmbeddedDocument): class Point(db.EmbeddedDocument):
pointId = db.IntField(required=True, unique=True) pointId = db.IntField(required=True)
X = db.FloatField(required=True) X = db.FloatField(required=True)
Y = db.FloatField(required=True) Y = db.FloatField(required=True)
...@@ -31,7 +30,7 @@ class Point(db.EmbeddedDocument): ...@@ -31,7 +30,7 @@ class Point(db.EmbeddedDocument):
# 标签 # 标签
class Label(db.EmbeddedDocument): class Label(db.EmbeddedDocument):
labelId = db.IntField(required=True, unique=True) labelId = db.IntField(required=True)
labelName = db.StringField(required=True) labelName = db.StringField(required=True)
pointList = db.ListField(db.EmbeddedDocumentField(Point)) pointList = db.ListField(db.EmbeddedDocumentField(Point))
...@@ -96,30 +95,9 @@ def create_images(image_list): ...@@ -96,30 +95,9 @@ def create_images(image_list):
return res return res
# 获取图片
def getImage(relation_list):
try:
image_list = Image.objects(relationId__in=relation_list)
data = [json.dumps(image.to_json(), ensure_ascii=False) for image in image_list]
return Result(1, len(image_list), data)
except Exception as e:
traceback.print_exc()
return Result(0, repr(e), {})
# 保存图片标注结果
def saveImage(image_list):
try:
images = create_images(image_list)
return Result(1, len(images), {})
except Exception as e:
traceback.print_exc()
return Result(0, repr(e), {})
# 图层实体 # 图层实体
class LayerIntity(db.EmbeddedDocument): class LayerEntity(db.EmbeddedDocument):
layerId = db.IntField(unique=True) layerId = db.IntField(required=True)
layerName = db.StringField(required=True) layerName = db.StringField(required=True)
layerUrl = db.StringField(required=True) layerUrl = db.StringField(required=True)
...@@ -131,19 +109,46 @@ class LayerIntity(db.EmbeddedDocument): ...@@ -131,19 +109,46 @@ class LayerIntity(db.EmbeddedDocument):
# 图层标注的数据库 # 图层标注的数据库
class Layer(db.Document): class Layer(db.Document):
relationId = db.IntField(required=True) relationId = db.IntField(required=True, unique=True)
layerList = db.ListField(db.EmbeddedDocumentField(LayerIntity)) layerEntityList = db.ListField(db.EmbeddedDocumentField(LayerEntity))
labelList = db.ListField(db.EmbeddedDocumentField(Label)) labelList = db.ListField(db.EmbeddedDocumentField(Label))
def to_json(self): def to_json(self):
return {"relationId": self.relationId, return {"relationId": self.relationId,
"layerList": [i.to_json for i in self.layerList], "layerEntityList": [i.to_json() for i in self.layerEntityList],
"labelList": [i.to_json for i in self.labelList] "labelList": [i.to_json() for i in self.labelList]
} }
# 根据json列表创建对象列表
def create_layer_entities(layer_entity_list):
res = []
for i in layer_entity_list:
layer_entity = LayerEntity(
layerId=i['layerId'],
layerName=i['layerName'],
layerUrl=i['layerUrl']
)
res.append(layer_entity)
return res
# 根据json列表创建对象列表
def create_layers(layer_list):
res = []
for i in layer_list:
layer = Layer(
relationId=i['relationId'],
layerEntityList=create_layer_entities(i['layerEntityList']),
labelList=create_labels(i['labelList'])
)
layer.save()
res.append(layer)
return res
# 地标实体 # 地标实体
class LandmarkIntity(db.EmbeddedDocument): class LandmarkEntity(db.EmbeddedDocument):
landmarkId = db.IntField(required=True) landmarkId = db.IntField(required=True)
landmarkName = db.StringField() landmarkName = db.StringField()
X = db.FloatField(required=True) X = db.FloatField(required=True)
...@@ -158,67 +163,86 @@ class LandmarkIntity(db.EmbeddedDocument): ...@@ -158,67 +163,86 @@ class LandmarkIntity(db.EmbeddedDocument):
# 地标存储表 # 地标存储表
class Landmark(db.Document): class Landmark(db.Document):
relationId = db.IntField(required=True) relationId = db.IntField(required=True, unique=True)
layerList = db.ListField(db.EmbeddedDocumentField(LayerIntity)) layerEntityList = db.ListField(db.EmbeddedDocumentField(LayerEntity))
landmarkList = db.ListField(db.EmbeddedDocumentField(LandmarkIntity)) landmarkEntityList = db.ListField(db.EmbeddedDocumentField(LandmarkEntity))
def to_json(self): def to_json(self):
return {"relationId": self.relationId, return {"relationId": self.relationId,
"layerList": [i.to_json for i in self.layerList], "layerEntityList": [i.to_json() for i in self.layerEntityList],
"landmarkList": [i.to_json for i in self.landmarkList] "landmarkEntityList": [i.to_json() for i in self.landmarkEntityList]
} }
# def getLayer(relation_list): # 根据json列表创建对象列表
# try: def create_landmark_entities(landmark_entity_list):
# fragment_list = [Fragment.get(Fragment.relationId == r_id) for r_id in relation_list] res = []
# data = [fragment.to_json for fragment in fragment_list] for i in landmark_entity_list:
# return Result(1, len(fragment_list), data) landmark_entity = LandmarkEntity(
# except: landmarkId=i['landmarkId'],
# return Result(0, "some relation ids don't exist", {}) landmarkName=i['landmarkName'],
# X=i['X'],
# Y=i['Y']
# def saveLayer(fragment_list, landmark_list): )
# try: res.append(landmark_entity)
# for item in fragment_list: return res
# fragment = Fragment(relationId=item['relationId'],
# layerList=item['layerList'],
# labelList=item['labelList'] # 根据json列表创建对象列表
# ) def create_landmarks(landmark_list):
# fragment.save() res = []
# for i in landmark_list:
# for item in landmark_list: landmark = Landmark(
# landmark = Landmark(relationId=item['relationId'], relationId=i['relationId'],
# layerList=item['layerList'], layerEntityList=create_layer_entities(i['layerEntityList']),
# landmark_list=item['landmark_list'] landmarkEntityList=create_landmark_entities(i['landmarkEntityList'])
# ) )
# landmark.save() res.append(landmark)
# landmark.save()
# return Result(1, len(fragment_list), {}) return res
# except:
# return Result(0, "error", {})
# 获取图片
# meta = {"imageList": [ def getImage(relation_list):
# {"relationId": 123, try:
# "imageUrl": "tom@qq.com", image_list = Image.objects(relationId__in=relation_list)
# "labelList": [{ data = [json.dumps(image.to_json(), ensure_ascii=False) for image in image_list]
# "labelId": 123, return Result(1, len(image_list), {"imageList": data})
# "labelName": "标注", except Exception as e:
# "pointList": [{ traceback.print_exc()
# "pointId": 14, return Result(0, repr(e), {})
# "X": 234,
# "Y": 14.25
# }] # 保存图片标注结果
# }]}, def saveImage(image_list):
# {"relationId": 156, try:
# "imageUrl": "jerry@qq.com", images = create_images(image_list)
# "labelList": [{ return Result(1, len(images), {})
# "labelId": 13, except Exception as e:
# "labelName": "标注", traceback.print_exc()
# "pointList": [{ return Result(0, repr(e), {})
# "pointId": 145,
# "X": 2.834,
# "Y": 145 # 获取图层
# }] def getLayer(relation_list):
# }]} try:
# ]} layer_list = Layer.objects(relationId__in=relation_list)
landmark_list = Landmark.objects(relationId__in=relation_list)
layer_data = [json.dumps(layer.to_json(), ensure_ascii=False) for layer in layer_list]
landmark_data = [json.dumps(landmark.to_json(), ensure_ascii=False) for landmark in landmark_list]
return Result(1, ["layers:", len(layer_data), "landmarks:", len(landmark_data)],
{"layerList": layer_data, "landmarkList": landmark_data})
except Exception as e:
traceback.print_exc()
return Result(0, repr(e), {})
# 保存图层标注结果
def saveLayer(layer_list, landmark_list):
try:
layers = create_layers(layer_list)
landmarks = create_landmarks(landmark_list)
return Result(1, ["layers:", len(layers), "landmarks:", len(landmarks)], {})
except Exception as e:
traceback.print_exc()
return Result(0, repr(e), {})
...@@ -61,3 +61,93 @@ def save_layer(): ...@@ -61,3 +61,93 @@ def save_layer():
'data': ret.data 'data': ret.data
} }
return json.dumps(res) return json.dumps(res)
# 保存图片标注结果的测试数据
# meta = {
# "imageList": [
# {
# "relationId": 123,
# "imageUrl": "tom@qq.com",
# "labelList": [
# {
# "labelId": 123,
# "labelName": "标注",
# "pointList": [
# {
# "pointId": 14,
# "X": 234,
# "Y": 14.25
# }
# ]
# }
# ]
# },
# {
# "relationId": 156,
# "imageUrl": "jerry@qq.com",
# "labelList": [
# {
# "labelId": 13,
# "labelName": "标注",
# "pointList": [
# {
# "pointId": 145,
# "X": 2.834,
# "Y": 145
# }
# ]
# }
# ]
# }
# ]
# }
# 保存图层标注结果的测试数据
# meta = {
# "layerList": [
# {
# "relationId": 8,
# "layerEntityList": [
# {
# "layerId": 7,
# "layerName": "layerNo1",
# "layerUrl": "www.layerNo1.com"
# }
# ],
# "labelList": [
# {
# "labelId": 181,
# "labelName": "label01",
# "pointList": [
# {
# "pointId": 21,
# "X": 211.01,
# "Y": 211.02
# }
# ]
# }
# ]
# }
# ],
# "landmarkList": [
# {
# "relationId": 1,
# "layerEntityList": [
# {
# "layerId": 3,
# "layerName": "layerNo3",
# "layerUrl": "www.layerNo3.com"
# }
# ],
# "landmarkEntityList": [
# {
# "landmarkId": 31,
# "landmarkName": "landmark31",
# "X": 31.1,
# "Y": 31.2
# }
# ]
# }
# ]
# }
Markdown is supported
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