1st push
This commit is contained in:
140
app/testapp/runtests.jl
Normal file
140
app/testapp/runtests.jl
Normal file
@@ -0,0 +1,140 @@
|
||||
# ---------------------------------------------- 100 --------------------------------------------- #
|
||||
using JSON3, MQTTClient, Dates, UUIDs, PrettyPrinting, LibPQ, Base64, DataFrames
|
||||
using GeneralUtils
|
||||
|
||||
config = copy(JSON3.read("config.json"))
|
||||
|
||||
msgMeta = GeneralUtils.generate_msgMeta(
|
||||
"/yiem_branch_1/agent/wine/backend/db/api/v1/testing";
|
||||
senderName = "wine_assistant_admin",
|
||||
senderId= string(uuid4()),
|
||||
mqttBrokerAddress= config[:mqttServerInfo][:broker],
|
||||
mqttBrokerPort= config[:mqttServerInfo][:port],
|
||||
)
|
||||
|
||||
outgoingMsg = Dict(
|
||||
:msgMeta=> msgMeta,
|
||||
:payload=> Dict(
|
||||
:functioncall=> "search_materWineTable",
|
||||
:args=> Dict(
|
||||
:columnname=> "wine_name",
|
||||
:searchkeyword=> "Yarra",
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
raw = GeneralUtils.sendReceiveMqttMsg(outgoingMsg)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sql =
|
||||
"""
|
||||
SELECT * FROM wine WHERE wine_name ILIKE '%yarra%';
|
||||
"""
|
||||
DBconnection = LibPQ.Connection("host=192.168.88.12 port=5432 dbname=yiem_wine_assistant user=yiem password=yiem@Postgres_0.0")
|
||||
result = LibPQ.execute(DBconnection, sql)
|
||||
LibPQ.close(DBconnection)
|
||||
|
||||
a = columntable(result)
|
||||
|
||||
|
||||
|
||||
""" Convert a DataFrame into a list of JSON rows.
|
||||
|
||||
# Arguments
|
||||
- `df::DataFrame`
|
||||
The input DataFrame to be converted.
|
||||
|
||||
# Return
|
||||
- `rows::Vector{Dict{String, Any}}`
|
||||
A vector of dictionaries, where each dictionary represents a row in JSON format.
|
||||
|
||||
# Example
|
||||
```jldoctest
|
||||
julia> using DataFrame, JSON3
|
||||
julia> df = DataFrame(A = [1, 2, 3], B = ["apple", "banana", "cherry"])
|
||||
julia> json_rows = dfToJSONRows(df)
|
||||
```
|
||||
|
||||
# Signature
|
||||
"""
|
||||
function dfToJSONRows(df::DataFrame)
|
||||
rows = []
|
||||
for row in eachrow(df)
|
||||
json_row = Dict{String, Any}()
|
||||
for col in names(df)
|
||||
json_row[col] = row[col]
|
||||
end
|
||||
push!(rows, json_row)
|
||||
end
|
||||
return rows
|
||||
end
|
||||
|
||||
|
||||
open("d.json", "w") do io
|
||||
JSON3.pretty(io, result)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user