Skip to content

Commit

Permalink
Updates for v0.6 (#114)
Browse files Browse the repository at this point in the history
* Adding the SDKCommonGQL submodule

* add toml

* add loader

* add dict for query

Co-authored-by: Sam Claassens <[email protected]>

* update loader
add comments
add suggestion @GearsAD

* Implementing GQL loader

* update to test for cyclic dependencies - TEST

* Adding a unit test

* add new schemas -
session
robot
user
affordance
annotation
map
update some old schemas blobentry
rename blob to blobentry - for my health
initial map schema - incomplete

Co-authored-by: Sam Claassens <[email protected]>
Co-authored-by: Johannes Terblanche <[email protected]>

* fix DateTime
add Optional

* Updating for new API

Co-authored-by: AlucardLO <[email protected]>

---------

Co-authored-by: Sam Claassens <[email protected]>
Co-authored-by: Danial Gawryjolek <[email protected]>
Co-authored-by: Sam Claassens <[email protected]>
Co-authored-by: Johannes Terblanche <[email protected]>
Co-authored-by: AlucardLO <[email protected]>
  • Loading branch information
6 people authored Apr 28, 2023
1 parent 31942cd commit d0222c9
Show file tree
Hide file tree
Showing 32 changed files with 14,188 additions and 128 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "sdkCommonGQL"]
path = sdkCommonGQL
url = [email protected]:NavAbility/SDKCommonGQL.git
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"python.analysis.extraPaths": [
"./src"
],
"python.formatting.provider": "black"
}
1 change: 1 addition & 0 deletions sdkCommonGQL
Submodule sdkCommonGQL added at af6e08
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
)

_version = "0.5.1"
_version = "0.6.0"

setup(
name="navabilitysdk",
Expand All @@ -38,5 +38,6 @@
"flake8==4.0.1",
"pytest==6.2.5",
"pytest-asyncio==0.18.1",
"pyyaml==6.0",
],
)
2 changes: 1 addition & 1 deletion src/navability/common/versions.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
payload_version = "0.18.1"
payload_version = "0.21.1"
2 changes: 1 addition & 1 deletion src/navability/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
from .variable.variable import Variable, VariableSkeleton, VariableSummary, VariableType
from .variable.variablenodedata import VariableNodeData

from .blob.blob import BlobEntry
from .blob.blobentry import BlobEntry
72 changes: 0 additions & 72 deletions src/navability/entities/blob/blob.py

This file was deleted.

133 changes: 133 additions & 0 deletions src/navability/entities/blob/blobentry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import base64
import json
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
from uuid import UUID, uuid4
from typing import Dict, List, Optional

from marshmallow import EXCLUDE, Schema, fields, post_load

from navability.common.timestamps import TS_FORMAT
from navability.common.versions import payload_version

# type BlobEntry {
# # This is created by server-side GraphQL #
# id: ID! @id
# # This is the forced server generated blobId, or the filesystem blobId. #
# blobId: ID!
# # This is the ID at creation at the edge, do whatever you want with this, but make sure you populate it. #
# originId: ID!
# label: String!
# description: String
# hash: String
# mimeType: String
# blobstore: String
# origin: String
# metadata: Metadata
# timestamp: DateTime
# nstime: BigInt
# _type: String!
# _version: String!

# createdTimestamp: DateTime! @timestamp(operations: [CREATE])
# lastUpdatedTimestamp: DateTime! @timestamp(operations: [CREATE, UPDATE])

# user: [Variable!]! @relationship(type: "DATA_USER", direction: IN)
# robot: [Robot!]! @relationship(type: "DATA_ROBOT", direction: IN)
# session: [Session!]! @relationship(type: "DATA_SESSION", direction: IN)
# variable: [Variable!]! @relationship(type: "DATA_VARIABLE", direction: IN)
# factor: [Factor!]! @relationship(type: "DATA_FACTOR", direction: IN)

# # NOTE: This is for the unique label constraints
# # In this situation, someone has to own this, so cannot be required
# userLabel: String
# robotLabel: String
# sessionLabel: String
# variableLabel: String
# factorLabel: String
# }


@dataclass()
class BlobEntry:
id: Optional[UUID]
blobId: Optional[UUID]
label: str
description: str
# createdTimestamp: datetime # = datetime.utcnow()
# updatedTimestamp: datetime
# size: int
blobstore: str
createdTimestamp: Optional[datetime] = None
lastUpdatedTimestamp: Optional[datetime] = None
hash: str = ''
mimeType: str = 'application/octet-stream'
originId: UUID = uuid4()
origin: str = ''
_type: str = "BlobEntry"
_version: str = payload_version
metadata: dict = field(default_factory=lambda: {})

# Optional
userLabel: Optional[str] = None
robotLabel: Optional[str] = None
sessionLabel: Optional[str] = None
variableLabel: Optional[str] = None
factorLabel: Optional[str] = None

def __repr__(self):
return (
f"<BlobEntry(label={self.label},"
f"label={self.label},id={self.id})>"
)

def dump(self):
return BlobEntrySchema().dump(self)

def dumps(self):
return BlobEntrySchema().dumps(self)

@staticmethod
def load(data):
import pdb; pdb.set_trace()
return BlobEntrySchema().load(data)


# Legacy BlobEntry_ contract
class BlobEntrySchema(Schema):
id = fields.UUID()
label = fields.Str(required=True)
description: str = fields.Str(required=True)
# createdTimestamp: datetime = fields.Method("get_timestamp", "set_timestamp", required=True)
# updatedTimestamp: datetime = fields.Method("get_timestamp", "set_timestamp", required=True)
# size: int = fields.Integer(required=True)
blobstore: str = fields.Str(required=True)
hash = fields.Str(required=False)
mimeType = fields.Str(required=False)
origin = fields.Str(required=False)
metadata = fields.Method("get_metadata", "set_metadata")
_version = fields.Str(required=True)

class Meta:
ordered = True

def get_timestamp(self, obj):
# Return a robust timestamp
ts = obj.timestamp.isoformat(timespec="milliseconds")
if not obj.timestamp.tzinfo:
ts += "+00"
return ts

def set_timestamp(self, obj):
return datetime.strptime(obj["formatted"], TS_FORMAT)

def get_metadata(self, obj):
return base64.b64encode(json.dumps(obj).encode())

def set_metadata(self, obj):
return json.loads(base64.b64decode(obj))

@post_load
def marshal(self, data, **kwargs):
return BlobEntry(**data)
14 changes: 7 additions & 7 deletions src/navability/entities/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

@dataclass()
class Client:
userId: str
robotId: str
sessionId: str
userLabel: str
robotLabel: str
sessionLabel: str

def __repr__(self):
return f"<Client(userId={self.userId}, robotId={self.robotId}, sessionId={self.sessionId})>" # noqa: E501, B950
return f"<Client(userLabel={self.userLabel}, robotId={self.robotLabel}, sessionId={self.sessionLabel})>" # noqa: E501, BLabeLabel

def dump(self):
return ClientSchema().dump(self)
Expand All @@ -24,9 +24,9 @@ def load(data):


class ClientSchema(Schema):
userId = fields.String(required=True)
robotId = fields.String(required=True)
sessionId = fields.String(required=True)
userLabel = fields.String(required=True)
robotLabel = fields.String(required=True)
sessionLabel = fields.String(required=True)

class Meta:
ordered = True
Expand Down
25 changes: 19 additions & 6 deletions src/navability/entities/factor/factor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass, field
from datetime import datetime
from typing import Dict, List
from uuid import UUID
import json
import base64

Expand All @@ -12,6 +13,7 @@

@dataclass()
class FactorSkeleton:
id: UUID
label: str
variableOrderSymbols: List[str]
tags: List[str]
Expand All @@ -34,6 +36,7 @@ def load(data):


class FactorSkeletonSchema(Schema):
id = fields.UUID(required=True)
label = fields.Str(required=True)
variableOrderSymbols = fields.List(
fields.Str, data_key="_variableOrderSymbols", required=True
Expand All @@ -50,7 +53,8 @@ def marshal(self, data, **kwargs):

@dataclass()
class FactorSummary:
label = str
id: UUID
label: str
variableOrderSymbols: List[str]
tags: List[str] = field(default_factory=lambda: ["FACTOR"])
timestamp: datetime = datetime.utcnow()
Expand All @@ -74,6 +78,7 @@ def load(data):


class FactorSummarySchema(Schema):
id = fields.UUID(required=True)
label = fields.Str(required=True)
variableOrderSymbols = fields.List(
fields.Str, data_key="_variableOrderSymbols", required=True
Expand Down Expand Up @@ -153,13 +158,14 @@ def marshal(self, data, **kwargs):

@dataclass()
class Factor:
id: UUID
label: str
fnctype: str
variableOrderSymbols: List[str]
data: FactorData
data: str
tags: List[str] = field(default_factory=lambda: ["FACTOR"])
timestamp: str = datetime.utcnow()
nstime: int = 0
timestamp: datetime = datetime.utcnow()
nstime: str = "0"
solvable: str = 1
_version: str = payload_version

Expand All @@ -183,6 +189,7 @@ def load(data):


class FactorSchema(Schema):
id = fields.UUID(required=True)
label = fields.Str(required=True)
_version = fields.Str(required=True)
variableOrderSymbols = fields.List(
Expand All @@ -193,6 +200,7 @@ class FactorSchema(Schema):
timestamp = fields.Method("get_timestamp", "set_timestamp", required=True)
nstime = fields.Str(default="0")
fnctype = fields.Str(required=True)
metadata = fields.Method("get_metadata", "set_metadata")
solvable = fields.Int(required=True)

class Meta:
Expand All @@ -213,12 +221,17 @@ def set_timestamp(self, obj):
return datetime.strptime(tsraw, TS_FORMAT)

def get_data(self, obj):
return obj.data.dump()
return base64.b64encode(obj.data.dumps().encode())

def set_data(self, ob):
def set_data(self, obj):
db64 = base64.b64decode(ob)
return FactorDataSchema().load(json.loads(db64))

def get_metadata(self, obj):
return base64.b64encode(json.dumps(obj).encode())

def set_metadata(self, obj):
return json.loads(base64.b64decode(obj))

@post_load
def marshal(self, data, **kwargs):
Expand Down
Loading

0 comments on commit d0222c9

Please sign in to comment.