Sign in to follow this  
Followers 0
strate

Match Similiar INI Sections

18 posts in this topic

I have no code just because I'm not sure where to start. I have a INI file that I wanna "sort/search" for similiar key values, example follows:

[123456]
Key1=part456
Key2=part457
Key3=part4580
Key4=part459
Key5=part4510

[654321]
Key1=part456
Key2=part457
Key3=part45
Key4=part4510
Key5=part44

[654987]
Key1=part46
Key2=part447
Key3=part4510
Key4=part40
Key5=part443

[987654]
Key1=part456
Key2=part47
Key3=part45
Key4=part40
Key5=part4

I need it to return a list that has the section names listed in the order of similiarity.

123456
654321
987654
654987

I have no idea how to start this. If someone has any ideas it would be great. I know how to do everyting except putting them into an order, this is the part that stops me.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites



I have no code just because I'm not sure where to start. I have a INI file that I wanna "sort/search" for similiar key values, example follows:

[123456]
Key1=part456
Key2=part457
Key3=part4580
Key4=part459
Key5=part4510

[654321]
Key1=part456
Key2=part457
Key3=part45
Key4=part4510
Key5=part44

[654987]
Key1=part46
Key2=part447
Key3=part4510
Key4=part40
Key5=part443

[987654]
Key1=part456
Key2=part47
Key3=part45
Key4=part40
Key5=part4

I need it to return a list that has the section names listed in the order of similiarity.

123456
654321
987654
654987

I have no idea how to start this. If someone has any ideas it would be great. I know how to do everyting except putting them into an order, this is the part that stops me.

Can't you just read the INI sections into an array and then sort the array with _arraysort() found in UDF array.au3

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Similarity of section name or key content?

And, could you tel us why you want this? It could bring up some unexpected ideas.

Share this post


Link to post
Share on other sites

Similarity of section name or key content?

And, could you tel us why you want this? It could bring up some unexpected ideas.

Similarity of key contents.

I manage production where I work, and need my forklift drivers to get product as fast as possible. Many of our production runs take the same parts. With this script I could manage the drivers better so that they don't pull the same part twice.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

just a sample, the part numbers are alphanumeric.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

The rest is left as an exercise..:)

FUnc testProductPartsSort()
   ;Get the sections. Lets pretend its like this
   Local $arr1[6] = [123456, "part456", "part457", "part4580", "part459", "part4510"]
   Local $arr2[6] = [654321, "part456", "part457", "part45", "part4510", "part44"]
   Local $arr3[6] = [654987, "part46", "part447", "part4510", "part40", "part443"]
   Local $arr4[6] = [987654, "part456", "part47", "part45", "part40", "part4"]
   Local $parts[100][2]
   $parts[0][0] = 0
   ArrUniqeCount($parts, $arr1)
   ArrUniqeCount($parts, $arr2)
   ArrUniqeCount($parts, $arr3)
   ArrUniqeCount($parts, $arr4)
   ConsoleWrite("SUM $arr1:=" & ArrUniqeSum($parts,$arr1) & @LF)
   ConsoleWrite("SUM $arr2:=" & ArrUniqeSum($parts,$arr2) & @LF)
   ConsoleWrite("SUM $arr3:=" & ArrUniqeSum($parts,$arr3) & @LF)
   ConsoleWrite("SUM $arr4:=" & ArrUniqeSum($parts,$arr4) & @LF)
   ArrPartsDump($parts)
EndFunc
Func ArrPartsDump($parts)
   Local $i
   ConsoleWrite($parts[0][0] & @LF)
   For $i = 1 to $parts[0][0]
      ConsoleWrite( $i & " : " & $parts[$i][1] & " - " & $parts[$i][0]& @LF)
   Next
EndFunc
Func ArrUniqeSum(ByRef $arr, ByRef $data)
   Local $dbg = 0
   If $dbg Then ConsoleWrite(@LF & ">")
   Local $sum, $i, $j
   For $i = 1 to UBound($data) -1 
      For $j = 1 to $arr[0][0]
         If $arr[$j][0] = $data[$i] Then 
            $sum += $arr[$j][1]
            If $dbg Then ConsoleWrite($sum)
            ExitLoop
         EndIf
      Next
      If $dbg Then ConsoleWrite(".")
   Next
   Return $sum
EndFunc
Func ArrUniqeCount(ByRef $arr, ByRef $data)
   ;NOTE: This is just brute force. So don't expect any performance
   
   Local $i, $j, $found = False
   ; NOTE: The 1 offset $data[0] is the section
   For $i = 1 to UBound($data) - 1
      For $j = 1 to $arr[0][0]
         If $arr[$j][0] = $data[$i] Then 
            $arr[$j][1] += 1
            $found = True
            ExitLoop
         EndIf
      Next
      If Not $found Then
         ;TODO: Check array size and resize 
         $arr[$arr[0][0]+1][0] = $data[$i]
         $arr[$arr[0][0]+1][1] = 1
         $arr[0][0] += 1
      EndIf
      $found = False
   Next
EndFunc

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Would you be able to explain the items that are wrote into the console?

I get the second part to the console the first is still throwing me off though.

Edited by strate

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

Each part gets a weight based on in how many sections it is listed in.

Summing the weights of each part in a product gives a value to sort the sections against.

This gives data that can be sorted on the value of SUM.

SUM $arr1:=10
SUM $arr2:=11
SUM $arr3:=8
SUM $arr4:=9

So it shoudl look like this after you have sorted the results

SUM $arr2:=11
SUM $arr1:=10
SUM $arr4:=9
SUM $arr3:=8

In my sample code $arrX[0] contains the section name.

How you identify the array containing the section data is up to you so I did not add any code for that.

This is just a dump to validate the array containing parts and their weights

13
1 : 3 - part456
2 : 2 - part457
3 : 1 - part4580
4 : 1 - part459
5 : 3 - part4510
6 : 2 - part45
7 : 1 - part44
8 : 1 - part46
9 : 1 - part447
10 : 2 - part40
11 : 1 - part443
12 : 1 - part47
13 : 1 - part4

Share this post


Link to post
Share on other sites

If I change each section so that it is as follows:

Local $arr1[6] = [123456, "part456", "part457", "part4580", "part459", "part4510"]
   Local $arr2[6] = [654321, "part456", "part457", "part4580", "part459", "part44"]
   Local $arr3[6] = [654987, "part456", "part457", "part4580", "part40", "part443"]
   Local $arr4[6] = [987654, "part456", "part47", "part45", "part40", "part4"]

Why are the first three $arrXs the same?

Thank you very much!! I would have never been able to code that, that clean.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

Nevermind I just looked at the second half of the console response and it is listed there as how to run it, sorry.


INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

Because The last elements have one occurrence and the second last has two and the rest is the same.

As you can see if you remove the first tree elements from each:

Local $arr1[3] = [123456, "part459", "part4510"]
   Local $arr2[3] = [654321, "part459", "part44"]
   Local $arr3[3] = [654987, "part40", "part443"]
   Local $arr4[6] = [987654, "part456", "part47", "part45", "part40", "part4"]

SUM $arr1:=3
SUM $arr2:=3
SUM $arr3:=3
SUM $arr4:=6

Share this post


Link to post
Share on other sites

Nevermind I just looked at the second half of the console response and it is listed there as how to run it, sorry.

Good..:)

Just don't forget to add array size checks before you put it in production. (See the TODO lines).

Share this post


Link to post
Share on other sites

Good..:)

Just don't forget to add array size checks before you put it in production. (See the TODO lines).

I'm sorry but what do you mean by size checks? what am I comparing them to?

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I'm sorry but what do you mean by size checks? what am I comparing them to?

never mind - I think I was wrong

EDIT changed post

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

I think he means to either add or subtract the number of indexes (sp?) needed for your code - but I am still learning.

I've been looking at it off and on the last couple hours and still can't seem to get it.

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites

I've been looking at it off and on the last couple hours and still can't seem to get it.

OK - maybe I got it but I am still not sure

$arr[0][0] = a value - the code looks through this even if the value is null - so the code would be faster if you only created the array to the size of your unknown and known values (parts) - does it fit (work)?


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

I'm sorry but what do you mean by size checks? what am I comparing them to?

The $parts array has a size of 100 items. The functions adding items to $parts should check if it exceeds the size of the array passed and resize (ReDim) the array adding say 50 (or 500 if your data is in that range) elements when a resize is requiered ($arr[0][0] = (UBound($arr, 1) -1). Take a look at the array tutorial in the wiki. There is a more elaborate explanation.

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