Sign in to follow this  
Followers 0
IanN1990

Filter Array [Solved]

3 posts in this topic

#1 ·  Posted (edited)

Hi,

I do try to avoid questions like this but i am unable to get my head around it. Below is a small example array

#NoTrayIcon
#include <Array.au3>

Dim $Example[1][4]

$Example[0][0] = 5
_Arrayadd($Example,"0|0|1366|768")
_Arrayadd($Example,"0|0|1920|1080")
_Arrayadd($Example,"1920|0|1280|1024")
_Arrayadd($Example,"1920|0|1280|768")
_Arrayadd($Example,"-1920|0|1920|1080")
_ArrayDisplay(Example)

I need unique entry's of column 1 and column 2, and column 3 / 4 being highest.

 

Example;

Row 1 (Col1 & Col2) and Row 2 (Col1 & Col2) Match (Both having 0)  BUT Row 2 (Col3) is greater then Row 1 (Col1) "1920 > 1366".

So Row 1 is removed.

 

Row 3 (Col1 & Col2) and Row 4 (Col1 & Col2) Match (Both having 1920 | 0)  and  Row 4 (Col3 & Col3)  match (1280 | 1280) but in Col4 1024 > 768. 

So Row 4 is removed

 

Row 5 doesn't match any other Col or Col 2 so is unique

This would leave me with

#NoTrayIcon
#include <Array.au3>

Dim $Example[1][4]

$Example[0][0] = 3
_Arrayadd($Example,"0|0|1920|1080")
_Arrayadd($Example,"1920|0|1280|1024")
_Arrayadd($Example,"-1920|0|1920|1080")
_ArrayDisplay(Example)

So i am leave with 3 "Unique" Col 1 and Col 2 but only the "biggest" col 3 followed by biggest col 4.

The data can also be in random orders.

Anyone have any ideas?

Edited by IanN1990

Share this post


Link to post
Share on other sites



Try this sort func:

#include-once
#include <Array.au3>

Func _arraySort2D_MC(ByRef $avArray, $ColOrder, $iStart = 0, $iEnd = 0, $iDesc = 0, $bDelDuplictes = False)
    ;Parameters:
    ;$avArray           Array to sort
    ;$ColdOrder         String mit den Sortieranweisungen, getrennt mit "|" für jede Spalte
    ;                   zulässige Angaben:
    ;                                       nur Spaltenindex = normale Sortierung
    ;                                       Spaltenindex%N = numerische Sortierung
    ;                                       Spaltenindex%D = Sortierung nach Datum JJJJ/MM/TT
    ;                                       Spaltenindex%G = Sortierung nach Geburtstag MM/TT/JJJJ
    ;                   z.B.: "1|2%N|3%D|0" die Reihenfolge für die Sortierung ist 1.,2., 3. 0. (0 basierend)
    ;                   die 1. Spalte wird Standard von _ArraySort verwendet
    ;                   die 2. Spalte (%N) wird bei der Sortierun numerisch behnadelt
    ;                   die 3. Spalte (%D) wird als Datum behandelt
    ;
    ;                   es müssen alle Spalten des Arrays in den Sortieranweisungen vorkommen
    ;$iStart            Zeile bei der die Sortierung beginnt (OPTIONAL)
    ;$iEnd              Zeile bei der die Sortierung endet (OPTIONAL)
    ;$iDesc             Absteigend 1 = JA 0 = NEIN (OPTIONAL)
    ;$bDelDuplictes     nur einmalige Zeilen zulassen   True = Jede Zeile ist einmalig
    ;                                                   False = Es werden alle Zeilen ausgegeben
    ;                   =====================================================================
    ;Rückgabe:         0 Fehler (nicht alle Spalten in $ColOrder definert
    ;                   1 Erfolg
    ;Autor:             AutoBert 2010 erweeitert 2012
    ;==============================================================================================================
    Local $iDims = UBound($avArray, 0)
    If @error Or $iDims <> 2 Then
        MsgBox(16, "Fehler:", "kein 2D-Array")
        Return 0
    EndIf
    If $iEnd = 0 Then $iEnd = UBound($avArray) - 1
    If $iEnd > UBound($avArray) - 1 Then $iEnd = UBound($avArray) - 1
    $aCols = StringSplit($ColOrder, "|")
    ;consolewrite($aCols[0] & " " & UBound($array, 2) & @CRLF)
    If $aCols[0] <> UBound($avArray, 2) Then
        MsgBox(16, "Fehler:", "unterschiedliche Spaltenanzahl!")
        Return 0
    EndIf
    Local Const $sLeer = "                                                                                                                                               "
    Local $aColformat = $aCols
    Local $sRow
    For $i = 1 To $aColformat[0]
        ;$aColformat[$i] = StringRight($aColformat[$i], 1)
        $aCols[$i] = StringReplace($aCols[$i], "N", "")
        $aCols[$i] = StringReplace($aCols[$i], "D", "")
    Next
    _ArrayDelete($aColformat, 0)
    _ArrayDelete($aCols, 0)
    Local $iCols = UBound($aColformat)
    For $i = $iStart To $iEnd
        $sRow = ""
        For $j = 0 To $iCols - 1
            $iCol = $aCols[$j]
            Switch StringUpper(StringRight($aColformat[$j], 1))
                Case "N" ;numerisch
                    $aNum = StringSplit($avArray[$i][$iCol], ",")
                    If IsArray($aNum) Then
                        If $aNum[0] = 1 Then _ArrayAdd($aNum, " ")
                        $sRow &= StringRight($sLeer & $aNum[1] & "," & StringLeft($aNum[2]&$sLeer, 30), 99)
                    Else
                        $sRow &= StringRight($sLeer & $aNum[1], 99)
                    EndIf
                Case "D" ;Datum JJJJ/MM/TT
                    ;consolewrite("D: " & $aColformat[$j] & " " &  $avArray[$i][$iCols])
                    $aDate = StringSplit($avArray[$i][$iCol], ".")
                    If IsArray($aDate) Then $sRow &= $aDate[3] & "." & StringRight("0" & $aDate[2], 2) & "." & StringRight("0" & $aDate[1], 2)
                Case "G" ;Geburtstags-Datum MM/TT/JJJJ
                    ;consolewrite("D: " & $aColformat[$j] & " " &  $avArray[$i][$iCols])
                    $aDate = StringSplit($avArray[$i][$iCol], ".")
                    If IsArray($aDate) Then $sRow &= StringRight("0" & $aDate[2], 2) & "." & StringRight("0" & $aDate[1], 2) & "." & $aDate[3]
                Case Else
                    $sRow &= $avArray[$i][$iCol]
            EndSwitch
            If $j <> $iCols - 1 Then $sRow &= "|"
        Next
        $avArray[$i][0] = $sRow
        ;consolewrite($sRow & @CRLF)
    Next
    _ArraySort($avArray, $iDesc, $iStart, $iEnd)
    If $bDelDuplictes Then
        For $i = $iEnd - 1 To $iStart Step -1
            If $avArray[$i][0] = $avArray[$i + 1][0] Then
                _ArrayDelete($avArray, $i + 1)
                $iEnd -= 1
            EndIf
        Next
    EndIf
    ;_ArrayDisplay($avArray)
    ;_ArrayDisplay($aColformat, "FormatStrings")
    ;_ArrayDisplay($aCols, "Cols")
    ;consolewrite($iCols & @CRLF)
    For $i = $iStart To $iEnd
        ;consolewrite($avArray[$i][0] & @CRLF)
        $aSplit = StringSplit($avArray[$i][0], "|", 2)
        For $j = 0 To $iCols - 1
            $iCol = $aCols[$j]
            Switch StringRight($aColformat[$j], 1)
                ;               Case "X"

                ;#cs
                Case "N" ;numerisch
                    $avArray[$i][$iCol] = StringReplace($aSplit[$j], " ", "")
                    if StringRight($avArray[$i][$iCol],1)="," Then $avArray[$i][$iCol] = StringTrimRight($avArray[$i][$iCol], 1)
                    ;consolewrite(" N: " & $avArray[$i][$iCol])
                Case "D" ;Datum JJJJ/MM/TT
                    $aDate = StringSplit($aSplit[$j], ".")
                    $avArray[$i][$iCol] = StringReplace($aDate[3] & "." & $aDate[2] & "." & $aDate[1], "_", "")
                    ;consolewrite(" D: " & $avArray[$i][$iCol])
                Case "G" ;Geburtstags-Datum MM/TT/JJJJ
                    $aDate = StringSplit($aSplit[$j], ".")
                    $avArray[$i][$iCol] = StringReplace($aDate[2] & "." & $aDate[1] & "." & $aDate[3], "_", "")
                    ;consolewrite(" D: " & $avArray[$i][$iCol])
                    ;#ce
                Case Else
                    $avArray[$i][$iCol] = $aSplit[$j]
                    ;consolewrite(" : " & $avArray[$i][$iCol])
            EndSwitch
        Next
        ;consolewrite(@CRLF)
    Next
    Return 1
    ;_ArrayDisplay($avArray)
EndFunc   ;==>_arraySort2D_MC

sorry is only dicumented in german and i have not much time yet. If you can't solve ask again, i think tomorow i have some time for english docu.

But short: you should use : "0|1|2|3" as sort param, afte  your array is sorted over all columns.

 

Share this post


Link to post
Share on other sites
4 hours ago, AutoBert said:

sorry is only dicumented in german and i have not much time yet. If you can't solve ask again, i think tomorow i have some time for english docu.

Dont be silly!! Though i don't speak german that function was perfect and i have been able to understand the source code behind it and have now integrated the function :) Thank you

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