Skip to content
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
previ committed May 7, 2023
commit e17230de49bcaf5fae555007b521602bf3999d0a
40 changes: 20 additions & 20 deletions coderbot/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ def run(self):
while(True):
logging.info("run.sync.begin")
settings = Config.read()
syncmodes = settings.get("syncmodes", {"settings": "n", "activities": "n", "programs": "n"})
sync_modes = settings.get("sync_modes", {"settings": "n", "activities": "n", "programs": "n"})
sync_period = int(settings.get("sync_period", "60"))

# Enter a context with an instance of the API client
with cloud_api_robot_client.ApiClient(self.configuration) as api_client:
# Create an instance of the API class
api_instance = robot_sync_api.RobotSyncApi(api_client)

self.sync_settings(api_instance, syncmodes["settings"])
self.sync_activities(api_instance, syncmodes["activities"])
self.sync_programs(api_instance, syncmodes["programs"])
self.sync_settings(api_instance, sync_modes["settings"])
self.sync_activities(api_instance, sync_modes["activities"])
self.sync_programs(api_instance, sync_modes["programs"])

sleep(sync_period)
logging.info("run.sync.end")

def sync_settings(self, api_instance, syncmode):
def sync_settings(self, api_instance, sync_mode):
try:
# Create an instance of the API class
api_response = api_instance.get_robot_setting()
Expand All @@ -81,7 +81,7 @@ def sync_settings(self, api_instance, syncmode):
local_most_recent = datetime.fromisoformat(cloud_setting_object["modified"]).timestamp() < Config.modified()
logging.info("settings.syncing: " + cloud_setting_object.get("id") + " name: " + cloud_setting_object.get("id"))
if cloud_setting != local_setting:
if syncmode == SYNC_UPSTREAM or (syncmode == SYNC_BIDIRECTIONAL and local_most_recent):
if sync_mode == SYNC_UPSTREAM or (sync_mode == SYNC_BIDIRECTIONAL and local_most_recent):
body = Setting(
id = cloud_setting_object.get('id'),
org_id = cloud_setting_object.get('org_id'),
Expand All @@ -93,13 +93,13 @@ def sync_settings(self, api_instance, syncmode):
)
api_response = api_instance.set_robot_setting(body)
logging.info("settings.upstream")
if syncmode == SYNC_DOWNSTREAM: # setting, down
if sync_mode == SYNC_DOWNSTREAM: # setting, down
Config.write(cloud_setting.data.setting)
logging.info("settings.downstream")
except cloud_api_robot_client.ApiException as e:
logging.warn("Exception when calling settings RobotSyncApi: %s\n" % e)

def sync_activities(self, api_instance, syncmode):
def sync_activities(self, api_instance, sync_mode):
activities = Activities.get_instance().list()
try:
# Get robot activities
Expand All @@ -123,7 +123,7 @@ def sync_activities(self, api_instance, syncmode):
if ac is not None and ac.get("data") != al.get("data"):
al["modified"] = al.get("modified", datetime.now(tz=timezone.utc).isoformat())
local_activity_more_recent = datetime.fromisoformat(ac.get("modified")).timestamp() < datetime.fromisoformat(al.get("modified")).timestamp()
if syncmode == SYNC_UPSTREAM or (local_activity_more_recent and syncmode == SYNC_BIDIRECTIONAL):
if sync_mode == SYNC_UPSTREAM or (local_activity_more_recent and sync_mode == SYNC_BIDIRECTIONAL):
ac["data"] = al.get("data")
ac["modified"] = al.get("modified")
body = Activity(
Expand All @@ -138,12 +138,12 @@ def sync_activities(self, api_instance, syncmode):
#logging.info("run.activities.cloud.saving")
api_response = api_instance.set_robot_activity(ac.get("id"), body)
logging.info("activities.update.upstream: " + al.get("name"))
elif syncmode == "d" or (not local_activity_more_recent and syncmode == SYNC_BIDIRECTIONAL):
elif sync_mode == "d" or (not local_activity_more_recent and sync_mode == SYNC_BIDIRECTIONAL):
al["data"] = ac.get("data")
al["modified"] = ac.get("modified")
Activities.get_instance().save(al.get("name"), al)
logging.info("activities.update.downstream: " + al.get("name"))
elif ac is None and syncmode in [SYNC_UPSTREAM, SYNC_BIDIRECTIONAL]:
elif ac is None and sync_mode in [SYNC_UPSTREAM, SYNC_BIDIRECTIONAL]:
body = Activity(
id="",
org_id="",
Expand All @@ -158,18 +158,18 @@ def sync_activities(self, api_instance, syncmode):
al["org_id"] = api_response.body["org_id"]
Activities.get_instance().save(al.get("name"), al)
logging.info("activities.create.upstream: " + al.get("name"))
elif ac is None and syncmode in [SYNC_DOWNSTREAM]:
elif ac is None and sync_mode in [SYNC_DOWNSTREAM]:
Activities.get_instance().delete(al.get("name"))
logging.info("activities.delete.downstream: " + al.get("name"))
for k, ac in a_c_m.items():
if a_l_m.get(k) is None and syncmode in [SYNC_DOWNSTREAM, SYNC_BIDIRECTIONAL]:
if a_l_m.get(k) is None and sync_mode in [SYNC_DOWNSTREAM, SYNC_BIDIRECTIONAL]:
Activities.get_instance().save(ac.get("name"), ac)
logging.info("activities.create.downstream: " + ac.get("name"))

except cloud_api_robot_client.ApiException as e:
logging.warn("Exception when calling activities RobotSyncApi: %s\n" % e)

def sync_programs(self, api_instance, syncmode):
def sync_programs(self, api_instance, sync_mode):
programs = list()
programs_to_be_deleted = list()
for p in ProgramEngine.get_instance().prog_list(active_only=False):
Expand Down Expand Up @@ -204,12 +204,12 @@ def sync_programs(self, api_instance, syncmode):
pc.get("code") == pl.get("code") and
pc.get("dom_code") == pl.get("dom_code") and
pc.get("status") == pl.get("status"))
logging.info("programs.syncing: " + str(pl.get("id")) + " name: " + pl.get("name"))
logging.info("programs.syncing: " + str(pl.get("id")) + " name: " + pl.get("name") + " sync_mode: " + sync_mode + " pc: " + str(pc))

if pc is not None and not pc_pl_equals:
pl["modified"] = pl.get("modified", datetime.now(tz=timezone.utc).isoformat())
local_program_more_recent = datetime.fromisoformat(pc.get("modified")).timestamp() < datetime.fromisoformat(pl.get("modified")).timestamp()
if syncmode == SYNC_UPSTREAM or (local_program_more_recent and syncmode == SYNC_BIDIRECTIONAL) and not to_be_deleted:
if sync_mode == SYNC_UPSTREAM or (local_program_more_recent and sync_mode == SYNC_BIDIRECTIONAL) and not to_be_deleted:
pc["data"] = pl.get("data")
pc["modified"] = pl.get("modified")
body = Program(
Expand All @@ -225,12 +225,12 @@ def sync_programs(self, api_instance, syncmode):
#logging.info("run.activities.cloud.saving")
api_response = api_instance.set_robot_program(pc.get("id"), body)
logging.info("programs.update.upstream: " + pl.get("name"))
elif syncmode == "d" or (not local_program_more_recent and syncmode == SYNC_BIDIRECTIONAL):
elif sync_mode == SYNC_DOWNSTREAM or (not local_program_more_recent and sync_mode == SYNC_BIDIRECTIONAL):
pl["data"] = pc.get("data")
pl["modified"] = pc.get("modified")
ProgramEngine.get_instance().save(program.Program.from_dict(pl))
logging.info("programs.update.downstream: " + pl.get("name"))
elif pc is None and syncmode in [SYNC_UPSTREAM, SYNC_BIDIRECTIONAL]:
elif pc is None and sync_mode in [SYNC_UPSTREAM, SYNC_BIDIRECTIONAL]:
body = Program(
id="",
org_id="",
Expand All @@ -246,13 +246,13 @@ def sync_programs(self, api_instance, syncmode):
pl["org_id"] = api_response.body["org_id"]
ProgramEngine.get_instance().save(program.Program.from_dict(pl))
logging.info("programs.create.upstream: " + pl.get("name"))
elif pc is None and syncmode in [SYNC_DOWNSTREAM]:
elif pc is None and sync_mode in [SYNC_DOWNSTREAM]:
ProgramEngine.get_instance().delete(pl.get("name"))
logging.info("programs.delete.downstream: " + pl.get("name"))

# manage programs not present locally in "active" status
for k, pc in p_c_m.items():
if p_l_m.get(k) is None and syncmode in [SYNC_DOWNSTREAM, SYNC_BIDIRECTIONAL]:
if p_l_m.get(k) is None and sync_mode in [SYNC_DOWNSTREAM, SYNC_BIDIRECTIONAL]:
pl = program.Program(name=pc.get("name"),
code=pc.get("code"),
dom_code=pc.get("dom_code"),
Expand Down