文档服务地址: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 json
from flask_mongoengine import MongoEngine
......@@ -19,7 +18,7 @@ class Result:
# 像素点
class Point(db.EmbeddedDocument):
pointId = db.IntField(required=True, unique=True)
pointId = db.IntField(required=True)
X = db.FloatField(required=True)
Y = db.FloatField(required=True)
......@@ -31,7 +30,7 @@ class Point(db.EmbeddedDocument):
# 标签
class Label(db.EmbeddedDocument):
labelId = db.IntField(required=True, unique=True)
labelId = db.IntField(required=True)
labelName = db.StringField(required=True)
pointList = db.ListField(db.EmbeddedDocumentField(Point))
......@@ -96,30 +95,9 @@ def create_images(image_list):
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):
layerId = db.IntField(unique=True)
class LayerEntity(db.EmbeddedDocument):
layerId = db.IntField(required=True)
layerName = db.StringField(required=True)
layerUrl = db.StringField(required=True)
......@@ -131,19 +109,46 @@ class LayerIntity(db.EmbeddedDocument):
# 图层标注的数据库
class Layer(db.Document):
relationId = db.IntField(required=True)
layerList = db.ListField(db.EmbeddedDocumentField(LayerIntity))
relationId = db.IntField(required=True, unique=True)
layerEntityList = db.ListField(db.EmbeddedDocumentField(LayerEntity))
labelList = db.ListField(db.EmbeddedDocumentField(Label))
def to_json(self):
return {"relationId": self.relationId,
"layerList": [i.to_json for i in self.layerList],
"labelList": [i.to_json for i in self.labelList]
"layerEntityList": [i.to_json() for i in self.layerEntityList],
"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)
landmarkName = db.StringField()
X = db.FloatField(required=True)
......@@ -158,67 +163,86 @@ class LandmarkIntity(db.EmbeddedDocument):
# 地标存储表
class Landmark(db.Document):
relationId = db.IntField(required=True)
layerList = db.ListField(db.EmbeddedDocumentField(LayerIntity))
landmarkList = db.ListField(db.EmbeddedDocumentField(LandmarkIntity))
relationId = db.IntField(required=True, unique=True)
layerEntityList = db.ListField(db.EmbeddedDocumentField(LayerEntity))
landmarkEntityList = db.ListField(db.EmbeddedDocumentField(LandmarkEntity))
def to_json(self):
return {"relationId": self.relationId,
"layerList": [i.to_json for i in self.layerList],
"landmarkList": [i.to_json for i in self.landmarkList]
"layerEntityList": [i.to_json() for i in self.layerEntityList],
"landmarkEntityList": [i.to_json() for i in self.landmarkEntityList]
}
# def getLayer(relation_list):
# try:
# fragment_list = [Fragment.get(Fragment.relationId == r_id) for r_id in relation_list]
# data = [fragment.to_json for fragment in fragment_list]
# return Result(1, len(fragment_list), data)
# except:
# return Result(0, "some relation ids don't exist", {})
#
#
# def saveLayer(fragment_list, landmark_list):
# try:
# for item in fragment_list:
# fragment = Fragment(relationId=item['relationId'],
# layerList=item['layerList'],
# labelList=item['labelList']
# )
# fragment.save()
#
# for item in landmark_list:
# landmark = Landmark(relationId=item['relationId'],
# layerList=item['layerList'],
# landmark_list=item['landmark_list']
# )
# landmark.save()
#
# return Result(1, len(fragment_list), {})
# except:
# return Result(0, "error", {})
# 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
# }]
# }]}
# ]}
# 根据json列表创建对象列表
def create_landmark_entities(landmark_entity_list):
res = []
for i in landmark_entity_list:
landmark_entity = LandmarkEntity(
landmarkId=i['landmarkId'],
landmarkName=i['landmarkName'],
X=i['X'],
Y=i['Y']
)
res.append(landmark_entity)
return res
# 根据json列表创建对象列表
def create_landmarks(landmark_list):
res = []
for i in landmark_list:
landmark = Landmark(
relationId=i['relationId'],
layerEntityList=create_layer_entities(i['layerEntityList']),
landmarkEntityList=create_landmark_entities(i['landmarkEntityList'])
)
res.append(landmark)
landmark.save()
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), {"imageList": 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), {})
# 获取图层
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():
'data': ret.data
}
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