[Include] DJson 1.6.2 - Fast/Extensive File Reader/Writer (Official DiniІ) (Works in FS)
#21

whow, thatґs nice

Thanks Draco, gonna change everything from dini to DJson now :P
Reply
#22

I have tried turning the Autocommit of at the beginning of all the data writing, then I commited the file and at the end I turned Autocommit on again.
The time that it takes is still around 2-5 seconds.

And I've maybe found a bug. When I registered directly after a gmx, it didn't stored all the data that I was going to save, it only saved 2 of the 7 savings to the file.

Here is my code:

pawn Код:
djAutocommit(false);
  format(str, sizeof(str), "%s/Password", player);
    djSetInt("Accounts.json", str, udb_hash(params));
    format(str, sizeof(str), "%s/Money", player);
    djSetInt("Accounts.json", str, GetPlayerMoney(playerid));
    format(str, sizeof(str), "%s/Score", player);
    djSetInt("Accounts.json", str, GetPlayerScore(playerid));
    format(str, sizeof(str), "%s/Health", player);
    GetPlayerHealth(playerid, pHealth);
    djSetFloat("Accounts.json", str, pHealth);
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    format(str, sizeof(str), "%s/X", player);
    djSetFloat("Accounts.json", str, Pos[0]);
    format(str, sizeof(str), "%s/Y", player);
    djSetFloat("Accounts.json", str, Pos[1]);
    format(str, sizeof(str), "%s/Z", player);
    djSetFloat("Accounts.json", str, Pos[2]);
    djCommit("Accounts.json");
    djAutocommit(true);
The variables player and params have been defined already.

Thanks
Reply
#23

Quote:
Originally Posted by Wadabak
I have tried turning the Autocommit of at the beginning of all the data writing, then I commited the file and at the end I turned Autocommit on again.
The time that it takes is still around 2-5 seconds.
The startup usually takes up to 3 or 4 seconds, due to the fact that the sqlite database is slow at startup, which djson uses as cache. Do you mean that?


Quote:
Originally Posted by Wadabak
And I've maybe found a bug. When I registered directly after a gmx, it didn't stored all the data that I was going to save, it only saved 2 of the 7 savings to the file.

Here is my code:

pawn Код:
djAutocommit(false);
  format(str, sizeof(str), "%s/Password", player);
    djSetInt("Accounts.json", str, udb_hash(params));
    format(str, sizeof(str), "%s/Money", player);
    djSetInt("Accounts.json", str, GetPlayerMoney(playerid));
    format(str, sizeof(str), "%s/Score", player);
    djSetInt("Accounts.json", str, GetPlayerScore(playerid));
    format(str, sizeof(str), "%s/Health", player);
    GetPlayerHealth(playerid, pHealth);
    djSetFloat("Accounts.json", str, pHealth);
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    format(str, sizeof(str), "%s/X", player);
    djSetFloat("Accounts.json", str, Pos[0]);
    format(str, sizeof(str), "%s/Y", player);
    djSetFloat("Accounts.json", str, Pos[1]);
    format(str, sizeof(str), "%s/Z", player);
    djSetFloat("Accounts.json", str, Pos[2]);
    djCommit("Accounts.json");
    djAutocommit(true);
The variables player and params have been defined already.
Can you please provide an example for that? What exactly is not saved? The issue is, that the file needs to be loaded to cache first. So, directly _set_ without _get_ before, won't work like expected. I'll make a fix for that on 1.3 release.

- Draco
Reply
#24

Quote:

The startup usually takes up to 3 or 4 seconds, due to the fact that the sqlite database is slow at startup, which djson uses as cache. Do you mean that?

That's not the issue. I've restarted the GM, then I've waited arround 10-15 seconds. I've used the command ~5 seconds later, the SendClientMessage will show. I've putted that sendclientmessage before djCommit("Accounts.json");.


The second thing.
When I have used the command after the gmx, it did fully saved. But then I did gmx again, it only saved 2 items.

It should look like this:
Код:
{"Antironix":{"Health":100.000000,"Money":0,"Password":256115588,"Score":0,"X":135.146362,"Y":-67.085334,"Z":1.578125}}
But sometimes it will show this:
Код:
{"Antironix":{"Health":100.000000,"Z":-42.978889}}
I'ts like 50% it will show the first one and 50% that it will show the second one.

Also if it will show the second one, it is ALWAYS showing 'Health' and 'Z', so the first and the last saving. And it is still during ~5 seconds when the SendClientMessage is showing.

Thanks.
Reply
#25

Thanks to Wadabak for reporting 1 issue, which is fixed in djson 1.3.

Released Version 1.3 (2008/08/31)
* fixed bug with arrays in djUnset
* fixed dj(Int/Float)Set-issue, if file hasn't been loaded yet (reported by Wadabak)
* using streamwriter for any commiting -> faster saving
* added djRevert

Please update asap if you are using djUnset or dmap (0.2 released, too!!) .

- Draco
Reply
#26

What issue did you fixed? As I still have the bug that it is loading slow and that it is sometimes saving 2 things instead of all 7 things.
Reply
#27

Nice!
Reply
#28

I dont know if it's a noob question... but....
I have the players' data, vehicles, houses and properties stored in individual files through the dini...
Then, how i can readapt all my gm for diniІ? Because exists several script lines with dini!

Sorry bad english
Reply
#29

Quote:
Originally Posted by JwLoaDing
I dont know if it's a noob question... but....
I have the players' data, vehicles, houses and properties stored in individual files through the dini...
Then, how i can readapt all my gm for diniІ? Because exists several script lines with dini!

Sorry bad english
Do you already have dini-user-files? In that case you need a converter.

For the script dini to djson conversion: very simple .
dini_Int becomes to djInt
dini_IntSet becomes to djSetInt
dini_Get becomes to dj
dini_Set becomes to djSet
and so on, parameters stay the same.

Special: dini_Exists is not required, you may need fexists for that.

A good read, may be the functions-page for djson, so you get what the functions do and will know how to adapt them.

- Draco
Reply
#30

I think it was asked and I missed it, hopefully not. Is DJson faster than pawno's file system?
Reply
#31

Quote:
Originally Posted by Cezar
I think it was asked and I missed it, hopefully not. Is DJson faster than pawno's file system?
DJson uses the pawno file system for initial read of the data. So if you are loading one big file _once_ and thats all: native pawno is faster.
But if you want to write a specific part of the file, or read several times (this is where djson uses memory-cache - no file read needed anymore) or commit lots of changes in a batch - djson is way faster.

- Draco
Reply
#32

Thks for reply Draco...
I got convert my gm... But I have a problem...
The data in the files were not loaded
Djson can load data in file as Dini? In each line?

Code:
PlayerName=NoPlayerName
HealthSpawn=70
Money=145789
Deaths=7
Kills=15
I have like this several files this way... A file for each player, for each car, for each house, for each property


Reply
#33

Quote:
Originally Posted by JwLoaDing
Thks for reply Draco...
I got convert my gm... But I have a problem...
The data in the files were not loaded
Djson can load data in file as Dini? In each line?

Code:
PlayerName=NoPlayerName
HealthSpawn=70
Money=145789
Deaths=7
Kills=15
I have like this several files this way... A file for each player, for each car, for each house, for each property


Hello JwLoaDing,

actually djson can not load dini files. It's a completely different (thatswhy faster ) file format.

I try to put a converter together for you, so you can easily convert your ini files to djson!

- Draco
Reply
#34

Thanks again, draco

I think I would get to do a function to convert the files of the cars, houses and properties because they are nominated for a numeric sequence, then with a loop I repeat the conversion procedure for each file... But, for the players whose files are nominated for the players' names I would have to do conversion file for file manually

I will wait for a converter, I think that should be simple for you
Reply
#35

Morgen Dracoblue,

i have some trouble with json, admittedly i know how to set:
Code:
{"data":[{"1":"2"},{"3":"4"}]}
but i would realy like to know, how to create something similiar to this:
Code:
{"data":[1,2,3,4]}
I hope you can help me out with this.

Danke!

MfG pen_theGun.
Reply
#36

Hi!

What you are about to do is to create an array, because [ and ] indictes that it is an array.

I made a short explanation how to access/write/count arrays in the djson-dev-wiki. Hope it helps - if it doesn't - ask again !

- Draco
Reply
#37

I seem to have found a bug with reading large strings before the server is restarted. For example if i used a register command it would save the password to a file good, but when i try to read that password it returns null untill the server is restarted. Here is some example code.
pawn Код:
#include <a_samp>
#include <djson>

forward testtimer();

new count, t_timer;

main()
{
    new str[129];//below is my name hashed with whirlpool (129 cells)
    format(str, sizeof(str), "362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D");
    djSet("test.json","test/pass",str);
    t_timer = SetTimer("testtimer",2000,true);
}
public OnGameModeInit(){djson_GameModeInit();return 1;}
public OnGameModeExit(){djson_GameModeExit();return 1;}

public testtimer()
{
    count ++;
    if(count == 5)KillTimer(t_timer);
    printf("attempt %d\n%s", count, dj("test.json","test/pass"));
}
Output on first execution
Код:
[08:37:59] ---------------
[08:37:59]   Loaded 0 filter scripts.

[08:37:59] Number of vehicle models: 0
[08:38:01] attempt 1

[08:38:03] attempt 2

[08:38:05] attempt 3

[08:38:08] attempt 4

[08:38:10] attempt 5

[08:38:28] --- Server Shutting Down.
Output after restart (same code)
Код:
[08:44:34] ---------------
[08:44:34]   Loaded 0 filter scripts.

[08:44:34] Number of vehicle models: 0
[08:44:36] attempt 1
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:39] attempt 2
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:41] attempt 3
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:43] attempt 4
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:46] attempt 5
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D

[08:45:32] --- Server Shutting Down.
I don't understand why this is happening it works fine for small strings and i checked the max string in the include is 255. If anyone can help it would be much appreciated.
Reply
#38

Quote:
Originally Posted by iggy1
Посмотреть сообщение
I seem to have found a bug with reading large strings before the server is restarted. For example if i used a register command it would save the password to a file good, but when i try to read that password it returns null untill the server is restarted. Here is some example code.
pawn Код:
#include <a_samp>
#include <djson>

forward testtimer();

new count, t_timer;

main()
{
    new str[129];//below is my name hashed with whirlpool (129 cells)
    format(str, sizeof(str), "362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D");
    djSet("test.json","test/pass",str);
    t_timer = SetTimer("testtimer",2000,true);
}
public OnGameModeInit(){djson_GameModeInit();return 1;}
public OnGameModeExit(){djson_GameModeExit();return 1;}

public testtimer()
{
    count ++;
    if(count == 5)KillTimer(t_timer);
    printf("attempt %d\n%s", count, dj("test.json","test/pass"));
}
Output on first execution
Код:
[08:37:59] ---------------
[08:37:59]   Loaded 0 filter scripts.

[08:37:59] Number of vehicle models: 0
[08:38:01] attempt 1

[08:38:03] attempt 2

[08:38:05] attempt 3

[08:38:08] attempt 4

[08:38:10] attempt 5

[08:38:28] --- Server Shutting Down.
Output after restart (same code)
Код:
[08:44:34] ---------------
[08:44:34]   Loaded 0 filter scripts.

[08:44:34] Number of vehicle models: 0
[08:44:36] attempt 1
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:39] attempt 2
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:41] attempt 3
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:43] attempt 4
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D
[08:44:46] attempt 5
362C5AE16755FB404B2C5B507522AE358F1DB630EBAE9836422E8C2E9FCAC537BA08A2EEF982CBBDAFFFC5D72F9595AF22400C1C0FEAD955FDA22ADC9916511D

[08:45:32] --- Server Shutting Down.
I don't understand why this is happening it works fine for small strings and i checked the max string in the include is 255. If anyone can help it would be much appreciated.
Set MAX_STRING to 512 and try.
Reply
#39

Quote:
Originally Posted by The_Moddler
Посмотреть сообщение
Set MAX_STRING to 512 and try.
Exelent nice1 it works, do you know why that happened? I mean the string was way less than 255
Reply
#40

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Exelent nice1 it works, do you know why that happened? I mean the string was way less than 255
Yes, becouse your file is greater than 255 bytes.. that's why ^^

To know the exact size, you can count all it's characters, and change it to the amount of characters that the file has.

Quote:
Originally Posted by [L3th4l]
Посмотреть сообщение
Question: Well, i created this vehicle ownership that saves the player's vehicle ( List most vehicles ownership save type ) and it also saves all possible mods a vehicle can have. So my question is, is it better and faster to save ^ my system using djson, or MySQL would be a better option?
MySQL is far faster, but if there aren't too many vehicles, you can try djson
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)