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

AllSkyAI - Additonal options #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions allsky_ai/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ The module contains the following options
```

### Release info
### V.1.0.5
* Added disable upload option
* Added Upload Frequency Option
* A default ExtraData file is saved for overlay variables consitency

### V.1.0.4
* BRG to RGB while reading from `s.image`

Expand Down
79 changes: 66 additions & 13 deletions allsky_ai/allsky_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
import requests
import time


# Disable Numpy warnings
np.seterr(all="ignore")

metaData = {
"name": "AllSkyAI",
"description": "Classify the current sky with ML. More info https://www.allskyai.com",
"module": "allsky_ai",
"version": "v1.0.4",
"version": "v1.0.5",
"events": [
"day",
"night"
Expand All @@ -37,7 +38,9 @@
"use_account": "False",
"account_auto_update": "False",
"allsky_id": "",
"access_token": ""
"access_token": "",
"disable_upload": "False",
"upload_frequency": "600"
},
"argumentdetails": {
"auto_update": {
Expand All @@ -63,7 +66,7 @@
"contribute": {
"required": "false",
"description": "Contribute",
"help": "Contribute by uploading an image every 10th minute. This will be used to build a better generic model for everyone!",
"help": "Contribute by uploading an image every 10th minute. This will be used to build a better generic model for everyone! * Only applicable unless you have an account",
"tab": "Contribute",
"type": {
"fieldtype": "checkbox"
Expand Down Expand Up @@ -98,6 +101,27 @@
"description": "Access Code",
"help": "Access code, also found on AllSkyAI website",
"tab": "AllSkyAI"
},
"disable_upload": {
"required": "false",
"description": "Disable Upload",
"help": "Will turn upload off",
"tab": "AllSkyAI",
"type": {
"fieldtype": "checkbox"
}
},
"upload_frequency" : {
"required": "true",
"description": "Upload Frequency",
"help": "How often should an image be uploaded",
"tab": "AllSkyAI",
"type": {
"fieldtype": "spinner",
"min": 10,
"max": 6000,
"step": 1
}
}
},
"enabled": "false"
Expand Down Expand Up @@ -246,7 +270,14 @@ def do_classification(camera_type=None):

return data_json


def empty_json():
data_json = dict()
data_json['AI_CLASSIFICATION'] = "None"
data_json['AI_CONFIDENCE'] = 0.00
data_json['AI_UTC'] = "None"
data_json['AI_INFERENCE'] = 0.00

return data_json
# -------------------------------------------------------------------------------------
# API Functions
# -------------------------------------------------------------------------------------
Expand Down Expand Up @@ -390,16 +421,28 @@ def current_milli_time():
return round(time.time() * 1000)


def check_time_elapsed(allsky_id, access_token):
if time.time() - (s.dbGet("allskyai_last_publish") / 1000) > 600:
s.log(1, f"Uploading image to AllSkyAI")
def check_time_elapsed(allsky_id, access_token, upload_frequency, disable_upload):
if disable_upload:
s.log(1, f"AllSkyAI - Upload disabled")
return

elif time.time() - (s.dbGet("allskyai_last_publish") / 1000) > upload_frequency:
s.log(1, f"AllSkyAI - Uploading image")
upload_image(allsky_id, access_token)
s.dbUpdate("allskyai_last_publish", current_milli_time())


# -------------------------------------------------------------------------------------

def run(camera_type, contribute, auto_update, use_account, account_auto_update, allsky_id, access_token):
def run(camera_type,
contribute,
auto_update,
use_account,
account_auto_update,
allsky_id,
access_token,
disable_upload,
upload_frequency
):
if use_account:
s.log(1, "Using AllSkyAI account")
if not allsky_id:
Expand All @@ -420,19 +463,23 @@ def run(camera_type, contribute, auto_update, use_account, account_auto_update,
if bool(result):
s.saveExtraData("allskyai.json", result)
s.log(1, f"AllSkyAI: {json.dumps(result)}")
else:
result = empty_json()
s.saveExtraData("allskyai.json", result)
s.log(1, f"AllSkyAI: {json.dumps(result)}")

# Check elapsed time. We will only upload an image every 10 minutes
if use_account:
if not s.dbHasKey("allskyai_last_publish"):
s.dbAdd("allskyai_last_publish", current_milli_time())
else:
check_time_elapsed(allsky_id=allsky_id, access_token=access_token)
check_time_elapsed(allsky_id=allsky_id, access_token=access_token, upload_frequency=upload_frequency, disable_upload=disable_upload)

elif contribute:
if not s.dbHasKey("allskyai_last_publish"):
s.dbAdd("allskyai_last_publish", current_milli_time())
else:
check_time_elapsed(allsky_id=allsky_id, access_token=access_token)
check_time_elapsed(allsky_id=allsky_id, access_token=access_token, upload_frequency=600, disable_upload=False)


# -------------------------------------------------------------------------------------
Expand All @@ -446,6 +493,8 @@ def ai(params, event):
account_auto_update = params["account_auto_update"]
allsky_id = params["allsky_id"]
access_token = params["access_token"]
disable_upload = params["disable_upload"]
upload_frequency = int(params["upload_frequency"])

if camera_type == "none":
s.log(0, "ERROR: Camera type not set, check AllSkyAI settings...")
Expand All @@ -459,7 +508,9 @@ def ai(params, event):
use_account=use_account,
account_auto_update=account_auto_update,
allsky_id=allsky_id,
access_token=access_token
access_token=access_token,
disable_upload=disable_upload,
upload_frequency=upload_frequency
)
elif s.TOD == "night":
run(camera_type=camera_type,
Expand All @@ -468,7 +519,9 @@ def ai(params, event):
use_account=use_account,
account_auto_update=account_auto_update,
allsky_id=allsky_id,
access_token=access_token
access_token=access_token,
disable_upload=disable_upload,
upload_frequency=upload_frequency
)

return "AllSkyAI executed!"
Expand Down