How to Convert String into bytearray(EUC-KR)? - ios

Hello There i am using swift 5.0 and developing BLE App.
As we have android app there are using default function as below
byte nByte[] = Name.getBytes( charsetName: "EUC-KR")
Output of android
Value[0] = 32 Value[1] = 30 Value[2] = 32 Value[3] =
32 Value[4] = 31 Value[5] = 31 Value[6] = 32 Value[7] = 37 Value[8] = 2d Value[9] = c3 Value[10] =
e6 Value[11] = ba Value[12] = cf Value[13] = 38 Value[14] = 30 Value[15] = c0 Value[16] = da Value[17] =
39 Value[18] = 30 Value[19] = 31 Value[20] = 35 Value[21] = 2d Value[22] = 58 Value[23] = 2d Value[24] =
30 Value[25] = 32 Value[26] = 2d Value[27] = 31 Value[28] = 32 Value[29] = 31 Value[30] = 32 Value[31] =
31 Value[32] = 32 Value[33] = 31 Value[34] = 2e Value[35] = 54 Value[36] = 58 Value[37] = 54
We used in iOS different type of string convert as below
Code 1
let rawEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(CFStringEncodings.EUC_KR.rawValue))
let encoding = String.Encoding(rawValue: rawEncoding)
let strEUCData = "20221127-충북80자9015-X-02-1212121.TXT".data(using: encoding) ?? Data()
Output of iOS
bytes : 38 elements
0 : 50
1 : 48
2 : 50
3 : 50
4 : 49
5 : 49
6 : 50
8 : 45
9 : 195
10 : 230
11 : 186
12 : 207
13 : 56
14 : 48
15 : 192
16 : 218
17 : 57
18 : 48
19 : 49
20 : 53
21 : 45
22 : 88
23 : 45
24 : 48
25 : 50
26 : 45
27 : 49
28 : 50
29 : 49
30 : 50
31 : 49
32 : 50
33 : 49
34 : 46
35 : 84
36 : 88
37 : 84
Code 2
let strEUCData1 = "20221127-충북80자9015-X-02-1212121.TXT".data(using: String.Encoding(rawValue: 0x80000940)) ?? Data()
All above functions given wrong byte array.
Any help will be appreciated.
Thank you.

They are the same data. The Android output is in Hex (base 16) number and the iOS output is in decimal (base 10) number:
Android (Hex) iOS (Decimal)
32 50
30 48
32 50
32 50
31 49
31 49
32 50
37 55
2d 45
c3 195
e6 230
ba 186
cf 207
38 56
30 48
c0 192
da 218
39 57
30 48
31 49
35 53
2d 45
58 88
2d 45
30 48
32 50
2d 45
31 49
32 50
31 49
32 50
31 49
32 50
31 49
2e 46
54 84
58 88
54 84

Related

Calculating the most frequent pairs in a dataset

Is it possible to calculate most frequent pairs from a combinations of pairs in a dataset with five columns?
I can do this with a macro in excel, I'd be curious to see if there's a simple solution for this in google sheets.
I have a sample data and results page here :
Data:
B1 B2 B3 B4 B5
6 22 28 32 36
7 10 17 31 35
8 33 38 40 42
10 17 36 40 41
8 10 17 36 54
9 30 32 51 55
1 4 16 26 35
12 28 30 40 43
42 45 47 49 52
10 17 30 31 47
10 17 33 51 58
4 10 17 30 32
2 35 36 37 43
6 10 17 38 55
3 10 17 25 32
Results would be like:
Value1 Value2 Frequency
10 17 8
10 31 2
17 31 2
10 36 2
17 36 2
30 32 2
10 30 2
17 30 2
10 32 2
17 32 2
etc
Each row represents a data set. The pairs don't have to be adjoining. There can be numbers between them.
Create a combination of pairs for each row using the method mentioned here. Then REDUCE all the pairs to create a virtual 2D array. Then use QUERY to group and find the count:
=QUERY(
REDUCE(
{"",""},
A2:A16,
LAMBDA(acc,cur,
{
acc;
QUERY(
LAMBDA(mrg,
REDUCE(
{"",""},
SEQUENCE(COLUMNS(mrg)-1,1,0),
LAMBDA(a_,c_,
{
a_;
LAMBDA(rg,
REDUCE(
{"",""},
OFFSET(rg,0,1,1,COLUMNS(rg)-1),
LAMBDA(a,c,{a;{INDEX(rg,1),c}})
)
)(OFFSET(mrg,0,c_,1,COLUMNS(mrg)-c_))
}
)
)
)(OFFSET(cur,0,0,1,5)),
"where Col1 is not null",0
)
}
)
),
"Select Col1,Col2, count(Col1) group by Col1,Col2 order by count(Col1) desc "
)
Input:
B1(A1)
B2
B3
B4
B5
6
22
28
32
36
7
10
17
31
35
8
33
38
40
42
10
17
36
40
41
8
10
17
36
54
9
30
32
51
55
1
4
16
26
35
12
28
30
40
43
42
45
47
49
52
10
17
30
31
47
10
17
33
51
58
4
10
17
30
32
2
35
36
37
43
6
10
17
38
55
3
10
17
25
32
Output(partial):
count
10
17
8
10
30
2
10
31
2
10
32
2
10
36
2
17
30
2
17
31
2
17
32
2
17
36
2
30
32
2
1
4
1
1
16
1
1
26
1
1
35
1
2
35
1
2
36
1
2
37
1
2
43
1
3
10
1
3
17
1
3
25
1

Export datas from mongodb using mongoexport from a specific time range with query and timestamp

I'm trying to export a collection from mongodb using mongoexport. This works so far:
mongoexport.exe --db dataloggin --collection p1 --out myRecords.json
The problem is that the file is huge and I can not open it anymore (araound 20GB, 30 days, every half a second a document).
I just need the data between the 3. March and the 5 March, so I tried to select this date range with the query selector as following:
mongoexport.exe --db dataloggin --collection p1 -q='{"timestamp":{"$gte":{"$timestamp":"2016-03-3T00:00:00.000Z"}:},"timestamp":{"$lt":{"$timestamp":"2016-03-05T00:00:00.000Z"}}}' --out myRecords.json
But I get an error:
error validating settings: query '[39 123 116 105 109 101 115 116 97 109 112 58 123 36 103 116 101 58 123 36 116 105 109 101 115 116 97 109 112 58 50 48 49 54 45 48 49 45 48 49 84 48 48 58 48 48 58 48 48 46 48 48 48 90 125 58 125 44 116 105 109 101 115 116 97 109 112 58 123 36 108 116 58 123 36 116 105 109 101 115 116 97 109 112 58 50 48 49 54 45 48 49 45 48 49 84 48 48 58 48 48 58 48 48 46 48 48 48 90 125 125 125 39]' is not valid JSON: json: cannot unmarshal string into Go value of type map[string]interface {}
Someone have an idea?
Many Thanks and regards

How to overcome with this error when using Networkx's kernighan_lin_bisection

I want to use kernighan_lin_bisection from Networkx to separate a network data.
But the error below showed up and I'm stuck.
It would be highly appreciated if you could help me overcome this error.
QT-------------------------------------------------------------------------
IndexError Traceback (most recent call last)
in ()
17 for c in init_partition:
18 for n in c:
---> 19 color_map_i[n]=colors[counter]
20 counter=counter+1
21
IndexError: list assignment index out of range
UNQT---------------------------------------------------------------------------
The coding I used and data source"200224_04_act.prn" are below.
QT---------------------------------------------------
G=nx.read_edgelist("200224_04_act.prn",nodetype=int)
colors=["red","blue","green"]
pos=nx.spring_layout(G)
init_nodes=np.array_split(G.nodes(),2)
init_partition=[set(init_nodes[0]),set(init_nodes[1])]
print(init_partition)
from networkx.algorithms.community import kernighan_lin_bisection
color_map_i=["black"]*nx.number_of_nodes(G)
print(color_map_i)
counter=0
for c in init_partition:
for n in c:
color_map_i[n]=colors[counter]
counter=counter+1
print(color_map_i)
nx.draw_networkx_edges(G,pos)
nx.draw_networkx_nodes(G,pos,node_color=color_map_i)
nx.draw_networkx_labels(G,pos)
plt.axis("off")
plt.show()
lst_b=kernighan_lin_bisection(G,partition=init_partition)
color_map_b=["black"]*nx.number_of_nodes(G)
counter=0
for c in lst_b:
for n in c:
color_map_b[n]=colors[counter]
counter=counter+1
nx.draw_networkx_edges(G,pos)
nx.draw_networkx_nodes(G,pos,node_color=color_map_b)
nx.draw_networkx_labels(G,pos)
plt.axis("off")
plt.show()
UNQT--------------------------------------------------------------
"200224_04_act.prn" below.(Number of nodes is around 2000 but I made it
small due to the limit of number of character)
1 415
2 415
3 415
3 1350
4 1351
5 1352
6 383
7 993
8 1353
9 887
10 887
11 887
12 887
13 887
14 1185
15 1185
16 1185
17 1185
18 1185
19 1146
20 1146
21 1146
22 1146
21 776
23 776
24 707
25 707
26 707
27 707
28 707
29 754
21 754
30 754
31 754
32 754
33 778
34 778
35 778
36 778
37 778
38 859
39 859
40 1354
41 563
42 563
43 563
44 563
45 563
46 1209
47 1209
48 1209
49 1209
50 1209
51 715
52 715
53 715
54 715
55 715
56 1048
57 1048
58 1047
59 1047
60 1047
61 1047
62 1047
63 718
64 718
65 718
66 718
67 718
68 947
17 947
69 947
70 889
71 744
72 744
73 744
74 744
75 744
76 1137
77 1137
78 1137
79 1137
80 612
81 612
82 612
83 612
17 612
84 790
85 790
86 790
87 790
88 790
89 922
90 922
91 922
92 922
93 922
21 738
94 738
95 738
96 738
97 738
98 1355
81 807
99 807
17 807
100 725
101 725
17 725
102 725
103 725
23 1046
104 661
105 661
106 661
107 661
108 661
109 907
110 907
111 907
112 907
113 907
114 840
115 840
116 840
117 840
17 840
118 759
23 759
119 759
23 761
120 761
121 761
122 761
123 1356
124 1265
125 1265
126 1265
127 1265
128 1265
129 894
29 894
130 894
131 894
132 667
133 667
124 758
134 758
135 758
122 758
136 758
137 471
138 471
You've got
for c in init_partition:
for n in c:
color_map_i[n]=colors[counter]
counter=counter+1
It looks to me like n will loop over all of the nodes of the graph. I do not see any entries in the graph that are 0. So probably the nodes are numbered 1 to N, while color_map_i is indexed from 0 to N-1. So it would break when n=N.
A good way to hunt for bugs like this in general would be to print n right before the line giving the error. This would give a hint to what the problem is.

parsing using awk

how to parse a file based on data from another file using awk.
i made a script:
BEGIN{ FS="\t" ; OFS="\t"
while((getline<"headfpkm")>0) {
++a
id[a]=$1
fpkm[a]=$2
print id[a],fpkm[a]
}
lastid=id[a]
print lastid
close("headfpkm")
}
/$lastid/{
print $2,$3,$5,$7,$8,$14,fpkm[a]
a--
lastid=id[a]
}
END{ print "total lines=",FNR,"\n\nfile 1 index: ",a}
when i run it :
/$ awk -f testawk.awk file2
it runs the BEGIN section properly but doesnt give any output.
NM_000014 5.04503
NM_000015 0.586677
NM_000016 1.138332278
NM_000017 0.64386
NM_000018 3.61746
NM_000019 2.8793
NM_000020 10.846
NM_000021 0.685098
NM_000022 46388.6
NM_000026 0.257471
NM_000026
total lines= 10
file 1 index: 10
Is anything wrong with the searching section??
file 2 looks like this:
34 ACADM NM_000016 9606 hsa-miR-3148 3 80 87 0.003 -0.016 -0.094 0.082 0.112 -0.160 97
34 ACADM NM_000016 9606 hsa-miR-3163 1 623 629 0.001 -0.022 -0.020 0.065 0.125 -0.01 57
35 ACADS NM_000017 9606 hsa-miR-3921 3 68 75 0.013 0.192 -0.097 0.031 -0.039 -0.147 82
35 ACADS NM_000017 9606 hsa-miR-4303 2 67 73 0.012 0.150 -0.052 0.013 -0.039 -0.036 31
35 ACADS NM_000017 9606 hsa-miR-4653-5p 3 68 75 0.003 0.192 -0.097 0.031 -0.039 -0.157 84
37 ACADVL NM_000018 9606 hsa-miR-124 2 31 37 0.003 0.023 -0.057 0.012 -0.032 -0.171 76
37 ACADVL NM_000018 9606 hsa-miR-1827 2 135 141 -0.007 -0.043 -0.058 0.039 -0.069 -0.258 91
37 ACADVL NM_000018 9606 hsa-miR-2682 2 134 140 0.003 -0.014 -0.058 0.004 -0.047 -0.232 87
37 ACADVL NM_000018 9606 hsa-miR-449c 2 134 140 -0.035 -0.014 -0.058 0.004 -0.047 -0.270 92
37 ACADVL NM_000018 9606 hsa-miR-506 2 31 37 -0.016 0.023 -0.057 0.012 -0.032 -0.190 80
This is going to be a bit of guess, because I'm not 100% sure as to what you're trying to accomplish. The better way to solve your problem, would be to do something like this:
BEGIN {
FS=OFS="\t"
}
FNR==NR {
c++
a[$1]=$2
next
}
$3 in a {
print $2,$3,$5,$7,$8,$14,a[$3]
}
END {
printf "total lines=%s\n\nfile 1 index: %s\n", FNR, c
}
Run like:
awk -f script.awk headfpkm file2
Results:
ACADM NM_000016 hsa-miR-3148 80 87 -0.160 1.138332278
ACADM NM_000016 hsa-miR-3163 623 629 -0.01 1.138332278
ACADS NM_000017 hsa-miR-3921 68 75 -0.147 0.64386
ACADS NM_000017 hsa-miR-4303 67 73 -0.036 0.64386
ACADS NM_000017 hsa-miR-4653-5p 68 75 -0.157 0.64386
ACADVL NM_000018 hsa-miR-124 31 37 -0.171 3.61746
ACADVL NM_000018 hsa-miR-1827 135 141 -0.258 3.61746
ACADVL NM_000018 hsa-miR-2682 134 140 -0.232 3.61746
ACADVL NM_000018 hsa-miR-449c 134 140 -0.270 3.61746
ACADVL NM_000018 hsa-miR-506 31 37 -0.190 3.61746
total lines=10
file 1 index: 10

Convert PNG images to pixel gray-level values feature vectors

I am a newbie in MATLAB and I have a set of bmp images which I need to convert into pixel gray-level values as feature vectors of image. Can anyone suggest me the way how I can do that?
I need to use these pixel gray-level values as features and then perform operations like PCA/LDA.
I tried imread() but it returns me a matrix.. I feel feature vector will be just one row vector.
Regards,
imread() is the correct way to do it. Then just convert from a matrix into a vector. For example:
>> X = randi(255, 10)
X =
208 41 168 181 112 71 192 215 90 20
231 248 10 9 98 174 66 65 212 14
33 245 217 71 196 168 130 208 150 136
233 124 239 12 203 42 179 63 141 199
162 205 174 25 48 31 228 237 234 239
25 37 194 210 125 128 245 90 73 34
72 108 190 178 114 245 140 51 194 146
140 234 101 81 165 87 36 65 193 120
245 203 168 243 181 150 39 158 98 4
247 245 44 9 193 58 66 121 145 86
>> X(:)
ans =
208
231
33
233
162
25
72
140
245
247
...
Then you can just stack your different observations together with [] and do PCA.

Resources