Sorting and Filtering Data - Flutter - Realtime Database - firebase

I have continuing data like this in my firebase realtime database. I want to get keys with values ​​greater than 75, their values and Province value.
{
"allboxes": {
"box00001": {
"boxes": {
"Electronic Box": 80,
"Glass Box": 25,
"Metal Box": 78,
"Oil Box": 90,
"Paper Box": 77,
"Plastic Box": 18
},
"info": {
"Id": "00001",
"Province": "Keçiören"
}
},
"box00002": {
"boxes": {
"Electronic Box": 95,
"Glass Box": 86,
"Metal Box": 45,
"Oil Box": 79,
"Paper Box": 98,
"Plastic Box": 18
},
"info": {
"Id": "00002",
"Province": "Etimesgut"
}
},
"box00003": {
"boxes": {
"Electronic Box": 55,
"Glass Box": 91,
"Metal Box": 79,
"Oil Box": 65,
"Paper Box": 50,
"Plastic Box": 100
},
"info": {
"Id": "00003",
"Province": "Çankaya"
}
}
}
}
I will use it in a Gridview.builder like this;
GridView.builder(
shrinkWrap: true,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
mainAxisExtent: 220,
crossAxisCount: 2,
crossAxisSpacing: 15,
),
itemCount: boxesValuesList!.length,
itemBuilder: (context, index) => OpenedBoxesGrid(
boxesValuesList![index].toString(),
boxesKeysList![index],
provinceValuesList![index],
),
)
I tried this;
final greaterThan75ValueTaskRef = FirebaseDatabase.instance
.ref('allboxes')
.orderByChild('boxes/Oil Box')
.startAt(75);
And It returns this in print function.
I/flutter ( 6345): [{boxes: {Glass Box: 86, Plastic Box: 18, Electronic Box: 95, Metal Box: 45, Oil Box: 79, Paper Box: 98}, info: {Id: 00002, Province: Etimesgut}}, {boxes: {Glass Box: 25, Plastic Box: 18, Electronic Box: 80, Metal Box: 78, Oil Box: 90, Paper Box: 77}, info: {Id: 00001, Province: Keçiören}}]
But as I mentioned, I want to get keys in one list, their values in another list, and their province values in another list. How can I do that? I want to create three lists with the ordered equivalent of each element like this.
[Electronic Box, Metal Box, Oil Box, Paper Box, Electronic Box, Glass Box, Oil Box, Paper Box, Glass Box, Metal Box, Plastic Box]
[80, 78, 90, 77, 95, 86, 79, 98, 91, 79, 100]
[Keçiören, Keçiören, Keçiören, Keçiören, Etimesgut, Etimesgut, Etimesgut, Etimesgut, Çankaya, Çankaya, Çankaya]

When you read from the Firebase Realtime Database, you get a DataSnapshot object with all the data from the path that you read.
To get the key of a snapshot, call its key property.
To get just the a specific branch under the snapshot, use its child() method. So for example (assuming that boxesValuesList is the DataSnapshot with the result of the query you shared), to get a snapshot of just the boxes in your builder, you'd do boxesValuesList![index].child("boxes").
This can go multiple levels deep, so again assuming that boxesValuesList is the DataSnapshot with the result of the query you shared, you could get just the value of the Oilbox with: boxesValuesList![index].child("boxes").child("Oil Box").getValue() or with a shorthand notation: boxesValuesList![index].child("boxes/Oil Box").getValue().

Related

Fetching block from Cosmos/Osmosis blockchain. Convert bytes to string then decrypt string

I am trying to fetch data like block_hash from Osmosis chain. The problem is I am getting a Uint8Array that I cannot actually convert to readable string/hash.
Response I get from my js app:
blockId: {
hash: Uint8Array(32) [
91, 215, 254, 180, 87, 180, 160, 121,
12, 47, 235, 35, 219, 203, 27, 45,
102, 213, 50, 40, 54, 194, 33, 28,
231, 139, 216, 246, 45, 73, 58, 188
],
partSetHeader: { total: 2, hash: [Uint8Array] }
}
Response I get from Postman:
"block_id": {
"hash": "mHyghR6nW+Mb+2SZ5DYTw6xfLO+IlrMW3vMh9nXo394=",
"part_set_header": {
"total": 2,
"hash": "u78nOYgp5bAZXmymTBFPbNIPxI+1NuRhi+I32Z5pSKY="
}
}
First I can't convert the Uint8Array to anything readable because when I try it with this code:
const string = new TextDecoder().decode(hash);
console.log(string);
I get this:
ڨ9�$Օka�
�Ց���ewf�§�qA�♥߂��
Also mHyghR6nW+Mb+2SZ5DYTw6xfLO+IlrMW3vMh9nXo394= is definitely not a valid blockchain transaction hash
A valid one looks like this:
BE2E8DFB4489D0349C78BC30D14802DE88FDF581F8DB6B6FAFA9EB6157646C07
Do you have any ideas is this any kind of encryption and if so how can I decrypt it?
Thank you very much in advance!
Use below mentioned code to convert blockhash into valid one /
const blockId="u78nOYgp5bAZXmymTBFPbNIPxI+1NuRhi+I32Z5pSKY=";
console.log(Buffer.from(blockId,'base64').toString("hex"))

How to count specific no of items in Postman response

I am new to postman. I have response and I want to count how many items with equipment_id =53
Here is my code which I tried but I couldn't see any output in console.
Response
[
{
"id": 373,
"user_id": 119118855,
"location_id": 9999,
"duration": 0,
"watts": 0,
"timestamp": "2019-07-12T00:00:00.000Z",
"equipment_id": 53,
"name": "10 Ride",
"equipment_name": "Bike2"
},
{
"id": 376,
"user_id": 119118855,
"location_id": 9999,
"duration": 0,
"watts": 0,
"timestamp": "2019-06-13T00:00:00.000Z",
"equipment_id": 53,
"name": "10 min Ride",
"equipment_name": "Bike2"
},
{
"id": 338,
"user_id": 119118855,
"location_id": 9999,
"duration": 0,
"watts": 0,
"timestamp": "2019-07-12T00:00:00.000Z",
"equipment_id": 17,
"name": "20 min Ride",
"equipment_name": "Bike"
},
]
Postman script I tried:
pm.test("count of records with equipment id 53",function(){
const jsonData = pm.response.json();
var count = jsonData.length;
//console.log(count);
function noofrecords (){
_each(count.equipment_id).to.include(53);
count++;
console.log("Count:" + noofrecords);
May I know how to write script to get count of equipment_id =53
Answer should be 2 here, but I am not getting it.
count = jsonData.filter( a => a["equipment_id"] === 53 ).length
this gives the count, here we are using array.filter to get all objects with equipment_id 53

Flutter decode one column of SQLite query result

My problem is that I have a sqlite Database with a column 'Rezepte'(Recipes) which contains a column 'Rezept_ID' and a column with the name('Rezept_Title') and I get a output like this:
{Rezept_ID: 0, Rezept_Title: [84, 104, 117, 110, 102, 105, 115, 99,
104, 102, 105, 108, 101, 116, 32, 105, 110, 32, 90, 105, 109, 116, 45,
83, 101, 115, 97, 109, 45, 75, 114, 117, 115, 116, 101, 32, 97, 117,
102, 32, 67, 104, 105, 108, 105, 45, 77, 97, 110, 103, 111, 45, 83,
97, 108, 97, 116]}
But I want for example(I'm not sure what the encoding means):
{Rezept_ID: 0, Rezept_Title: 'spaghetti'}
I found out that the numbers are just a decimal encoding and my question is:
How can I encode always just the column 'Rezept_Title' anscii? Or is there another encoding which dart shows in cleartext?
My current function to get the recipes is:
getRecipes() async {
Database db = await DatabaseHelper.instance.database;
// get all rows
List<Map> result = await db.query('Rezepte');
// print the results
return result.forEach((row) => print(row));
}
Looks like Rezept_Title is an array representation of a buffer instead of a string.
To make a string back out of a buffer array, use: new String.fromCharCodes(array)
In example:
getRecipes() async {
Database db = await DatabaseHelper.instance.database;
// get all rows
List<Map> result = await db.query('Rezepte');
// copy List of mutable Maps the ugly way
List<Map> parsedResult = [];
result.forEach((r) => parsedResult.add(Map<String, dynamic>.from(r)));
// make Rezept_Title string again
parsedResult.forEach((r) =>
r['Rezept_Title'] = new String.fromCharCodes(r['Rezept_Title'])
);
// print the parsed results
return parsedResult.forEach((row) => print(row));
}
You should get a print of:
{Rezept_ID: 0, Rezept_Title: "Thunfischfilet in Zimt-Sesam-Kruste auf Chili-Mango-Salat"}
PS: Better way to do this would be saving strings instead of buffers into database (and converting current records).

Forms Recognizer can't identify fields without : as keys

I've been using Forms Recognizer for some days now and can't get it to recognize the keys in my forms.
I want to use it to extract the answers given by students in a test...here is an example.
I can't change the structure of the sheet students fill because it is a national exam and I don't have access to who organizes it.
So I trained a model as recommended on Microsoft documentation and used it to "read" the forms and it gets most of the answers, but it all comes as values of a key "Tokens"
{
"key": [
{
"text": "__Tokens__",
"boundingBox": [
0,
0,
0,
0,
0,
0,
0,
0
]
}
],
"value": [
{
"text": "01",
"boundingBox": [
110.1,
826.6,
125.6,
826.6,
125.6,
816.8,
110.1,
816.8
],
"confidence": 1
},
{
"text": "A",
"boundingBox": [
148.2,
834.4,
160.6,
834.4,
160.6,
816.8,
148.2,
816.8
],
"confidence": 1
},
{
"text": "26",
"boundingBox": [
229.4,
828.6,
246,
828.6,
246,
816.8,
229.4,
816.8
],
"confidence": 1
},
{
"text": "B",
"boundingBox": [
268.6,
834.4,
277.8,
834.4,
277.8,
816.8,
268.6,
816.8
],
"confidence": 1
}
Then I recreated the structure on excel but with : after the numbers and trained another model. I also printed some copies of it and filled in to test and Form Recognizer understood the numbers as keys.
{
"key": [
{
"text": "01:",
"boundingBox": [
270.4,
1625.4,
313,
1625.4,
313,
1600.5,
270.4,
1600.5
]
}
],
"value": [
{
"text": "A",
"boundingBox": [
350.7,
1620.9,
368.8,
1620.9,
368.8,
1587,
350.7,
1587
],
"confidence": 1
}
]
},
{
"key": [
{
"text": "26:",
"boundingBox": [
520.2,
1624.2,
552.8,
1624.2,
552.8,
1600.5,
520.2,
1600.5
]
}
],
"value": [
{
"text": "E",
"boundingBox": [
604.6,
1618.8,
625.8,
1618.8,
625.8,
1587,
604.6,
1587
],
"confidence": 1
}
]
}
Does anyone know some way to recognize the number fields as keys without the : ?
Form Recognizer will not consider the row numbers as keys unless specifically marked as keys, hence it currently does not discover them as keys.

IniRead array and pass to download function with progress bar

so i'm trying to work out how to get a downloader function working in a tool i'm working on, basically theres a tab with 3 download buttons, based on what button is clicked in the tab i'd like it to pass to one function, the downloder that will read the links from the ini file, with a progress bar in the tab I'll post the code bellow so you'll get an understanding
So it will download the files absolutely fine the only problem is when I start the app the download for the first file in the array starts automatically even though I didn't click the label in the tab, nor does the rest of the GUI function, I can't switch tabs as it just "freezes" then the download starts all over again if i comment out the case dwitch for $modlabel1 like so ";Case $modlabel1" it allows me to switch tabs etc just fine and I can switch tabs and click on the other 2 buttons and they will download as intended but the GUI stays on the mod tab till its finished, another small issue I have is i need the files to download with the same as the source file name, is that possible to do with InetGet?
Downloads Tab
Func _mods_gui()
$modsgui = GUICreate("Mods", 1270, 610, 5, 105, BitOR($ws_popup, $ws_border), $ws_ex_mdichild, $maingui)
GUISetBkColor(3487029)
DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $setgui, "int", 250, "long", 524288)
$progressbar1 = GUICtrlCreateProgress(10, 200, 1250, 50, $PBS_MARQUEE)
$modlabel1 = GUICtrlCreateLabel("Download" & #CRLF & "DayZ Epoch 1.0.5.1", 50, 50, 350, 100, $ss_center)
GUICtrlSetFont(-1, 30, 700, 0, "Segeo UI", 4)
GUICtrlSetBkColor(-1, 3825)
GUICtrlSetColor(-1, 16777215)
_guictrl_setonhover(-1, "_Hover", "_Hover_Leave")
$modlabel2 = GUICtrlCreateLabel("Download" & #CRLF & "DayZ Overwatch 0.2.5", 450, 50, 350, 100, $ss_center)
GUICtrlSetFont(-1, 30, 700, 0, "Segeo UI", 4)
GUICtrlSetBkColor(-1, 3825)
GUICtrlSetColor(-1, 16777215)
_guictrl_setonhover(-1, "_Hover", "_Hover_Leave")
$modlabel3 = GUICtrlCreateLabel("Download" & #CRLF & "Namalsk 0.75", 850, 50, 350, 100, $ss_center)
GUICtrlSetFont(-1, 30, 700, 0, "Segeo UI", 4)
GUICtrlSetBkColor(-1, 3825)
GUICtrlSetColor(-1, 16777215)
_guictrl_setonhover(-1, "_Hover", "_Hover_Leave")
$modsgr2 = GUICtrlCreateGraphic(0, 25, 1270, 250)
GUICtrlSetState(-1, $gui_disable)
GUICtrlSetGraphic(-1, $gui_gr_color, 0, 2368548)
GUICtrlSetGraphic(-1, $gui_gr_rect, 0, 0, 1270, 250)
GUISetState(#SW_SHOW, $modsgui)
EndFunc
While Switch Case
Case $modsgui
Switch $nmsg[0]
Case $modlabel1
_downloadmod(0)
Case $modlabel2
_downloadmod(1)
Case $modlabel3
_downloadmod(2)
EndSwitch
Download Array
Func _downloadmod($mod)
$modarrayread[3] = [IniRead(#ScriptDir & "\LauncherFiles\data\XGLConfig.cfg", "mod_links", "mod_epoch", Default), IniRead(#ScriptDir & "\LauncherFiles\data\XGLConfig.cfg", "mod_links", "mod_overwatch", Default), IniRead(#ScriptDir & "\LauncherFiles\data\XGLConfig.cfg", "mod_links", "mod_namalsk", Default)]
$dwnmod = InetGet($modarrayread[$mod], #ScriptDir & "\Mods\$name.zip", 1, 1)
Do
Sleep(50)
$prc = Round(InetGetInfo($dwnmod, 0) / (InetGetInfo($dwnmod, 1)) * 100)
GUICtrlSetData($progressbar1, $prc)
Until InetGetInfo($dwnmod, $INET_DOWNLOADCOMPLETE)
EndFunc
INI
[mod_links]
mod_epoch=http://files.xexgaming.com/mods/#DayZ_Epoch1051.zip
mod_overwatch=http://files.xexgaming.com/mods/#DayZOverwatch.zip
mod_namalsk=http://files.xexgaming.com/mods/#Namalsk.zip
Credits to Trojan for the help with the array, worked out how to get the parameters using his example
I worked with the example script in the help for GUICtrlCreateProgress as base and wrote a script which hopefully does what u wanted it to do.
If you have any questions feel free to ask :)
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
Example()
Func Example()
Local $progressbar1, $button1, $button2, $button3
Local $downarrayread[3] = [IniRead(#ScriptDir & "\Files\data\Config.cfg", "links", "link_1", Default), IniRead(#ScriptDir & "\Files\data\Config.cfg", "links", "link_2", Default), IniRead(#ScriptDir & "\Files\data\Config.cfg", "links", "link_3", Default)]
GUICreate("Downloads", 220, 100, 100, 200)
$progressbar1 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
$button1 = GUICtrlCreateButton("Start 1", 5, 70, 70, 20)
$button2 = GUICtrlCreateButton("Start 2", 75, 70, 70, 20)
$button3 = GUICtrlCreateButton("Start 3", 145, 70, 70, 20)
GUISetState(#SW_SHOW)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $button1
$hDownload = InetGet($downarrayread[1], #ScriptDir & "/Downloads/File1", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
Sleep(250)
GUICtrlSetData($progressbar1,((InetGetInfo($hDownload,$INET_DOWNLOADSIZE )/InetGetInfo($hDownload, $INET_DOWNLOADREAD))*100)/3)
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
Case $button2
$hDownload = InetGet($downarrayread[2], #ScriptDir & "/Downloads/File2", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
Sleep(250)
GUICtrlSetData($progressbar1,((InetGetInfo($hDownload,$INET_DOWNLOADSIZE )/InetGetInfo($hDownload, $INET_DOWNLOADREAD))*100)/3+33.33)
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
Case $button3
$hDownload = InetGet($downarrayread[3], #ScriptDir & "/Downloads/File3", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
Sleep(250)
GUICtrlSetData($progressbar1,((InetGetInfo($hDownload,$INET_DOWNLOADSIZE )/InetGetInfo($hDownload, $INET_DOWNLOADREAD))*100)/3+66.66)
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
EndSwitch
WEnd
EndFunc ;==>Example

Resources