Ouf, mon tri de table fonctionne enfin, non seulement mon import de csv fonctionne bien, mais maintenant je consomme très très peu de RAM pour charger tout le fichier
This commit is contained in:
125
Tests/a_tst_sort.lua
Normal file
125
Tests/a_tst_sort.lua
Normal file
@@ -0,0 +1,125 @@
|
||||
-- Scripts pour tester le tri (sort) d'un tableau d'adresse MAC en fonction du signal de réception
|
||||
-- pour les tests on charge un fichier CSV de d'adresse MAC sniffées précédemment
|
||||
-- source: https://wxlua.developpez.com/tutoriels/lua/general/cours-complet/#L6-f
|
||||
-- source: https://wxlua.developpez.com/tutoriels/lua/general/cours-complet/#L13-g
|
||||
|
||||
print("\n a_tst_sort.lua zf190209.2014 \n")
|
||||
|
||||
zmac_adrs={}
|
||||
zmac_adrs_index={}
|
||||
|
||||
|
||||
|
||||
function zshow()
|
||||
for i=1, #zmac_adrs do
|
||||
print(i,zmac_adrs[i])
|
||||
zindex, zadrs, zname, zrssi, ztime = zmac_adrs[i]:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)")
|
||||
print("toto",zindex, zadrs, zname, zrssi, ztime, "tutu")
|
||||
end
|
||||
end
|
||||
|
||||
function zload_tableau()
|
||||
filename="tst_sniffer_wifi1.csv"
|
||||
if file.open(filename, "r") then
|
||||
repeat
|
||||
local line=file.read('\n')
|
||||
if line then
|
||||
-- print("line: "..line)
|
||||
local zfield = {} local zpart=""
|
||||
for zpart in line:gmatch("[^,]+") do
|
||||
zfield[#zfield+1] = zpart
|
||||
end
|
||||
zmac_adrs[#zmac_adrs+1]=line:sub(1, -2)
|
||||
-- zmac_adrs_index[zfield[2]]=#zmac_adrs
|
||||
end
|
||||
until not line
|
||||
file.close()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--zload_tableau()
|
||||
|
||||
--print("tableau chargé") --important, c'est pour attendre que le tableau soit complètement chargé !
|
||||
--zshow()
|
||||
|
||||
|
||||
function zsort_tableau()
|
||||
print("tri du tableau")
|
||||
-- table.sort(zmac_adrs, function(a,b) return a.zrssi < b.zrssi end)
|
||||
table.sort(zmac_adrs, function(a,b)
|
||||
return a:match("[^,]+,[^,]+,[^,]+,([^,]+),[^,]+") < b:match("[^,]+,[^,]+,[^,]+,([^,]+),[^,]+")
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
function test_ram_table()
|
||||
zmac_adrs={}
|
||||
for i=1, 70 do
|
||||
print(i)
|
||||
--zmac_adrs[#zmac_adrs+1]={adrs="b8:d7:af:a6:bd:86", zname=0, zrssi=-50, ztime= 0}
|
||||
zmac_adrs[i]={adrs="b8:d7:af:a6:bd:86", zname=0, zrssi=-50, ztime= 0}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function find_adrs(zadrs)
|
||||
for i=1, #zmac_adrs do
|
||||
if zadrs == zmac_adrs[i]:match("[^,]+,([^,]+),[^,]+,[^,]+,[^,]+") then
|
||||
return zmac_adrs[i]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
test_ram_table()
|
||||
|
||||
zload_tableau()
|
||||
zsort_tableau()
|
||||
zshow()
|
||||
|
||||
print(find_adrs("02:ec:f1:a1:c8:29"))
|
||||
print(find_adrs("da:a1:19:b6:6b:50"))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print(zmac_adrs_index["02:ec:f1:a1:c8:29"])
|
||||
print(zmac_adrs[70])
|
||||
|
||||
t1, t2, t3, t4=zmac_adrs[70]:match("[^,]+,[^,]+,[^,]+,([^,]+),[^,]+")
|
||||
print(t1, t2, t3, t4)
|
||||
print(zmac_adrs[70]:match("[^,]+,[^,]+,[^,]+,([^,]+),[^,]+"))
|
||||
|
||||
zmac_adrs=nil
|
||||
zmac_adrs={}
|
||||
|
||||
zmac_adrs_index=nil
|
||||
zmac_adrs_index={}
|
||||
|
||||
|
||||
zmac_adrs_index={}
|
||||
zmac_adrs_index["toto"]=3
|
||||
print(zmac_adrs_index["toto"])
|
||||
|
||||
|
||||
]]
|
||||
|
||||
|
||||
|
||||
|
||||
function zround(num, dec)
|
||||
local mult = 10^(dec or 0)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
end
|
||||
|
||||
|
||||
|
||||
73
Tests/tst_sniffer_wifi1.csv
Normal file
73
Tests/tst_sniffer_wifi1.csv
Normal file
@@ -0,0 +1,73 @@
|
||||
1,da:a1:19:9b:4a:ba,0,-59,0
|
||||
2,9a:2e:66:00:03:c2,0,-58,0
|
||||
3,02:50:09:00:02:1e,0,-50,0
|
||||
4,9a:e6:33:b4:e9:a3,0,-58,0
|
||||
5,02:be:a3:2d:79:40,0,-40,0
|
||||
6,da:a1:19:b6:6b:50,0,-18,0
|
||||
7,f6:58:e4:25:70:b8,0,-57,0
|
||||
8,16:92:17:8f:1b:8c,0,-58,0
|
||||
9,9a:b8:4c:16:fe:f2,0,-59,0
|
||||
10,80:58:f8:17:dc:d8,0,-48,0
|
||||
11,c0:a6:00:bf:4e:43,0,-55,0
|
||||
12,80:58:f8:69:65:61,0,-42,0
|
||||
13,56:c8:77:a2:ac:9a,0,-57,0
|
||||
14,80:58:f8:49:1b:9d,0,-35,0
|
||||
15,26:b4:90:7b:35:4c,0,-57,0
|
||||
16,02:ab:db:d0:ce:ae,0,-34,0
|
||||
17,da:a1:19:fa:ba:d3,0,-59,0
|
||||
18,da:a1:19:95:ad:85,0,-57,0
|
||||
19,3a:42:0a:8d:2b:89,0,-58,0
|
||||
20,02:a5:79:4e:6c:8a,0,-42,0
|
||||
21,da:a1:19:5a:8a:7a,0,-58,0
|
||||
22,da:a1:19:d2:cb:be,0,-59,0
|
||||
23,cc:c0:79:7d:f5:d5,S7 Melanie,0,0
|
||||
24,da:a1:19:6a:ce:8f,0,-55,0
|
||||
25,1a:8c:3b:82:77:be,0,-58,0
|
||||
26,da:a1:19:01:2e:80,0,-54,0
|
||||
27,b8:d7:af:a6:bd:86,S7 zf,0,0
|
||||
28,96:a6:83:5c:39:15,0,-56,0
|
||||
29,da:a1:19:5f:b4:06,0,-52,0
|
||||
30,d8:30:62:5a:d6:3a,IMAC Maman,0,0
|
||||
31,4a:0f:35:e2:24:22,0,-47,0
|
||||
32,be:d8:cc:17:36:2c,0,-41,0
|
||||
33,02:2a:5c:ff:53:d3,0,-47,0
|
||||
34,da:a1:19:e1:e9:b7,0,-49,0
|
||||
35,da:a1:19:eb:5e:a2,0,-58,0
|
||||
38,da:a1:19:99:b6:98,0,-58,0
|
||||
36,02:6a:8d:b8:14:e2,0,-37,0
|
||||
37,80:58:f8:3d:5d:59,0,-37,0
|
||||
39,02:00:6c:8a:09:a9,0,-35,0
|
||||
40,ba:4b:28:9c:18:b6,0,-59,0
|
||||
41,da:a1:19:41:cb:f0,0,-55,0
|
||||
42,d6:75:c7:4e:52:20,0,-56,0
|
||||
43,da:a1:19:fa:53:66,0,-32,0
|
||||
44,92:76:98:d8:ab:ce,0,-56,0
|
||||
45,02:6e:d1:5f:35:c6,0,-40,0
|
||||
46,da:a1:19:a7:be:86,0,-50,0
|
||||
47,5c:f9:38:a1:f7:f0,MAC zf,-28,0
|
||||
48,80:58:f8:e6:e2:de,0,-47,0
|
||||
49,0c:2c:54:b3:c5:1a,0,-34,0
|
||||
50,da:a1:19:e1:23:63,0,-57,0
|
||||
51,da:a1:19:ec:26:dd,0,-56,0
|
||||
52,02:62:96:8b:80:4f,0,-29,0
|
||||
53,02:de:2f:a2:95:98,0,-40,0
|
||||
54,0e:c6:f3:36:ae:d9,0,-58,0
|
||||
55,da:a1:19:e8:48:bd,0,-49,0
|
||||
56,02:be:a3:95:0e:8b,0,-30,0
|
||||
57,ca:8e:46:cc:78:bd,0,-58,0
|
||||
58,80:58:f8:44:09:ce,0,-30,0
|
||||
59,02:07:49:35:67:10,0,-58,0
|
||||
60,c0:ee:fb:4a:ff:28,0,-55,0
|
||||
61,da:a1:19:ed:93:84,0,-59,0
|
||||
62,02:c5:a0:96:05:bd,0,-32,0
|
||||
63,da:a1:19:a6:a0:93,0,-56,0
|
||||
64,46:79:22:70:f5:b8,0,-59,0
|
||||
65,86:27:18:64:f8:c0,0,-57,0
|
||||
66,da:a1:19:89:2c:80,0,-59,0
|
||||
67,da:a1:19:01:85:98,0,-47,0
|
||||
68,80:58:f8:1c:18:4b,0,-39,0
|
||||
69,da:a1:19:30:32:b9,0,-55,0
|
||||
70,02:ec:f1:a1:c8:29,0,-49,0
|
||||
71,02:e6:ac:b3:6e:40,0,-43,0
|
||||
72,da:a1:19:70:fc:f2,0,-28,0
|
||||
73,88:e9:fe:6b:ec:1e,MAC Luc,0,0
|
||||
|
Reference in New Issue
Block a user