Initial backend+frontend connection + gitignore changes

This commit is contained in:
Alan Rynne 2021-10-29 11:17:40 +02:00
Родитель ce3cf66db7
Коммит 8dcc98164d
7 изменённых файлов: 158 добавлений и 110 удалений

4
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,4 @@
.vscode/
server/__pycache__/

160
frontend/package-lock.json сгенерированный
Просмотреть файл

@ -1744,16 +1744,6 @@
"integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==",
"dev": true
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"cacache": {
"version": "13.0.1",
"resolved": "https://registry.npmjs.org/cacache/-/cacache-13.0.1.tgz",
@ -1780,34 +1770,6 @@
"unique-filename": "^1.1.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"fs-extra": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz",
@ -1819,25 +1781,6 @@
"universalify": "^0.1.0"
}
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
"integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
@ -1854,16 +1797,6 @@
"minipass": "^3.1.1"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
},
"terser-webpack-plugin": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/terser-webpack-plugin/-/terser-webpack-plugin-2.3.8.tgz",
@ -1880,18 +1813,6 @@
"terser": "^4.6.12",
"webpack-sources": "^1.4.3"
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.2",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.8.2.tgz",
"integrity": "sha512-Nkq+z9mAsMEK+qkXgK+9Ia7D8w9uu9j4ut0IMT5coMfux3rCgIp1QBB1CYwY0M34A1nRMSONEaWXxAAw6xSl/Q==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
}
}
}
},
@ -11513,6 +11434,87 @@
}
}
},
"vue-loader-v16": {
"version": "npm:vue-loader@16.8.2",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.8.2.tgz",
"integrity": "sha512-Nkq+z9mAsMEK+qkXgK+9Ia7D8w9uu9j4ut0IMT5coMfux3rCgIp1QBB1CYwY0M34A1nRMSONEaWXxAAw6xSl/Q==",
"dev": true,
"optional": true,
"requires": {
"chalk": "^4.1.0",
"hash-sum": "^2.0.0",
"loader-utils": "^2.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dev": true,
"optional": true,
"requires": {
"color-convert": "^2.0.1"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"dev": true,
"optional": true,
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dev": true,
"optional": true,
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
"dev": true,
"optional": true
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
"dev": true,
"optional": true
},
"loader-utils": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz",
"integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==",
"dev": true,
"optional": true,
"requires": {
"big.js": "^5.2.2",
"emojis-list": "^3.0.0",
"json5": "^2.1.2"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"dev": true,
"optional": true,
"requires": {
"has-flag": "^4.0.0"
}
}
}
},
"vue-router": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.5.1.tgz",

Просмотреть файл

@ -84,14 +84,18 @@
</v-col>
<div>
You are about to compare commit
<v-chip :close="commitA" @click:close="commitA = null">
<v-chip :close="commitA != null" @click:close="commitA = null">
{{ commitA ? commitA.id : "Select commit" }}
</v-chip>
against
<v-chip :close="commitB" @click:close="commitB = null">
<v-chip :close="commitB != null" @click:close="commitB = null">
{{ commitB ? commitB.id : "Select commit" }}
</v-chip>
<v-btn color="success" :disabled="!commitA || !commitB">
<v-btn
color="success"
:disabled="!commitA || !commitB"
@click="requestDiff"
>
Run this!
</v-btn>
</div>
@ -100,6 +104,8 @@
</template>
<script>
import { TOKEN } from "@/speckleUtils"
export default {
name: "CommitPanel",
components: {},
@ -109,6 +115,24 @@ export default {
commitA: null,
commitB: null
}
},
methods: {
async requestDiff() {
console.log("diff requested for", this.commitA.id, this.commitB.id)
var diffUrl = `http://localhost:8000/diff/${this.$route.params.id}/${this.commitA.id}/${this.commitB.id}`
console.log(diffUrl)
fetch(diffUrl, {
headers: {
method: "POST",
cors: "no-cors",
Authorisation: `Bearer ${localStorage.getItem(TOKEN)}`,
"Content-type": "application/json",
"Access-Control-Allow-Origin": "*"
}
})
.then(async res => console.log("fetch success", await res.json(), res))
.catch(err => console.warn("fetch failed", err))
}
}
}
</script>

Двоичные данные
server/__pycache__/main.cpython-39.pyc

Двоичный файл не отображается.

Двоичные данные
server/__pycache__/mesh_diff.cpython-39.pyc

Двоичный файл не отображается.

Просмотреть файл

@ -1,14 +1,33 @@
from typing import Optional
from fastapi import FastAPI
from fastapi import FastAPI, Request
from mesh_diff import compare_meshes
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
origins = [
"http://localhost",
"http://localhost:8080",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/diff/{stream_id}/{commit_current}/{commit_previous}")
def get_diff(stream_id: str, commit_current: str, commit_previous: str, q: Optional[str] = None):
return compare_meshes(stream_id, commit_current, commit_previous)
def get_diff(stream_id: str, commit_current: str, commit_previous: str, request: Request):
print(request)
print(request.headers.get("Authorisation"))
token = request.headers.get("Authorisation").split(" ")[1]
print(token)
return compare_meshes(stream_id, commit_current, commit_previous, token)

Просмотреть файл

@ -17,21 +17,19 @@ from specklepy.objects.other import RenderMaterial
import os
HOST = "speckle.xyz"
#STREAM_ID = "8325294b8f"
#COMMIT_ID = "d930269725" # current commit
#PREV_COMMIT_ID = "e9d8f67969" # previous commit
HOST = "latest.speckle.dev"
DIFF_BRANCH = "diff"
COLORS = [-6426, -13108, -19790, -26215, -32640, -39322, -45747, -52429, -59111, -65536]
COLORS = [-6426, -13108, -19790, -26215, -
32640, -39322, -45747, -52429, -59111, -65536]
WHITE = -1
def get_authenticated_client() -> SpeckleClient:
client = SpeckleClient(host=HOST)
account = get_default_account()
client.authenticate(token=account.token)
def get_authenticated_client(token: str) -> SpeckleClient:
client = SpeckleClient(host=HOST)
client.authenticate(token=token)
return client
def receive_data(
client: SpeckleClient, stream_id: str, commit_id: str
) -> Any:
@ -45,7 +43,8 @@ def receive_data(
return res
def get_all_meshes(child:Base):
def get_all_meshes(child: Base):
meshes = []
names = child.get_dynamic_member_names()
@ -58,7 +57,7 @@ def get_all_meshes(child:Base):
if not hasattr(prop, "displayMesh"):
break
meshes.append((prop.displayMesh, prop.id))
elif isinstance(prop, list):
elif isinstance(prop, list):
for p in prop:
if isinstance(p, Mesh):
meshes.append((p, p.id))
@ -68,6 +67,7 @@ def get_all_meshes(child:Base):
meshes.append((p.displayMesh, p.id))
return meshes
def get_all_points(meshes: List[Mesh]):
points = []
for mesh in meshes:
@ -79,16 +79,19 @@ def get_all_points(meshes: List[Mesh]):
points.append(point)
return points
def find_point(current: Point, points: List[Point]):
for point in points:
if (point.x == current.x and point.y == current.y and point.z == current.z):
return True
return False
def find_closest_point(current: Point, points: List[Point]):
smallest_distance = None
for point in points:
d = ((current.x - point.x)**2 + (current.y - point.y)**2 + (current.z - point.z)**2)**0.5
d = ((current.x - point.x)**2 + (current.y - point.y)
** 2 + (current.z - point.z)**2)**0.5
if smallest_distance is not None:
if d > smallest_distance:
continue
@ -96,12 +99,12 @@ def find_closest_point(current: Point, points: List[Point]):
return smallest_distance
def compare_meshes(stream_id: str, commit_current: str, commit_previous: str):
client = get_authenticated_client()
def compare_meshes(stream_id: str, commit_current: str, commit_previous: str, token: str):
client = get_authenticated_client(token)
# see if existing diff commit already exists
# query for latest x commits in diff branch
# read commit message & parse
# read commit message & parse
# return url if found
# get meshes from commits
@ -152,7 +155,7 @@ def compare_meshes(stream_id: str, commit_current: str, commit_previous: str):
diff_values = []
for vertex in vertices:
diff_values.append(find_closest_point(vertex, previous_points))
# determine color value for vertex by remapping domain
bin_size = max(diff_values) / len(COLORS)
for i in range(0, len(vertices), 1):
@ -175,11 +178,10 @@ def compare_meshes(stream_id: str, commit_current: str, commit_previous: str):
prev_meshes.append(mesh)
# create a new commit with the diff meshes and changed edges
return send_diff_data(stream_id, commit_current, commit_previous, diff_meshes, match_meshes, prev_meshes)
return send_diff_data(stream_id, commit_current, commit_previous, diff_meshes, match_meshes, prev_meshes, client)
def send_diff_data(stream_id: str, commit_current: str, commit_previous: str, meshes: List[Mesh], unchanged: List[Mesh], prev: List[Mesh]):
client = get_authenticated_client()
def send_diff_data(stream_id: str, commit_current: str, commit_previous: str, meshes: List[Mesh], unchanged: List[Mesh], prev: List[Mesh], client):
# create a branch if necessary
branches = client.branch.list(stream_id)
@ -201,12 +203,9 @@ def send_diff_data(stream_id: str, commit_current: str, commit_previous: str, me
commit_id = client.commit.create(
stream_id,
hash, # object id
hash, # object id
DIFF_BRANCH,
message= commit_current + "-" + commit_previous
message=commit_current + "-" + commit_previous
)
return 'https://speckle.xyz/streams/' + stream_id + '/commits/' + commit_id
return f'https://{HOST}/streams/' + stream_id + '/commits/' + commit_id