jerem488 Posted September 19, 2020 Share Posted September 19, 2020 Hi all, I have a function, it works fine but it takes many hours !! Can you tell me if the code can be changed? optimized? expandcollapse popupTournamentsClassement() Func TournamentsClassement() ;This file have 25000 lines Local $s_FileClassement = @DesktopDir & "\Classement.txt" Local $h_FileOpenClassement = FileOpen($s_FileClassement) ;This file have 3000 lines Local $s_FileTournaments = @DesktopDir & "\Tournaments.txt" Local $h_FileOpenTournaments = FileOpen($s_FileTournaments) Local $i_LignesClassement = _FileCountLines($h_FileOpenClassement) Local $i_LignesTournaments = _FileCountLines($h_FileOpenTournaments) For $i_LignesTournament = 1 To $i_LignesTournaments $s_LigneTournament = FileReadLine($h_FileOpenTournaments, $i_LignesTournament) $a_DataTournament = StringSplit($s_LigneTournament, "|", 2) ConsoleWrite("Date match: " & $a_DataTournament[6] & @TAB & "Joueur: " & $a_DataTournament[9] & @TAB & "Adversaire: " & $a_DataTournament[10] & @LF) For $i_LigneClassement = 1 To $i_LignesClassement $s_LigneClassement = FileReadLine($h_FileOpenClassement, $i_LigneClassement) $s_LigneClassement = StringRegExpReplace($s_LigneClassement, "(\d{4})-(\d{2})-(\d{2})", "$1/$2/$3") ;ConsoleWrite("$s_LigneClassement: " & $s_LigneClassement & @LF) $a_DataClassement = StringSplit($s_LigneClassement, "|", 2) $i_DiffDate = _DateDiff("D", $a_DataTournament[6], $a_DataClassement[2]) If $a_DataTournament[9] == $a_DataClassement[0] And $i_DiffDate < 0 Then _FileWriteToLine($h_FileOpenTournaments, $i_LignesTournament, $s_LigneTournament & "|" & $a_DataClassement[1]) ConsoleWrite($s_LigneTournament & "|" & $a_DataClassement[1] & @LF) ExitLoop ;this part does not work properly. ;I must change the line "If $a_DataTournament[9] == $a_DataClassement[0] And $i_DiffDate < 0 Then" with If $a_DataTournament[10] == $a_DataClassement[0] And $i_DiffDate < 0 Then ;ElseIf $a_DataTournament[10] == $a_DataClassement[0] And $i_DiffDate < 0 Then ;_FileWriteToLine($h_FileOpenTournaments, $i_LignesTournament, $s_LigneTournament & "||" & $a_DataClassement[1]) ;ConsoleWrite($s_LigneTournament & "||" & $a_DataClassement[1] & @LF) ;ExitLoop ; ------------------------------------------------------- EndIf Next Next EndFunc Thanks Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted September 19, 2020 Share Posted September 19, 2020 @jerem488 Could you please post a sample text file and a desired result? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
dmob Posted September 19, 2020 Share Posted September 19, 2020 Depending on your data, you probably can read the files into arrays.... and marvel at the speed improvement Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 19, 2020 Moderators Share Posted September 19, 2020 jerem488, This thread has been reported as possibly game-related. As far as I can see you are merely manipulating datasets, which happen to record the results of some form of competition. As such I am happy to leave the thread open. M23 P.S. I completely agree with the "array" suggestion above. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
jchd Posted September 19, 2020 Share Posted September 19, 2020 I even suspect this could be best done using a database and then SQLite (included with AutoIt distribution) is a perfect candidate. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
jerem488 Posted September 19, 2020 Author Share Posted September 19, 2020 13 minutes ago, jchd said: I even suspect this could be best done using a database and then SQLite (included with AutoIt distribution) is a perfect candidate. I think I will use this ! Arrays are too big for this... Qui ose gagneWho Dares Win[left]CyberExploit[/left] Link to comment Share on other sites More sharing options...
jchd Posted September 19, 2020 Share Posted September 19, 2020 Think twice about the correct schema to create. If for only one sport or game (e.g. chess) and one level of competition (local, regional or national) then things are simple. If not it can always be done but will require more detailled thinking. Without mode detail, I'd start with 3 tables constrained together by foreign keys: -) a players table -) a tournament table -) a matches table. A very simple skeleton (omitting many things wich depend on the activity and rules) can then be: CREATE TABLE "Players" ( "PlayerID" INTEGER PRIMARY KEY, "License" CHAR, "LicenseYear" CHAR, "Name" CHAR NOT NULL, "Surname" CHAR, "Rank" CHAR, "Birth" CHAR, "Phone" CHAR, "Email" CHAR); CREATE TABLE "Tournaments" ( "TournamentID" INTEGER PRIMARY KEY, "Name" CHAR, "Date" CHAR, "Place" CHAR); CREATE TABLE "Matches" ( "MatchID" INTEGER PRIMARY KEY, "TournamentID" INTEGER CONSTRAINT "fkMatchTournament" REFERENCES "Tournaments"("TournamentID") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, "Datetime" CHAR, "Player1" INTEGER CONSTRAINT "fkMatchPlayer1" REFERENCES "Players"("PlayerID") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, "Player2" INTEGER CONSTRAINT "fkMatchPlayer2" REFERENCES "Players"("PlayerID") ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED, "Score1" CHAR, "Score2" CHAR, "Comment" CHAR NOT NULL DEFAULT ''); This may need complete rewrite if, for instance, there are more than 2 players in a match, how the score is counted and detailed (e.g. tennis) and rank is computed. Yet this can be a basis for thinking about a schema. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now