Sign in to follow this  
Followers 0
michaelslamet

Filter Text and Get Report

25 posts in this topic

I have a hard time to figure this out:

$data = "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data = "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data = "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data = "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data = "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data = "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data = "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

I would like to get report like this:

user1 > 3 times, which is:
www.abc.com :: Dec-12-2013 11:12:13
www.rrrxxy.com :: Oct-11-2013 09:12:18
www.abcxxy.com :: Oct-18-2013 10:11:18

user2 > 3 times, which is:
www.abc1.com :: Nov-12-2013 11:12:18
www.xyz2.com :: Oct-12-2013 09:12:18
www.abcxxy.com :: Oct-18-2013 10:12:18

user3 > 1 times, which is:
www.abc2.com :: Oct-12-2013 10:12:18

"user1", "user2", "user3" can be anything, so it could not be hard-coded.

Please point me to a right direction.

Thanks and Happy New Year, all!

Share this post


Link to post
Share on other sites



How many records do we talk about? Usually this is a job for a database.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

How many records do we talk about? Usually this is a job for a database.

 

Only few hundread maximum. Stored in a variable.

Thanks for reply, water :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

michaelslamet,

Quick and dirty...

#include <array.au3>

local $data

$data &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

local $a10 = StringSplit($data,@crlf,3)
local $a20[ubound($a10)][3], $sSaveUser = '', $sOut = '', $iCnt = 0

_arraysort($a10)

for $1 = 0 to ubound($a10) - 1
    if $a10[$1] = '' then ContinueLoop
    if $sSaveUser = stringsplit($a10[$1],'::',3)[0] then
        $sOut &= stringformat('%-30s %-30s',stringsplit($a10[$1],'::',3)[1], stringsplit($a10[$1],'::',3)[2]) & @crlf
    Else
        stringreplace($data,stringsplit($a10[$1],'::',3)[0],'')
        $iCnt = @extended
        $sOut &= stringsplit($a10[$1],'::',3)[0] & ' > ' & $iCnt & @CRLF
        $sSaveUser = stringsplit($a10[$1],'::',3)[0]
        $sOut &= stringformat('%-30s %-30s',stringsplit($a10[$1],'::',3)[1], stringsplit($a10[$1],'::',3)[2]) & @crlf
    endif
next

ConsoleWrite($sOut & @LF)

Happy New Year !

kylomas

edit : you can delete the def for $a20

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thank you, kylomas :)

I got this error when running it:

>Running AU3Check (1.54.22.0)  from:C:\Program Files\AutoIt3
C:\Documents and Settings\Windows\Desktop\app\report.au3(20,49) : ERROR: syntax error
    if $sSaveUser = stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3(21,73) : ERROR: syntax error
        $sOut &= stringformat('%-30s %-30s',stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3(21,106) : ERROR: syntax error
        $sOut &= stringformat('%-30s %-30s',stringsplit($a10[$1],'::',3)[1], stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3(23,57) : ERROR: syntax error
        stringreplace($data,stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3(25,46) : ERROR: syntax error
        $sOut &= stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3(26,50) : ERROR: syntax error
        $sSaveUser = stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3(27,73) : ERROR: syntax error
        $sOut &= stringformat('%-30s %-30s',stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3(27,106) : ERROR: syntax error
        $sOut &= stringformat('%-30s %-30s',stringsplit($a10[$1],'::',3)[1], stringsplit($a10[$1],'::',3)[
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Windows\Desktop\app\report.au3 - 8 error(s), 0 warning(s)

 

WinXP, AutoIT 3.8.8.1

Maybe need a newer AutoIT? Could it for 3.8.81 ?

Share this post


Link to post
Share on other sites

Something like this:

#include <array.au3>
Global $sData = "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF & _
        "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF & _
        "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF & _
        "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF & _
        "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF & _
        "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF & _
        "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18"
Global $aResult[1000][2] = [[1, 2]]
Global $aTempData, $aTempRecord
$aTempData = StringSplit($sData, @CRLF, 1)
For $i = 1 To $aTempData[0]
    $aTempRecord = StringSplit($aTempData[$i], " :: ", 1)
    For $j = 1 To $aResult[0][0]
        If $aResult[$j][0] = $aTempRecord[1] Then
            If $aResult[$j][1] = "" Then
                $aResult[$j][1] = $aTempRecord[2] & " :: " & $aTempRecord[3]
            Else
                $aResult[$j][1] = $aResult[$j][1] & "|" & $aTempRecord[2] & " :: " & $aTempRecord[3]
            EndIf
            ExitLoop
        ElseIf $aResult[$j][0] = "" Then
            $aResult[$j][0] = $aTempRecord[1]
            $aResult[$j][1] = $aTempRecord[2] & " :: " & $aTempRecord[3]
            $aResult[0][0] = $aResult[0][0] + 1
            ExitLoop
        EndIf
    Next
Next
ReDim $aResult[$aResult[0][0]][$aResult[0][1]]
$aResult[0][0] = $aResult[0][0] - 1
For $i = 1 To $aResult[0][0]
    $aTempRecord = StringSplit($aResult[$i][1], "|")
    ConsoleWrite($aResult[$i][0] & " > " & $aTempRecord[0] & " times, which is:" & @CRLF)
    For $j = 1 To $aTempRecord[0]
        ConsoleWrite(" " & $aTempRecord[$j] & @CRLF)
    Next
Next
_ArrayDisplay($aResult)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

michaelslamet,

These errors are due to a new feature for StringSplit introduced from the 3.3.10.0

kylomas,

nice demonstration of this new feature though  :)

But at each call to stringsplit($a10[$1] ,'::', 3)[n] a new internal temporary array is created so don't you find this way a bit heavy ?

Edited by mikell

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

mikell,

But at each call to stringsplit($a10[$1] ,'::', 3)[n] a new internal temporary array is created so don't you find this way a bit heavy ?

 

Yes, I thought so at first.  Increased the input file to 1000+ records with no appreciable change in speed ( not measured). 

edit: Mikell, Maybe your right. 10000 recs took 6.2 secs...

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

michaelslamet,

Apologies for the confusion...The following is similar to above soluitons and runs 10010 recs in .06 seconds (runs in either 3.3.8 or 3.3.10)

#include <array.au3>

local $data, $tdata

$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

for $1 = 1 to 1000
    $tdata &= $data
next

local $a10 = StringSplit($tdata,@crlf,3), $a20
local $sSaveUser = '', $sOut = '', $iCnt = 0

_arraysort($a10)

local $st = timerinit()

for $1 = 0 to ubound($a10) - 1
    if stringlen($a10[$1]) = 0 then ContinueLoop
    $a20 = stringsplit($a10,'::',3)
    if ubound($a20) < 2 then continueloop
    if $sSaveUser = $a20[0] then
        $sOut &= stringformat('%-30s %-30s',$a20[1], $a20[2]) & @crlf
    Else
        stringreplace($data,$a20[0],'')
        $iCnt = @extended
        $sOut &= $a20[0] & ' > ' & $iCnt & @CRLF
        $sSaveUser = $a20[0]
        $sOut &= stringformat('%-30s %-30s',$a20[1], $a20[2]) & @crlf
    endif
next

ConsoleWrite(stringformat('Time to run %03i records = %2.4f',$1*10,timerdiff($st)/1000) & @lf)

The other solution takes .85 seconds, a significant difference as pointed out by mikell.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Wouldn't something like this be an alternative start or using a 2D array even?

#include <array.au3>
#include <File.au3>
Global $data



$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF


$sOutput = StringRegExpReplace($data, '.*?(user\d+)\s\:\:\s(\w.*?)\s\:\:\s(.*?\d\:\d+\:\d+)', '$1   $2  $3')
ConsoleWrite($sOutput & @CRLF)
Local Const $sFilePath = @TempDir & "\temp.txt"

$hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE)
FileWrite ($hFileOpen, $sOutput)
FileClose($hFileOpen)
$array = FileReadToArray($sFilePath)
_ArraySort($array)
_ArrayDisplay($array)
Edited by Jury

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

@Jury:

I got this when run:

ERROR: FileReadToArray(): undefined function.

And second: "user1", "user2", "user3" could be anything. It could be "michael", "susan", "bill", so this RegExp:

[autoit]
$sOutput = StringRegExpReplace($data, '.*?(user\d+)\s\:\:\s(\w.*?)\s\:\:\s(.*?\d\:\d+\:\d+)', '$1   $2  $3')
[/autoit]

Will work with such condition?

@Kylomas:

Wow, the code is running fast!! On my PC: Time to run 100010 records = 0.0749

But I found $sOut is contain nothing ... ?

@Mikell:

Thank you :)

@Water:

Thank you for providing the working code! Time to run 10010 records = 0.4836

Edited by michaelslamet

Share this post


Link to post
Share on other sites
ERROR: FileReadToArray(): undefined function.

That's easy: Add

#include <File.au3>

to your script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

kylomas,

There were some typos in your script

#include <array.au3>

local $data, $tdata

$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

for $1 = 0 to 1000
    $tdata &= $data
next

local $a10 = StringSplit($tdata,@crlf,3), $a20
local $sSaveUser = '', $sOut = '', $iCnt = 0

_arraysort($a10)

local $st = timerinit()

for $i = 0 to ubound($a10) - 1
    if stringlen($a10[$i]) = 0 then ContinueLoop
    $a20 = stringsplit($a10[$i],'::',3)
    if ubound($a20) < 2 then continueloop
    if $sSaveUser = $a20[0] then
        $sOut &= stringformat('%-30s %-30s',$a20[1], $a20[2]) & @crlf
    Else
        stringreplace($tdata,$a20[0],'')
        $iCnt = @extended
        $sOut &= $a20[0] & ' > ' & $iCnt & @CRLF
        $sSaveUser = $a20[0]
        $sOut &= stringformat('%-30s %-30s',$a20[1], $a20[2]) & @crlf
    endif
next
ConsoleWrite(stringformat('Time to run %03i records = %2.4f',$1*10,timerdiff($st)/1000) & @lf)
FileWrite("1.txt", $sOut)

It was worth it to correct them as once done your script runs 0.4465 on my old XP :sorcerer:

Though this time will certainly be a bit longer with many different user names

Edited by mikell

Share this post


Link to post
Share on other sites

Though this time will certainly be a bit longer with many different user names

 

Yes, when I used test data with 1000 possible random users for 10000 records the run time increased to18+ seconds.

I took out the 2ND split and the use of @EXTENDED returned from stringinstr to accumulate user totals and got the run time under 1 sec...

#include <array.au3>
#include <date.au3>

local $tdata

#cs
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

for $1 = 0 to 1000
    $tdata &= $data
next
#ce

for $1 = 1 to 10000
    $tdata &= 'user' & stringformat('%04i',random(1,1000,1)) & ' :: ' & 'www.'
    for $2 = 1 to random(5,16,1)
        $tdata &= chr(random(97,122,1))
    Next
    $tdata &= '.com :: '
    $tdata &= _dateadd('D',random(-365,365,1),_nowcalc()) & @crlf
next

local $a10 = StringSplit($tdata,@crlf,3)
local $sSaveUser = '', $sOut = '', $iCnt = 1,$tOut = ''

_arraysort($a10)

local $st = timerinit()

for $1 = 0 to ubound($a10) - 1
    if stringlen($a10[$1]) = 0 then ContinueLoop
    if $sSaveUser = stringleft($a10[$1],stringinstr($a10[$1],' ::')-1) then
        $tOut &= stringformat('   %-30s %-30s', _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+) \:\:.*','$1'), _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+)','$1')) _
            & @crlf
        $iCnt += 1
    Else
        $sSaveUser = stringleft($a10[$1],stringinstr($a10[$1],' ::')-1)
        $sOut &= stringleft($a10[$1],stringinstr($a10[$1],' ::')-1) & ' > ' & $iCnt & @crlf
        $tOut &= stringformat('   %-30s %-30s', _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+) \:\:.*','$1'), _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+)','$1')) _
            & @crlf
        $sOut &= $tOut
        $tOut = ''
        $iCnt = 1
    endif


next
ConsoleWrite(stringformat('Time to run %03i records = %2.4f',$1-1,timerdiff($st)/1000) & @lf)
filedelete('1.txt')
FileWrite("1.txt", $sOut)
shellexecute('1.txt')

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

That's easy: Add

#include <File.au3>

to your script.

 

No, it's not from File.au3

The one from File.au3 is _FileReadToArray that take 2 parameters, while FileReadToArray on Jury's code only 1 parameter.

Before asking, I did do a search and found this

Maybe this only available on the newest AutoIT?

Share this post


Link to post
Share on other sites

No, it's not from File.au3

The one from File.au3 is _FileReadToArray that take 2 parameters, while FileReadToArray on Jury's code only 1 parameter.

Before asking, I did do a search and found this

Maybe this only available on the newest AutoIT?

That function is built in in version 3.3.10.xx +, if you're not running the latest version so you'll have to use the UDF version of that function.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I try to challenge myself although this is definitely too advance for me.
Kylomas and water's code also cause my head spin very fast, trying to understand :))

To make it "worst":
 

$data = "user1 :: 3 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data = "user2 :: 4 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data = "user3 :: 2 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data = "user2 :: 3 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data = "user1 :: 2 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data = "user2 :: 1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

I would like to get report like this:

user2 > 3 times, which is:
1 :: www.abcxxy.com :: Oct-18-2013 10:11:18
3 :: www.xyz2.com :: Oct-12-2013 09:12:18
4 :: www.abc1.com :: Nov-12-2013 11:12:18

user1 > 2 times, which is:
2 :: www.rrrxxy.com :: Oct-11-2013 09:12:18
3 :: www.abc.com :: Dec-12-2013 11:12:13

user3 > 1 times, which is:
2 :: www.abc2.com :: Oct-12-2013 10:12:18

So it will sort descendingly which user most frequently browse the web
and then sort ascendingly by the "counter" for each user.

I hope this is not too difficult :P

Share this post


Link to post
Share on other sites

Added to kylomas script, here is a way to sort users ascending by counter

#include <array.au3>
#include <date.au3>

local $tdata

#cs
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

for $1 = 0 to 1000
    $tdata &= $data
next
#ce

for $1 = 1 to 10000
    $tdata &= 'user' & stringformat('%04i',random(1,1000,1)) & ' :: ' & 'www.'
    for $2 = 1 to random(5,16,1)
        $tdata &= chr(random(97,122,1))
    Next
    $tdata &= '.com :: '
    $tdata &= _dateadd('D',random(-365,365,1),_nowcalc()) & @crlf
next

local $a10 = StringSplit($tdata,@crlf,3)
local $sSaveUser = '', $sOut = '', $iCnt = 1,$tOut = ''

_arraysort($a10)

local $st = timerinit()

for $1 = 0 to ubound($a10) - 1
    if stringlen($a10[$1]) = 0 then ContinueLoop
    if $sSaveUser = stringleft($a10[$1],stringinstr($a10[$1],' ::')-1) then
        $tOut &= stringformat('   %-30s %-30s', _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+) \:\:.*','$1'), _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+)','$1')) _
            & @crlf
        $iCnt += 1
    Else
        $sSaveUser = stringleft($a10[$1],stringinstr($a10[$1],' ::')-1)
        $sOut &= stringleft($a10[$1],stringinstr($a10[$1],' ::')-1) & ' > ' & stringformat('%02i', $iCnt) & @crlf
        $tOut &= stringformat('   %-30s %-30s', _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+) \:\:.*','$1'), _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+)','$1')) _
            & @crlf
        $sOut &= $tOut
        $tOut = ''
        $iCnt = 1
    endif
next

$sOut = StringStripWS($sOut, 3)
$res = stringregexp(stringregexpreplace(stringregexpreplace($sOut, '(?s)(\V+>\h)(\d+)(.+?)(?=\v+\V+>|$)', "$2$1$2$3"), '\r\n(?!\d)', '§'), '(?m)^.+?$', 3)
_ArraySort($res, 1)
$sOut = stringregexpreplace(StringReplace(_ArrayToString($res, @crlf), '§', @crlf), '(?m)^\d+', '')

filedelete('1.txt')
FileWrite("1.txt", $sOut)
shellexecute('1.txt')

For the other part of your neverending game, you'll just have to add yourself a slight complement  :P

Share this post


Link to post
Share on other sites

Added to kylomas script, here is a way to sort users ascending by counter

#include <array.au3>
#include <date.au3>

local $tdata

#cs
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$data &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$data &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$data &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$data &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$data &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$data &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

for $1 = 0 to 1000
    $tdata &= $data
next
#ce

for $1 = 1 to 10000
    $tdata &= 'user' & stringformat('%04i',random(1,1000,1)) & ' :: ' & 'www.'
    for $2 = 1 to random(5,16,1)
        $tdata &= chr(random(97,122,1))
    Next
    $tdata &= '.com :: '
    $tdata &= _dateadd('D',random(-365,365,1),_nowcalc()) & @crlf
next

local $a10 = StringSplit($tdata,@crlf,3)
local $sSaveUser = '', $sOut = '', $iCnt = 1,$tOut = ''

_arraysort($a10)

local $st = timerinit()

for $1 = 0 to ubound($a10) - 1
    if stringlen($a10[$1]) = 0 then ContinueLoop
    if $sSaveUser = stringleft($a10[$1],stringinstr($a10[$1],' ::')-1) then
        $tOut &= stringformat('   %-30s %-30s', _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+) \:\:.*','$1'), _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+)','$1')) _
            & @crlf
        $iCnt += 1
    Else
        $sSaveUser = stringleft($a10[$1],stringinstr($a10[$1],' ::')-1)
        $sOut &= stringleft($a10[$1],stringinstr($a10[$1],' ::')-1) & ' > ' & stringformat('%02i', $iCnt) & @crlf
        $tOut &= stringformat('   %-30s %-30s', _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+) \:\:.*','$1'), _
            stringregexpreplace($a10[$1],'.*\:\: ([\V]+)','$1')) _
            & @crlf
        $sOut &= $tOut
        $tOut = ''
        $iCnt = 1
    endif
next

$sOut = StringStripWS($sOut, 3)
$res = stringregexp(stringregexpreplace(stringregexpreplace($sOut, '(?s)(\V+>\h)(\d+)(.+?)(?=\v+\V+>|$)', "$2$1$2$3"), '\r\n(?!\d)', '§'), '(?m)^.+?$', 3)
_ArraySort($res, 1)
$sOut = stringregexpreplace(StringReplace(_ArrayToString($res, @crlf), '§', @crlf), '(?m)^\d+', '')

filedelete('1.txt')
FileWrite("1.txt", $sOut)
shellexecute('1.txt')

For the other part of your neverending game, you'll just have to add yourself a slight complement  :P

 

Haha, alright o:)

This is too advanced for me, but I will figure it out.

Anyway, the code produce a incorrect report:

#include <array.au3>
#include <date.au3>

Local $tdata

$tdata  = "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$tdata &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$tdata &= "user1 :: www.abc.com :: Dec-12-2013 11:12:13" & @CRLF
$tdata &= "user2 :: www.abc1.com :: Nov-12-2013 11:12:18" & @CRLF
$tdata &= "user3 :: www.abc2.com :: Oct-12-2013 10:12:18" & @CRLF
$tdata &= "user2 :: www.xyz2.com :: Oct-12-2013 09:12:18" & @CRLF
$tdata &= "user2 :: www.abcxxy.com :: Oct-18-2013 10:12:18" & @CRLF
$tdata &= "user1 :: www.rrrxxy.com :: Oct-11-2013 09:12:18" & @CRLF
$tdata &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF
$tdata &= "user1 :: www.abcxxy.com :: Oct-18-2013 10:11:18" & @CRLF

$sOut = Sort($tdata)

FileDelete('1.txt')
FileWrite("1.txt", $sOut)
ShellExecute('1.txt')

Func Sort($tdata)

    Local $a10 = StringSplit($tdata, @CRLF, 3)
    Local $sSaveUser = '', $sOut = '', $iCnt = 1, $tOut = ''

    _ArraySort($a10)

    For $1 = 0 To UBound($a10) - 1
        If StringLen($a10[$1]) = 0 Then ContinueLoop
        If $sSaveUser = StringLeft($a10[$1], StringInStr($a10[$1], ' ::') - 1) Then
            $tOut &= StringFormat('   %-30s %-30s', _
                    StringRegExpReplace($a10[$1], '.*\:\: ([\V]+) \:\:.*', '$1'), _
                    StringRegExpReplace($a10[$1], '.*\:\: ([\V]+)', '$1')) _
                     & @CRLF
            $iCnt += 1
        Else
            $sSaveUser = StringLeft($a10[$1], StringInStr($a10[$1], ' ::') - 1)
            $sOut &= StringLeft($a10[$1], StringInStr($a10[$1], ' ::') - 1) & ' > ' & StringFormat('%02i', $iCnt) & @CRLF
            $tOut &= StringFormat('   %-30s %-30s', _
                    StringRegExpReplace($a10[$1], '.*\:\: ([\V]+) \:\:.*', '$1'), _
                    StringRegExpReplace($a10[$1], '.*\:\: ([\V]+)', '$1')) _
                     & @CRLF
            $sOut &= $tOut
            $tOut = ''
            $iCnt = 1
        EndIf
    Next

    $sOut = StringStripWS($sOut, 3)
    $res = StringRegExp(StringRegExpReplace(StringRegExpReplace($sOut, '(?s)(\V+>\h)(\d+)(.+?)(?=\v+\V+>|$)', "$2$1$2$3"), '\r\n(?!\d)', '§'), '(?m)^.+?$', 3)
    _ArraySort($res, 1)
    $sOut = StringRegExpReplace(StringReplace(_ArrayToString($res, @CRLF), '§', @CRLF), '(?m)^\d+', '')

    Return $sOut
EndFunc   ;==>Sort

 

The result is incorrect:

user2 > 06

   www.abcxxy.com                 Oct-18-2013 10:11:18          

   www.abcxxy.com                 Oct-18-2013 10:11:18          

   www.abcxxy.com                 Oct-18-2013 10:11:18          

   www.rrrxxy.com                 Oct-11-2013 09:12:18          

   www.rrrxxy.com                 Oct-11-2013 09:12:18          

   www.abc1.com                   Nov-12-2013 11:12:18          

user3 > 03

   www.abcxxy.com                 Oct-18-2013 10:12:18          

   www.xyz2.com                   Oct-12-2013 09:12:18          

   www.abc2.com                   Oct-12-2013 10:12:18

user1 > 01

   www.abc.com                    Dec-12-2013 11:12:13          

 

Share this post


Link to post
Share on other sites

ms,

I changed something trying to speed it up and have since forgotten what I changed...doh!

The solution needs to be re-visited anyway given your new criteria.  However, it's 4:00AM here and the wife will be PISSED if I stay up all night, again.

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0