Raised This Month: $51 Target: $400
 12% 

Classifying File


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-30-2018 , 10:07   Classifying File
Reply With Quote #1

I have a file which is classified like this
PHP Code:
[1]
STATUS "UNFINISHED"
START_DATE "09/24/18 03:14"
TEAM_ONE_TAG "[TSM]"
TEAM_TWO_TAG "[FaZe]"
PLAYER_NUM 5

[2]
STATUS "UNFINISHED"
START_DATE "09/25/18 03:23"
TEAM_ONE_TAG "[Liquid]"
TEAM_TWO_TAG "[TSM]"
PLAYER_NUM 
So basically [1] represents the ID, from which I will be able to identify the class.
Now, I need a method to remove the classes by ID. Let's say we want to remove [1].

The file should look like this when we remove [1].
PHP Code:
[2]
STATUS "UNFINISHED"
START_DATE "08/25/18 03:23"
TEAM_ONE_TAG "[Liquid]"
TEAM_TWO_TAG "[TSM]"
PLAYER_NUM 
In simple words, I want to detect the 5 lines under the specified ID and ignore them.

I have an idea which should work, by adding the ID number of that class in front of each sentence but I'm looking for a better solution.

Thanks for any help!
__________________

Last edited by edon1337; 08-30-2018 at 10:15.
edon1337 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-30-2018 , 10:16   Re: Classifying File
Reply With Quote #2

Presumably you read this data in already such that you can index it. Simply write back the data without the one you don't want.
__________________
fysiks is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-30-2018 , 10:20   Re: Classifying File
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Presumably you read this data in already such that you can index it. Simply write back the data without the one you don't want.
It's not as easy as it looks to index these 'classes' as the only thing that differs among them is the ID. I know how to get rid of a line, the problem is indexing them.

What I'm incapable of is finding all the corresponding lines that belong to an ID, I'll highlight the ID's in blue and the corresponding lines of each ID in red:

Quote:
[1]
STATUS = "UNFINISHED"
START_DATE = "08/24/18 03:14"
TEAM_ONE_TAG = "[TSM]"
TEAM_TWO_TAG = "[FaZe]"
PLAYER_NUM = 5


[2]
STATUS = "UNFINISHED"
START_DATE = "08/25/18 03:23"
TEAM_ONE_TAG = "[Liquid]"
TEAM_TWO_TAG = "[TSM]"
PLAYER_NUM = 3


It would be quite easy to index them if I did this

Quote:
[1]
1_STATUS = "UNFINISHED"
1_START_DATE = "08/24/18 03:14"
1_TEAM_ONE_TAG = "[TSM]"
1_TEAM_TWO_TAG = "[FaZe]"
1_PLAYER_NUM = 5


[2]
2_STATUS = "UNFINISHED"
2_START_DATE = "08/25/18 03:23"
2_TEAM_ONE_TAG = "[Liquid]"
2_TEAM_TWO_TAG = "[TSM]"
2_PLAYER_NUM = 3


But, I'm trying to avoid that way.
__________________

Last edited by edon1337; 08-30-2018 at 10:23.
edon1337 is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-30-2018 , 10:43   Re: Classifying File
Reply With Quote #4

You did not understand what fysiks said. When you read the data you most likely save it in a trie/array or something. Let's say it's a dynamic array, then you can simply skip a specific entry in the array and write all the other items. You just need to be smart about how you organize your data: for example class 0 is at index 0, class 1 at index 1, etc.

A worse way, if you want to work directly with the file, once you find the wanted index skip all lines until you find another index, it's not hard.
__________________

Last edited by HamletEagle; 08-30-2018 at 10:43.
HamletEagle is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-30-2018 , 11:17   Re: Classifying File
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
You did not understand what fysiks said. When you read the data you most likely save it in a trie/array or something. Let's say it's a dynamic array, then you can simply skip a specific entry in the array and write all the other items. You just need to be smart about how you organize your data: for example class 0 is at index 0, class 1 at index 1, etc.
Oh, I see, nice idea. I was too carried away with deleting the lines I had no time to think of a better way.
I was using string array or w/e you call it combined with enum that's why I needed an ID, using CellArray, it won't be needed anymore.

Is this okay? There might even be a way where I don't even need to fill eData array but I can't bother thinking.
PHP Code:
CheckSchedule( )
{
    new 
szConfigs32 ], szFormat64 ], szData128 ], szKey32 ], szValue32 ];
    
get_configsdirszConfigscharsmaxszConfigs ) );
    
    
formatexszFormatcharsmaxszFormat ), "%s/%s"szConfigsg_szFile );
    new 
iFilePointer fopenszFormat"rt" );
    
    new 
eDataTournamentData ];
    
    if( 
iFilePointer )
    {
        while( 
fgetsiFilePointerszDatacharsmaxszData ) ) )
        {
            if( 
szData] == EOS || ( szData] == '/' && szData] == '/' ) || szData] == ';' || szData] == '[' )
            continue;
            
            
trimszData );  
            
            
strtokszDataszKeycharsmaxszKey ), szValuecharsmaxszValue ), '=' );
            
trimszKey );
            
trimszValue );
            
            if( 
equalszKey"TOURNAMENT_START_DATE" ) )
            
eDataTOURNAMENT_START_DATE ] = szValue;
            
            else if( 
equalszKey"TOURNAMENT_TEAM_ONE_TAG" ) )
            
eDataTOURNAMENT_TEAM_ONE_TAG ] = szValue;
            
            else if( 
equalszKey"TOURNAMENT_TEAM_TWO_TAG" ) )
            
eDataTOURNAMENT_TEAM_TWO_TAG ] = szValue;
            
            else if( 
equalszKey"TOURNAMENT_PLAYER_NUM" ) )
            
eDataTOURNAMENT_PLAYER_NUM ] = szValue;
            
            else if( 
equalszKey"TOURNAMENT_STATUS" ) )
            
eDataTOURNAMENT_STATUS ] = szValue;
            
            if( 
equaleDataTOURNAMENT_STATUS ], "UNFINISHED" ) )
            {                    
                
ArrayPushArrayg_aTournamentDataeData );
            }
        }
        
fcloseiFilePointer );
    }

__________________

Last edited by edon1337; 08-30-2018 at 11:20.
edon1337 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-31-2018 , 08:42   Re: Classifying File
Reply With Quote #6

You can try to use this code as an base.

Code:
/**  * Removes a key from a vault  *  * @param vaultname Vault name to look in  * @param key      Key to remove  * @return    No return  */ stock fvault_remove_key(const vaultname[], const key[]) {     new filename[128];     _FormatVaultName(vaultname, filename, sizeof(filename) - 1);         if( !file_exists(filename) )     {         return;     }         new file = fopen(_temp_vault, "wt");         new vault = fopen(filename, "rt");         new _data[512], _key[64], _other[3];     new bool:found_key;         while( !feof(vault) )     {         fgets(vault, _data, sizeof(_data) - 1);         parse(_data, _key, sizeof(_key) - 1, _other, sizeof(_other) - 1);                 if( equal(_key, key) )         {             found_key = true;             continue;         }                 fputs(file, _data);     }         fclose(file);     fclose(vault);         if( found_key )     {         delete_file(filename);                 while( !rename_file(_temp_vault, filename, 1) ) { }     }     else     {         delete_file(_temp_vault);     } }
__________________








CrazY. is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-31-2018 , 08:46   Re: Classifying File
Reply With Quote #7

Quote:
Originally Posted by CrazY. View Post
You can try to use this code as an base.

Code:
/**  * Removes a key from a vault  *  * @param vaultname Vault name to look in  * @param key      Key to remove  * @return    No return  */ stock fvault_remove_key(const vaultname[], const key[]) {     new filename[128];     _FormatVaultName(vaultname, filename, sizeof(filename) - 1);         if( !file_exists(filename) )     {         return;     }         new file = fopen(_temp_vault, "wt");         new vault = fopen(filename, "rt");         new _data[512], _key[64], _other[3];     new bool:found_key;         while( !feof(vault) )     {         fgets(vault, _data, sizeof(_data) - 1);         parse(_data, _key, sizeof(_key) - 1, _other, sizeof(_other) - 1);                 if( equal(_key, key) )         {             found_key = true;             continue;         }                 fputs(file, _data);     }         fclose(file);     fclose(vault);         if( found_key )     {         delete_file(filename);                 while( !rename_file(_temp_vault, filename, 1) ) { }     }     else     {         delete_file(_temp_vault);     } }
As everyone said above, it's better to not push the data into the array in the first place rather than pushing it and deleting.
__________________
edon1337 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-31-2018 , 09:24   Re: Classifying File
Reply With Quote #8

Um? I'm not sure about who you're referring... The code I sent to you does exactly what @fysiks said.
__________________








CrazY. is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 08-31-2018 , 10:09   Re: Classifying File
Reply With Quote #9

Quote:
Originally Posted by CrazY. View Post
Um? I'm not sure about who you're referring... The code I sent to you does exactly what @fysiks said.
It removes a key, meanwhile I'm able to simply skip it or ignore. My problem is solved I only need to test it and see whether it works as expected.
__________________
edon1337 is offline
shauli
Member
Join Date: Jun 2018
Old 08-31-2018 , 19:09   Re: Classifying File
Reply With Quote #10

Quote:
Originally Posted by edon1337 View Post
Oh, I see, nice idea. I was too carried away with deleting the lines I had no time to think of a better way.
I was using string array or w/e you call it combined with enum that's why I needed an ID, using CellArray, it won't be needed anymore.

Is this okay? There might even be a way where I don't even need to fill eData array but I can't bother thinking.
A general tip: remember to reset your variable's value when using them inside a for/while loop, it will help you to prevent bugs.

For example, if your 2nd or 3rd index will miss one of the strings (lets say 'TOURNAMENT_START_DATE') you'll accidentally push wrong information to your array because eData[ TOURNAMENT_START_DATE ] already has a value from the previous iterations.
shauli is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:28.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode