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

Ml old #10

Open
wants to merge 173 commits into
base: main-old
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
f65b17d
Edited 'main.py'
Sep 19, 2023
92c8f2e
Update deployment ShakeDetection
Sep 19, 2023
89f22b3
Edited 'main.py'
Sep 19, 2023
d701b19
Edited 'main.py'
Sep 19, 2023
ddde762
Edited 'main.py'
Sep 19, 2023
d2e5995
Edited 'main.py'
Sep 19, 2023
0ca602d
Edited 'main.py'
Sep 19, 2023
8679189
Edited 'main.py'
Sep 19, 2023
2311f49
Edited 'main.py'
Sep 19, 2023
7466371
Edited 'main.py'
Sep 19, 2023
047ed42
Edited 'main.py'
Sep 19, 2023
8808cfb
Edited 'main.py'
Sep 19, 2023
a5954dc
Edited 'main.py'
Sep 19, 2023
a2e28df
Edited 'main.py'
Sep 19, 2023
367d25a
Edited 'main.py'
Sep 19, 2023
de6da2e
Edited 'main.py'
Sep 19, 2023
c238091
Edited 'main.py'
Sep 19, 2023
5b06b07
Update deployment Fleet console
Sep 19, 2023
6b7ee9a
Update deployment ShakeDetection
Sep 19, 2023
e32fedc
Update deployment ShakeDetection
Sep 19, 2023
8b87581
Update deployment ShakeDetection
Sep 19, 2023
cbad6d5
Merge branch 'main-old' into ml-old
tomas-quix Sep 19, 2023
3782ca3
Update deployment ShakeDetection
Sep 19, 2023
66f0551
Merge remote-tracking branch 'refs/remotes/origin/ml-old'
Sep 19, 2023
b1d8b68
Edited 'main.py'
Sep 19, 2023
7db37da
Update deployment ShakeDetection
Sep 19, 2023
f209b90
Update deployment ShakeDetection
Sep 19, 2023
72ceb61
Update deployment ShakeDetection
Sep 19, 2023
db28ce3
Edited 'requirements.txt'
Sep 19, 2023
4d04426
Update deployment ShakeDetection
Sep 19, 2023
e5eec5e
Edited 'dockerfile'
Sep 19, 2023
085794a
Update deployment ShakeDetection
Sep 19, 2023
747609f
Merge remote-tracking branch 'refs/remotes/origin/ml-old'
Sep 19, 2023
4058ffb
Update deployment ShakeDetection
Sep 19, 2023
2916457
Update deployment ShakeDetection
stereosky Sep 21, 2023
67895eb
Update deployment ShakeDetection
stereosky Sep 21, 2023
cece0cb
Edited 'main.py'
Sep 28, 2023
b4a1ba9
Edited 'main.py'
Sep 28, 2023
f7e5c75
Edited 'main.py'
Sep 28, 2023
712c185
Edited 'main.py'
Sep 28, 2023
74f1fa0
Edited 'main.py'
Sep 28, 2023
819fa5d
Edited 'main.py'
Sep 28, 2023
5f8ec4e
Edited 'main.py'
Sep 28, 2023
875bd21
Edited 'main.py'
Sep 28, 2023
57c54be
'ShakeDetection/app.yaml' edited via Quix Portal
Sep 28, 2023
6338810
'ShakeDetection/app.yaml' edited via Quix Portal
Sep 28, 2023
c2d6521
'ShakeDetection/app.yaml' edited via Quix Portal
Sep 28, 2023
91f1eb9
'ShakeDetection/app.yaml' edited via Quix Portal
Sep 29, 2023
3797072
Edited 'main.py'
Sep 29, 2023
ab69008
Edited 'main.py'
Sep 29, 2023
0211723
'ShakeDetection/app.yaml' edited via Quix Portal
Oct 2, 2023
f33eef7
'ShakeDetection/app.yaml' edited via Quix Portal
Oct 2, 2023
31eb3d0
Edited 'main.py'
Oct 2, 2023
96a8937
Edited 'main.py'
Oct 2, 2023
8fa9444
Edited 'main.py'
Oct 2, 2023
530d8d6
Edited 'main.py'
Oct 2, 2023
7d2084b
Edited 'main.py'
Oct 2, 2023
f75c7b3
Update deployment QR Settings Share
stereosky Oct 26, 2023
773b31a
Update deployment Fleet console
stereosky Oct 26, 2023
598e2fa
Update deployment ShakeDetection
stereosky Oct 26, 2023
3a27f95
Upload 'quix_streamingdataframes-0.0.1a1-py3-none-any (2).whl'
Nov 1, 2023
f7d6e78
Rename 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
8ca0b86
Edited 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
88602bb
Edited 'requirements.txt'
Nov 1, 2023
faf8fe8
Edited 'requirements.txt'
Nov 1, 2023
8065c11
Edited 'main.py'
Nov 1, 2023
8450a9e
Edited 'main.py'
Nov 1, 2023
f339215
Edited 'requirements.txt'
Nov 1, 2023
e569da7
Upload 'quix_streamingdataframes-0.0.1a1-py3-none-any (3).whl'
Nov 1, 2023
5975dd5
Delete 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
3f60cbb
Rename 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
56d598c
Edited 'requirements.txt'
Nov 1, 2023
dc6b077
Edited 'requirements.txt'
Nov 1, 2023
b80456e
Upload 'quix_streamingdataframes-0.0.1a1-py3-none-any (4).whl'
Nov 1, 2023
34d1de5
Delete 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
fefdc6f
Rename 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
b83a903
Edited 'requirements.txt'
Nov 1, 2023
afd4f83
Delete 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
62118d9
Upload 'quix_streamingdataframes-0.0.1a1-py3-none-any (4).whl'
Nov 1, 2023
a773b91
Rename 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 1, 2023
d97a143
'ShakeDetection/app.yaml' edited via Quix Portal
Nov 1, 2023
48e81f5
Edited 'main.py'
Nov 1, 2023
9b2b452
Edited 'main.py'
Nov 1, 2023
cbc23c8
Edited 'main.py'
Nov 1, 2023
f15a387
Edited 'main.py'
Nov 1, 2023
dacc63f
Edited 'main.py'
Nov 1, 2023
01c384e
Edited 'main.py'
Nov 1, 2023
bc76342
Edited 'main.py'
Nov 1, 2023
964bc52
Edited 'main.py'
Nov 1, 2023
d17eedb
Edited 'main.py'
Nov 1, 2023
e1d5fe4
Edited 'main.py'
Nov 1, 2023
5af0dbb
Edited 'main.py'
Nov 1, 2023
3b29fa9
Edited 'main.py'
Nov 1, 2023
d39f5c5
Edited 'main.py'
Nov 1, 2023
8430c78
Edited 'main.py'
Nov 1, 2023
e9db1d4
Edited 'main.py'
Nov 1, 2023
251cade
Edited 'main.py'
Nov 1, 2023
bbfc9ae
Edited 'main.py'
Nov 1, 2023
e8b6094
Edited 'main.py'
Nov 1, 2023
980c8fd
Edited 'main.py'
Nov 1, 2023
e5c249c
'ShakeDetection/app.yaml' edited via Quix Portal
Nov 1, 2023
83a2748
Edited 'main.py'
Nov 1, 2023
4533510
Edited 'main.py'
Nov 1, 2023
c03c404
Edited 'requirements.txt'
Nov 1, 2023
597b223
Edited 'main.py'
Nov 1, 2023
706c24f
Edited 'main.py'
Nov 1, 2023
17dbbf3
Edited 'main.py'
Nov 1, 2023
2a7d72a
Edited 'main.py'
Nov 1, 2023
0cc3041
Edited 'main.py'
Nov 1, 2023
076b6b5
Edited 'main.py'
Nov 1, 2023
43a1977
Edited 'main.py'
Nov 1, 2023
29453b2
Edited 'main.py'
Nov 1, 2023
dfa74dd
Edited 'main.py'
Nov 1, 2023
c877ce3
Edited 'main.py'
Nov 1, 2023
11af7f0
Edited 'main.py'
Nov 1, 2023
84912af
Edited 'main.py'
Nov 1, 2023
214a2cf
Edited 'main.py'
Nov 1, 2023
f0206e9
Edited 'main.py'
Nov 1, 2023
696a76a
Edited 'main.py'
Nov 1, 2023
de2d017
Edited 'main.py'
Nov 1, 2023
0758648
Edited 'main.py'
Nov 1, 2023
abcdecc
Edited 'main.py'
Nov 1, 2023
7626810
Edited 'main.py'
Nov 1, 2023
79721e0
Edited 'main.py'
Nov 1, 2023
e70b30e
Edited 'main.py'
Nov 1, 2023
fec9231
Edited 'main.py'
Nov 1, 2023
ddc508c
Edited 'main.py'
Nov 1, 2023
a93ff85
Edited 'main.py'
Nov 1, 2023
699731c
Delete 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 6, 2023
fc48eab
Upload 'quix_streamingdataframes-0.0.1a1-py3-none-any (5).whl'
Nov 6, 2023
ae87fd2
Rename 'quix_streamingdataframes-0.0.1a1-py3-none-any.whl'
Nov 6, 2023
a58109e
Edited 'requirements.txt'
Nov 6, 2023
b908ce3
Edited 'main.py'
Nov 6, 2023
d6faee0
Edited 'requirements.txt'
Nov 6, 2023
503a7f9
Edited 'requirements.txt'
Nov 6, 2023
827d00a
Edited 'main.py'
Nov 6, 2023
8229d43
Edited 'main.py'
Nov 6, 2023
705c07e
'ShakeDetection/app.yaml' edited via Quix Portal
Nov 6, 2023
2deeaf0
Edited 'main.py'
Nov 6, 2023
5b01165
Edited 'main.py'
Nov 6, 2023
9f99cde
Edited 'main.py'
Nov 6, 2023
8f54a60
Edited 'main.py'
Nov 6, 2023
d800578
Edited 'main.py'
Nov 6, 2023
054e697
'ShakeDetection/app.yaml' edited via Quix Portal
Nov 6, 2023
e9d265f
'ShakeDetection/app.yaml' edited via Quix Portal
Nov 6, 2023
95c07c1
Edited 'main.py'
Nov 6, 2023
bcb7758
Edited 'main.py'
Nov 6, 2023
697b6f9
Edited 'main.py'
Nov 6, 2023
cad1e40
Edited 'main.py'
Nov 6, 2023
0e090df
Edited 'main.py'
Nov 6, 2023
fc9e4ea
Edited 'main.py'
Nov 6, 2023
90c73af
Edited 'main.py'
Nov 6, 2023
46ef3e4
Edited 'main.py'
Nov 6, 2023
fb070c5
Edited 'main.py'
Nov 6, 2023
cfef77e
Edited 'main.py'
Nov 6, 2023
ae1321b
Edited 'main.py'
Nov 6, 2023
3a68529
Edited 'main.py'
Nov 6, 2023
6e991a6
Edited 'main.py'
Nov 6, 2023
fbd105b
Edited 'main.py'
Nov 6, 2023
296fa49
Edited 'main.py'
Nov 6, 2023
5719181
Edited 'main.py'
Nov 6, 2023
027532c
Edited 'main.py'
Nov 6, 2023
8e98ed0
Edited 'main.py'
Nov 6, 2023
1b6e478
Edited 'main.py'
Nov 6, 2023
fbebcc2
Edited 'main.py'
Nov 6, 2023
66004e5
Edited 'main.py'
Nov 6, 2023
610c61e
Edited 'main.py'
Nov 6, 2023
5f7b769
Edited 'main.py'
Nov 6, 2023
cdef8da
Edited 'main.py'
Nov 6, 2023
a7d1e36
Edited 'main.py'
Nov 6, 2023
9e77e42
Edited 'requirements.txt'
Nov 6, 2023
178b07b
Edited 'requirements.txt'
Nov 6, 2023
2229977
Edited 'main.py'
Nov 6, 2023
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
7 changes: 6 additions & 1 deletion ShakeDetection/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ variables:
- name: input
inputType: InputTopic
description: Name of the input topic to listen to.
defaultValue: phone-data
defaultValue: gforce
required: true
- name: output
inputType: OutputTopic
description: Name of the output topic to write to.
defaultValue: events
required: true
- name: model
inputType: FreeText
description: ''
defaultValue: XGB_model_v1.8.pkl
required: true
dockerfile: build/dockerfile
runEntryPoint: main.py
defaultFile: main.py
2 changes: 2 additions & 0 deletions ShakeDetection/build/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ ENV PYTHONIOENCODING=UTF-8

WORKDIR /app
COPY --from=git /project .
RUN apt-get update
RUN apt-get install -y libgomp1
RUN find | grep requirements.txt | xargs -I '{}' python3 -m pip install -i http://pip-cache.pip-cache.svc.cluster.local/simple --trusted-host pip-cache.pip-cache.svc.cluster.local -r '{}' --extra-index-url https://pypi.org/simple --extra-index-url https://pkgs.dev.azure.com/quix-analytics/53f7fe95-59fe-4307-b479-2473b96de6d1/_packaging/public/pypi/simple/
ENTRYPOINT ["python3", "main.py"]
64 changes: 43 additions & 21 deletions ShakeDetection/main.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,66 @@
import quixstreams as qx
from sdk.stream_reader_new import StreamReaderNew
from sdk.stream_writer_new import StreamWriterNew
import os
from streamingdataframes import Application, MessageContext, State
from streamingdataframes.models.rows import Row
from streamingdataframes.models.serializers import (
QuixTimeseriesSerializer,
QuixDeserializer,
JSONDeserializer
)

from azure.storage.blob import BlobClient
import pickle
import pandas as pd

client = qx.QuixStreamingClient()

print("Opening input and output topics")
model = os.environ["model"]
blob = BlobClient.from_connection_string(
"DefaultEndpointsProtocol=https;AccountName=quixmodelregistry;AccountKey=9OkHZOhAW+1vtwWjReLKLQ8zyPzB0lDjaxjpTvIxaCrrlfe5rBehIc2NexmrrlyZoyUokfxlBkuaLUVUpoUoBQ==;EndpointSuffix=core.windows.net",
"models",
model)

input_topic = client.get_topic_consumer(os.environ["input"], "v3.4", auto_offset_reset=qx.AutoOffsetReset.Latest)
output_topic = client.get_topic_producer(os.environ["output"])
with open(model, "wb+") as my_blob:
blob_data = blob.download_blob()
blob_data.readinto(my_blob)

def predict(value: dict, ctx):
data_df = pd.DataFrame([{'gForceZ': value["gForceZ"], 'gForceY': value["gForceY"], 'gForceX': value["gForceX"], 'gForceTotal': value["gForceTotal"]}])
value["shaking"] = int(loaded_model.predict(data_df)[0])

def on_dataframe_received(stream_consumer: qx.StreamConsumer, df: pd.DataFrame):

if "gForceX" in df:
df["gForceTotal"] = df["gForceX"].abs() + df["gForceY"].abs() + df["gForceZ"].abs()
df["shaking"] = df["gForceTotal"].apply(lambda x: 1 if x > 15 else 0)
print("Loaded")

print(df[["gForceTotal", "shaking"]])
loaded_model = pickle.load(open(model, 'rb'))

output_topic.get_or_create_stream(stream_consumer.stream_id).timeseries.publish(df)

# Quix app does not require the broker being defined
app = Application.Quix("big-query-sink-v5", auto_offset_reset="latest", )
input_topic = app.topic(os.environ["input"], value_deserializer=QuixDeserializer())
output_topic = app.topic(os.environ["output"], value_serializer=QuixTimeseriesSerializer())

# Hook up to termination signal (for docker image) and CTRL-C

def on_stream_received(stream_consumer: qx.StreamConsumer):
print("New stream: " + stream_consumer.stream_id)

stream_consumer.timeseries.on_dataframe_received = on_dataframe_received

# "Gold" members get realtime notifications about purchase events larger than $1000
sdf = app.dataframe(input_topic)
sdf = sdf[["Timestamp", "gForceX", "gForceY", "gForceZ"]]

sdf["gForceTotal"] = sdf["gForceX"].abs() + sdf["gForceY"].abs() + sdf["gForceZ"].abs()

sdf["shaking"] = sdf["gForceTotal"] > 15


def gForceTotalSum(row: dict, ctx, state: State):
state_value = state.get("sum-1", 0.0)
state_value += row["gForceTotal"]
state.set("sum-1", state_value)
row["sum"] = state_value

sdf = sdf.apply(gForceTotalSum, stateful=True)

sdf.apply(predict)

input_topic.on_stream_received = on_stream_received
sdf.apply(lambda row,ctx: print(row)) # easy way to print out

sdf.to_topic(output_topic)

print("Listening to streams. Press CTRL-C to exit.")
qx.App.run()
app.run(sdf)
Binary file not shown.
6 changes: 5 additions & 1 deletion ShakeDetection/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
quixstreams==0.5.5
azure-storage-blob
xgboost==0.90
scikit-learn
pandas
./quix_streamingdataframes-0.0.1a1-py3-none-any.whl
10 changes: 5 additions & 5 deletions quix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ deployments:
publicAccess:
enabled: true
urlPrefix: qr-settings-share
desiredStatus: Running
desiredStatus: Stopped
variables:
- name: BearerToken
inputType: Secret
description: ''
required: true
value: qr_bearer_token
secretKey: qr_bearer_token
- name: Fleet console
application: FleetConsole
deploymentType: Service
Expand All @@ -35,7 +35,7 @@ deployments:
publicAccess:
enabled: true
urlPrefix: fleetconsole
desiredStatus: Running
desiredStatus: Stopped
variables:
- name: topic
inputType: FreeText
Expand All @@ -50,12 +50,12 @@ deployments:
- name: ShakeDetection
application: ShakeDetection
deploymentType: Service
version: shake-fn-old
version: a27c23e3aa0a39d7081d0eb5ecece6c5fe0169b7
resources:
cpu: 1000
memory: 2000
replicas: 1
desiredStatus: Running
desiredStatus: Stopped
variables:
- name: input
inputType: InputTopic
Expand Down