From f3dc298ba7f619de5480523e7c659ab856247e84 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Wed, 15 Jan 2025 03:00:31 +0700 Subject: [PATCH 1/5] update version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 47e8db1..fc2b80f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GeneralUtils" uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe" authors = ["tonaerospace "] -version = "0.1.1" +version = "0.2.1-dev" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" From b51059d73ffaa1c8f019ecfe147a0b41f0955d95 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Thu, 16 Jan 2025 11:06:43 +0700 Subject: [PATCH 2/5] update --- src/util.jl | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/util.jl b/src/util.jl index bc82e30..dec607c 100644 --- a/src/util.jl +++ b/src/util.jl @@ -3,7 +3,8 @@ module util export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, replaceDictKeys, findMatchingDictKey, textToDict, randstring, randstrings, timeout, dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString, - dfToString, dataframe_to_json_list, dict_to_string, extract_triple_backtick_text, + dfToString, dataframe_to_json_list, dictToString, dictToString_noKey, + dictToString_numbering, extract_triple_backtick_text, countGivenWords, remove_french_accents, detect_keyword using JSON3, DataStructures, Distributions, Random, Dates, UUIDs, MQTTClient, DataFrames @@ -709,7 +710,15 @@ end # Signature """ -function dict_to_string(od::T) where {T<:AbstractDict} +function dictToString(od::T) where {T<:AbstractDict} + items = [] + for (i, (key, value)) in enumerate(od) + push!(items, "$key: $value") + end + return join(items, ", ") +end + +function dictToString_numbering(od::T) where {T<:AbstractDict} items = [] for (i, (key, value)) in enumerate(od) push!(items, "$i) $key: $value") @@ -717,6 +726,14 @@ function dict_to_string(od::T) where {T<:AbstractDict} return join(items, ", ") end +function dictToString_noKey(od::T) where {T<:AbstractDict} + items = [] + for (i, (key, value)) in enumerate(od) + push!(items, "$value") + end + return join(items, ", ") +end + """ extract_triple_backtick_text(text::String) -> Vector{String} From 2700e594e4988a390aa4156c570661b4d7841f59 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Mon, 20 Jan 2025 18:20:30 +0700 Subject: [PATCH 3/5] update --- src/util.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.jl b/src/util.jl index dec607c..4b3e6b8 100644 --- a/src/util.jl +++ b/src/util.jl @@ -480,7 +480,7 @@ end function dfToVectorDict(df::DataFrame) vec = [] for row in eachrow(df) - d = Dict{String, Any}() + d = DataStructures.OrderedDict{String, Any}() for col in names(df) d[col] = row[col] end From 43ead8b8d5a59ff31b5ddd08aa4480f3ca1db845 Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Sat, 25 Jan 2025 13:31:15 +0700 Subject: [PATCH 4/5] update --- src/communication.jl | 4 ++-- src/util.jl | 48 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/communication.jl b/src/communication.jl index e780f46..dd278b1 100644 --- a/src/communication.jl +++ b/src/communication.jl @@ -496,7 +496,7 @@ function sendMqttMsg(outgoingMsg::Dict{Symbol, T})::NamedTuple where {T<:Any} ) response = sendMqttMsg(mqttInstance, outgoingMsg) - disconnect(mqttInstance.client) + try disconnect(mqttInstance.client) catch end return response end @@ -576,7 +576,7 @@ function sendReceiveMqttMsg(outgoingMsg::Dict{Symbol, T}; ) response = sendReceiveMqttMsg(mqttInstance, :ch1, outgoingMsg; timeout=timeout, maxattempt=maxattempt) - disconnect(mqttInstance.client) + try disconnect(mqttInstance.client) catch end return response end diff --git a/src/util.jl b/src/util.jl index 4b3e6b8..7d977e6 100644 --- a/src/util.jl +++ b/src/util.jl @@ -5,7 +5,7 @@ export timedifference, showstracktrace, findHighestIndexKey, uuid4snakecase, rep dataframeToCSV, dfToVectorDict, disintegrate_vectorDict, getDataFrameValue, dfRowtoString, dfToString, dataframe_to_json_list, dictToString, dictToString_noKey, dictToString_numbering, extract_triple_backtick_text, - countGivenWords, remove_french_accents, detect_keyword + countGivenWords, remove_french_accents, detect_keyword, extractTextBetweenCharacter using JSON3, DataStructures, Distributions, Random, Dates, UUIDs, MQTTClient, DataFrames @@ -747,7 +747,7 @@ Extracts text enclosed within triple backticks (```) from the given string. - `Vector{String}`: A vector of strings, each representing a block of text enclosed within triple backticks found in the input string. # Examples: - ```julia + ```jldoctest julia> extract_triple_backtick_text("Here is some text ```with a code block``` and more text.") 1-element Vector{String}: "with a code block" @@ -779,7 +779,7 @@ Detects if a keyword exists in the text in different case variations (lowercase, - `Union{Nothing, String}`: Returns the matched keyword variation if found, otherwise returns nothing # Examples: - ```julia + ```jldoctest julia> detect_keyword("test", "This is a Test case") "Test" @@ -821,7 +821,7 @@ Count the occurrences of each word in the given list within the provided text. - `Vector{Int64}`: Their respective counts in the `text`. # Examples - ```julia + ```jldoctest julia> GeneralUtils.countGivenWords("hello world hello", ["hello", "world"]) 2-element Vector{Int64}: 2 @@ -863,7 +863,7 @@ Remove French accents from the given text. - `String`: The input string with all French accents removed. # Examples - ```julia + ```jldoctest julia> remove_french_accents("Café") "Cafe" @@ -907,6 +907,44 @@ function remove_french_accents(text::AbstractString)::AbstractString end +""" + extractTextBetweenCharacters(text::String, start_char::Char, end_char::Char)::String + +Extracts and returns the text that is enclosed between two specified characters within a given string. + +# Arguments: +- `text::String`: The input string from which to extract the text. +- `startchar::Char`: The starting character that marks the beginning of the desired text. +- `endchar::Char`: The ending character that marks the end of the desired text. + +# Returns: +- `String`: The substring enclosed between `start_char` and `end_char`. + +# Examples: +```jldoctest + julia> text = "Hello [World]!" + julia> extracted_text = extractTextBetweenCharacter(text, '[', ']') + println(extracted_text) # Output: "World" +""" +function extractTextBetweenCharacter(text::String, startchar::Char, endchar::Char) + result = [] + start_index = 0 + in_braces = false + + for (i, c) in enumerate(text) + if c == startchar + start_index = i + 1 + in_braces = true + elseif c == endchar + if in_braces + push!(result, text[start_index:i-1]) + in_braces = false + end + end + end + + return result +end From 00d2173f269e87f11103dbfa43dfa48dc5200c5d Mon Sep 17 00:00:00 2001 From: narawat lamaiin Date: Sat, 25 Jan 2025 14:21:45 +0700 Subject: [PATCH 5/5] update --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index fc2b80f..9234e35 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GeneralUtils" uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe" authors = ["tonaerospace "] -version = "0.2.1-dev" +version = "0.2.1" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"