Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloud Sync #199

Draft
wants to merge 60 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
51f0346
sync setting, activities
previ Apr 10, 2023
c857b1a
wip
previ Apr 18, 2023
a2e6f39
wip
previ Apr 25, 2023
e17230d
wip
previ May 7, 2023
29b0dc4
wip
previ May 21, 2023
15d215d
wip
previ May 28, 2023
f5a4395
wip
previ May 29, 2023
57b2f03
wip
previ Jun 1, 2023
19a4398
wip
previ Jun 2, 2023
9377a57
wip
previ Jun 4, 2023
1cf11aa
wip
previ Jun 4, 2023
8f0e377
wip
previ Jun 4, 2023
0607076
wip
previ Jun 5, 2023
fba1635
wip
previ Jun 5, 2023
e5a2592
wip
previ Jun 5, 2023
870ea4b
wip
previ Jun 5, 2023
ab77159
wip
previ Jun 5, 2023
0b84abb
wip
previ Jun 5, 2023
cb8f7f9
wip
previ Jun 5, 2023
0645172
wip
previ Jun 5, 2023
304f221
wip
previ Jun 5, 2023
affa726
wip
previ Jun 5, 2023
b2999aa
wip
previ Jun 6, 2023
a430f2a
wip
previ Jun 11, 2023
639d4b9
wip
previ Aug 16, 2023
f23d78f
wip
previ Aug 16, 2023
1ba0456
update default config.json
previ Aug 19, 2023
bd2ee94
increase initial delay for testing
previ Aug 19, 2023
f1817f8
debug test api
previ Aug 19, 2023
16ffbad
debug tests
previ Aug 19, 2023
b49c58d
debug tests
previ Aug 19, 2023
24ef531
Update camera_test.py - fix tests
previ Aug 19, 2023
52f5dd1
Update coderbot_test.py - fix
previ Aug 19, 2023
f65bc87
Update camera_test.py fix
previ Aug 19, 2023
7c13bb3
Update coderbot_test.py fix
previ Aug 19, 2023
7070b18
Update coderbot_test.py -fix
previ Aug 19, 2023
14f6478
Update coderbot_test.py fix servo test
previ Aug 19, 2023
164da91
Update Dockerfile stub add CODERBOT_CLOUD_API_ENDPOINT
previ Aug 19, 2023
45e0bce
fixes
previ Aug 26, 2023
8198e09
fix
previ Aug 27, 2023
bfaa258
fix
previ Aug 27, 2023
6969fea
fix
previ Aug 27, 2023
f639184
fix
previ Aug 27, 2023
24dde58
fix
previ Aug 27, 2023
f50165b
wip
previ Dec 23, 2023
4967d4d
bumo deps
previ Dec 24, 2023
ffcb801
bump deps
previ Dec 24, 2023
b6a4401
bump deps
previ Dec 24, 2023
d8ef622
fix audio_devide
previ Dec 24, 2023
e929c0e
fix bot, cam
previ Dec 24, 2023
c89f25c
fix video stream
previ Dec 24, 2023
9ad1051
add uuid
previ Dec 28, 2023
f561d46
add uuid
previ Dec 28, 2023
5880e87
add uuid
previ Dec 28, 2023
2b1be19
add uuid
previ Dec 28, 2023
ca68f8f
fix sync activity, program
previ Dec 30, 2023
e0582ac
fix daveProgram case of null body
previ Dec 31, 2023
e214e59
sync settings
previ Dec 31, 2023
93735f7
fix detectMultiScale
previ Feb 28, 2024
13e081a
schemathesis==3.24.3
previ Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .github/workflows/build_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ on: push
jobs:
test:
runs-on: ubuntu-latest
container: coderbot/coderbot-ci:3.9-bullseye-slim
container:
image: ghcr.io/coderbotorg/coderbot-ci:stub-latest
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GHCR_READ }}
steps:
- uses: actions/checkout@v3 # Checking out the repo
- run: pip install -r docker/stub/requirements.txt
Expand All @@ -21,13 +25,16 @@ jobs:
echo "test complete"
- run: |
export PYTHONPATH=./stub:./coderbot:./test
export CODERBOT_CLOUD_API_ENDPOINT=http://localhost:5000
python3 coderbot/main.py > coderbot.log &
sleep 30
sleep 60
cat coderbot.log
curl http://localhost:5000/api/v1/openapi.json
apt-get install -y python3-venv
mkdir -p schemathesis
python3 -m venv schemathesis
. schemathesis/bin/activate
pip install schemathesis
pip install schemathesis==3.24.3
st run --endpoint 'activities' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
#st run --endpoint 'media' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
st run --endpoint 'control/speak' --hypothesis-max-examples=10 --request-timeout=20 http://localhost:5000/api/v1/openapi.json
Expand Down
59 changes: 47 additions & 12 deletions coderbot/activity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import logging
import uuid
from tinydb import TinyDB, Query
from threading import Lock
from datetime import datetime
# Programs and Activities databases

ACTIVITY_STATUS_DELETED = "deleted"
ACTIVITY_STATUS_ACTIVE = "active"
ACTIVITY_KIND_STOCK = "stock"
ACTIVITY_KIND_USER = "user"


class Activities():
_instance = None

Expand All @@ -14,11 +24,16 @@ def __init__(self):
self.activities = TinyDB("data/activities.json")
self.query = Query()
self.lock = Lock()
self.permanentlyRemoveDeletedActivities()

def load(self, name, default):
def load(self, id, default, active_only=True):
with self.lock:
if name and default is None:
activities = self.activities.search(self.query.name == name)
if id and default is None:
activities = []
if active_only:
activities = self.activities.search((self.query.id == id) & (self.query.status == ACTIVITY_STATUS_ACTIVE))
else:
activities = self.activities.search(self.query.id == id)
if len(activities) > 0:
return activities[0]
elif default is not None:
Expand All @@ -27,25 +42,45 @@ def load(self, name, default):
return None
return None

def save(self, name, activity):
def save(self, activity):
if activity.get("id") is None:
activity["id"] = str(uuid.uuid4())
with self.lock:
# if saved activity is "default", reset existing default activity to "non-default"
if activity.get("default", False) is True:
self.activities.update({'default': False})
if self.activities.search(self.query.name == name) == []:
if self.activities.search(self.query.id == activity.get("id")) == []:
self.activities.insert(activity)
else:
self.activities.update(activity, self.query.name == activity["name"])
self.activities.update(activity, self.query.id == activity.get("id"))
activity = self.activities.search(self.query.id == activity.get("id"))[0]
logging.info("updating/creating activity - id: %s, name: %s", str(activity.get("id")), str(activity.get("name")))
return activity

def delete(self, name):
def delete(self, id, logical = True):
with self.lock:
activities = self.activities.search(self.query.name == name)
activities = self.activities.search(self.query.id == id)
if len(activities) > 0:
activity = activities[0]
if activity.get("default", False) is True:
self.activities.update({'default': True}, self.query.stock == True)
self.activities.remove(self.query.name == activity["name"])
self.activities.update({'default': True}, self.query.kind == ACTIVITY_KIND_STOCK)
if logical:
activity["status"] = ACTIVITY_STATUS_DELETED
activity["modified"] = datetime.now().isoformat()
self.activities.update(activity, self.query.id == id)
else:
self.activities.remove(self.query.id == id)

def list(self):
def permanentlyRemoveDeletedActivities(self):
for a in self.list(active_only=False):
logging.info("checking: " + a["id"])
if a["status"] == ACTIVITY_STATUS_DELETED:
logging.info("deleting: " + a["name"])
self.delete(a["id"], logical=False)

def list(self, active_only = True):
with self.lock:
return self.activities.all()
if active_only:
return self.activities.search(self.query.status == ACTIVITY_STATUS_ACTIVE)
else:
return self.activities.all()
Loading
Loading