Jump to content

Optimizing the code


jerem488
 Share

Recommended Posts

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?

TournamentsClassement()
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

  • Moderators

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.

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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

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

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 here
RegExp tutorial: enough to get started
PCRE 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...