Jump to content

Recommended Posts

Posted

So I have a nice long array (20-30k elements) and what I am trying to do is get a list of the unique items in column 1. Then if there is a match of column 1 to the unique, add the value of column into the hold array. Here is a shortened version of what I have been trying to make work. My issue is that I don't know how to add the column 2 matches into the imageData since each unique color will have a different number of elements in it.

local $uniqueColors[2] = ["FF8822","00A2F1"]
local $imageData[7][2] = [["FF8822","A2"],["00A2F1","A3"],["FF8822","B7"],["00A2F1","G4"],["FF8822","J10"],["FF8822","J11"],["FF8822","A10"],["00A2F1","H4"]]
local $holdArray[2][50]

for $h = 0 to UBound($imageData, $UBOUND_ROWS)-1
   for $r = 0 to UBound($uniqueColors)-1
      if ($imageData[$h][0] = $uniqueColors[$r]) Then
      
            ; how to add $imageData[$h][1] into $holdArray[$r][??]
            
      EndIf

      Next
Next

So end the end it would look like:

$holdArray[2][6] [["FF8822","A2","B7","J10","J11","A10"]["00A2F1","A3","G4","H4","",""]]

 

Thanks for the assistance!

Posted (edited)

Hey,

Not tested but something like this should work. I am pretty sure someone else will mention a more efficient approach.

If you don't mind the $imageData array getting destroyed :)  Else just make a copy of it and perform the same on it.

1- For each unique color

2- Check imagedata for column2

3- if not "x" meaning previously processed, then

4- add to next available column on holdarray

5- check for all rows after this, marking all matches as "x"

 

for $i = 0 to ubound($uniqueColors)-1
    $iCounter = 1
    $holdArray[$i][0] = $uniqueColors[$i]
    for $j = 0 to ubound($imageData)-1
        if not $imageData[$j][0] = "x" Then
            if $uniqueColors[$i] = $imageData[$j][0] Then
                $holdArray[$i][$iCounter]=$imageData[$j][1]
                $iCounter += 1
                for $k = $j+1 to ubound($imageData)-1
                    if ($imageData[$k][0] = $uniqueColors[$i]) and ($imageData[$k][1] = $imageData[$j][1]) then
                        $imageData[$k][0] = "x"
                        $imageData[$k][1] = "x"
                    EndIf
                Next
            EndIf
        EndIf
    next
Next

 

Edited by GokAy
Posted
1 hour ago, BrianTheLibrarian said:

I don't know how to add the column 2 matches into the imageData since each unique color will have a different number of elements in it

A much easier way could be to keep on using a 2D array and store the results in column 1, then to use StringSplit on these elements if needed. Example :

#Include <Array.au3>

local $uniqueColors[2][2] = [["FF8822",""],["00A2F1", ""]]
;_ArrayDisplay($uniqueColors)
local $imageData[8][2] = [["FF8822","A2"],["00A2F1","A3"],["FF8822","B7"],["00A2F1","G4"],["FF8822","J10"],["FF8822","J11"],["FF8822","A10"],["00A2F1","H4"]]

for $r = 0 to UBound($uniqueColors)-1
   for $h = 0 to UBound($imageData)-1
        if $imageData[$h][0] = $uniqueColors[$r][0] Then
            $uniqueColors[$r][1] &= $imageData[$h][1] & ","
      EndIf
      Next
      If StringRight($uniqueColors[$r][1], 1) = "," Then $uniqueColors[$r][1] = StringTrimRight($uniqueColors[$r][1], 1)
Next
_ArrayDisplay($uniqueColors)

 

Posted

@mikell I must have understood the OP wrong. The code I wrote accounts for multiple accounts of column2, and only adds once at first instance. You assumed they would be unique. Do I get this right? :) 

Looking at column2 values again this time, they look like a spreadsheet address. So, your code may  not only be better (easier), but also the correct approach.

However, you can also modify your code, with an if check with StringInStr with the already stored values and not append if found, in case multiple accounts of column2 may exist.

Posted

I would switch to a database for such processing. AutoIt has SQLite support.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

So I ended up with this, which solved my problem. I needed it in a textfile after I thought about it for a while.

 

for $r = 0 to UBound($uniqueColors)-1
      for $h = 0 to UBound($imageData, $UBOUND_ROWS)-1
         if ($imageData[$h][0] = $uniqueColors[$r]) Then
           _ArrayAdd($holdData, $imageData[$h][1])
         EndIf
      Next
      FileWriteLine($file, $uniqueColors[$r] &" : "&   _ArrayToString($holdData  ,"," ))
      $holdData[0]
Next

Thanks for the suggestions / help!

 

Posted (edited)

Here another way :

#include <Array.au3>

Local $uniqueColors[2] = ["FF8822","00A2F1"]
Local $imageData[8][2] = [["FF8822","A2"],["00A2F1","A3"],["FF8822","B7"],["00A2F1","G4"],["FF8822","J10"],["FF8822","J11"],["FF8822","A10"],["00A2F1","H4"]]
Local $holdArray[UBound($uniqueColors)][UBound($imageData)+2]
For $r = 0 To UBound($uniqueColors) - 1
  $holdArray[$r][0] = 1
  $holdArray[$r][1] = $uniqueColors[$r]
  For $h = 0 To UBound($imageData) - 1
    If $imageData[$h][0] = $uniqueColors[$r] Then
      $holdArray[$r][0] += 1
      $holdArray[$r][$holdArray[$r][0]] = $imageData[$h][1]
    EndIf
  Next
Next

;_ArrayColDelete($holdArray, 0)  Depends if you want to keep counts or not
_ArrayDisplay($holdArray)

 

Edited by Nine

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
×
×
  • Create New...