Football Scores, In-Play Stats & Momentum via script, using an API. Version 2

Locked
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

As promised in the old thread , I've made some major changes to the code I posted to pull scores, stats and momentum data for matches from the SofaScore API

Old thread here:

viewtopic.php?f=50&t=24908

There were a few issues with the old code, primarily the pattern matching between the BF market names and the ones used by SofaScore. In many cases the team names used are completely different, site by site. The download code was also indiscriminate, in that data for all live matches was being pulled on each loop - not very efficient.

So, I hit on the idea of creating an input\output loop in Guardian via the Import & Export CSV Rules, using only markets where the baf was deployed. The code then knows which markets to query for on SofaScore plus it allows for much more complex pattern matching in the code.

I'm using a 3 part pattern match now.

1. 2 strings match exactly in both match names, ignoring commonly used words
2. An algo using the Damerau–Levenshtein distance to return the edit distance between the 2 strings. i.e how many single character edits are needed to match them
(https://en.wikipedia.org/wiki/Damerau-L ... n_distance for any bored enough to check :D )
3. A simple check on whether we have an age match i.e U19, U23 etc or a womens match. There are often matches played the same time\day where the only difference is the "U19", "(W)" in the market name

Where we have 2 matches that both pattern match, I'm then ranking on the shortest Damerau–Levenshtein distance to determine which is the correct match

A step through then looks like this:

1. Deploy baf to required Match Odds markets in Guardian using a coupon\filter etc
2. Run script in Scite (Same install instructions as Version 1)
3. Baf creates a file in C:\Temp\CSV_Output with the market name appended, when an inplay state is detected
4. Script picks up exported file name, deletes it and checks if there is a pattern matched market listed in SS and it doesnt already exist, if so it queries its Event ID and adds it to an array to be queried each loop, until match end
5. Script queries the API for each match with an EventID, and returns the score, stats and momentum data to the import CSV for Guardian to import
6. At match end (status set in the API), the market is deleted from our query list automatically

Notes:

You should be able to leave the script running 24/7 as it is self maintainiing. I left it on all weekend with no crashes. Just load and apply your baf to the days markets daily etc

Scores, stats and Momentum are pulled for each match automatically. Where SS are only publishing the score or a cut down set of data then only those will be created in the import CSV. Momentum and stats tend to only be available for major leagues

I've changed the default value of all the SV's to 0, so you may want to cater for those in your automation i.e Is Not 0

SV's returned can be checked in the exported CSV file but I've added in a few more for the Momentum Graph
Note: Graph is on a 0 axis so 0 to +99 is in favour of Home, 0 to -99 in favour of Away


5MinAvgPressure (Average of last 5 mins)
10MinAvgPressure (Average of last 5 mins)
MatchAvgPressure (Average of Entire match)
Momentum1 (Current Momentum, 1m interval)
Momentum2 (Current Momentum -1, 1m interval)
Momentum3 etc
Momentum4
Momentum5
Time = 0
5MinPeakResult (Highest Momentum value in last 5m)
10MinPeakResult (Highest Momentum value in last 10m)
5MinLowResult (Lowest Momentum value in last 5m)
10MinLowResult (Lowest Momentum value in last 10m)

1HHighResult1 (at 45m, this returns the highest + peak in the 1st half)
1HHighResult2 (at 45m, this returns the 2nd highest + peak in the 1st half)
1HLowResult1 (at 45m, this returns the lowest - peak in the 1st half)
1HLowResult2 (at 45m, this returns the 2nd lowest - peak in the 1st half)

I put the last 4 in so the automation would have a handle on decent first half pressure for each team, ready for any 2nd half entries, without having to refer to individual stats

Note: The SV for Time is only available where there is a momentum graph as its uses the number of datapoints for the graph. It is more accurate than using BA in play time however as the 2nd half always starts on minute 46, irrelevant of 1st half ET

IMPORTANT:You need to create the following directory C:\Temp\CSV_Output manually, prior to using the baf\script for the first time

I've included an experimental 2nd Half LTD baf to demo the SV's created. No idea how this one plays out in real life. It does however , populate the watch list with the time, score and key stats (if available) via alert rules, so you can see at a glance whats happening in the game
Capture.JPG
I ran this all weekend and the pattern matching checked out on every match I looked at, though there were so many games I cant guarantee every one was 100% - too much work for one person lol

Anyway, hope this is useful. I've enjoyed the challenge of creating it and learnt quite a bit along the way

Cheers

Stu

Code: Select all


#include <Inet.au3>
#include <json.au3>
;~ #include <Array.au3>
#include <String.au3>
#include <File.au3>
#include <Date.au3>
#include <math.au3>



Local $HomeString, $AwayTeam1, $Momentum, $Markets, $MarketList[0][20], $aScoreArray[0][10], $EventID[0]
$Update = 0

$OutFiles = "C:\Temp\CSV_Output"


While 1

	;$Update = $Update + 1

	Local $aMyTable

	;Read BA Output files to an array
	$aFileList = _FileListToArray($OutFiles, "*")

	;If new files found, process them
	If UBound($aFileList) > 0 Then

		For $x = 1 To UBound($aFileList) - 1
			$MarketName = StringReplace($aFileList[$x], "Output_", "")
			$MarketName = StringReplace($MarketName, ".csv", "")
			_ArraySearch($MarketList, $MarketName)
			If @error Then
				_ArrayAdd($MarketList, $MarketName)
			EndIf
			FileDelete("C:\Temp\CSV_Output\" & $aFileList[$x])
		Next

		$URL = "https://api.sofascore.com/api/v1/sport/football/events/live"
		$data = _INetGetSource($URL)
		;Json_Dump($data)
		$object = json_decode($data)
		Local $Count = Json_Get($object, '.events')
		;MsgBox("", "", "Wait")

		For $d = UBound($MarketList) - 1 To 0 Step -1

			;If we dont have a EventId already, find it
			If $MarketList[$d][1] = "" Then

				For $i = 0 To UBound($Count) - 1

					Local $aFinalArray[0][4]
					$HomeTeam = Json_Get($object, '.events' & '[' & $i & '].homeTeam.name')
					$AwayTeam1 = Json_Get($object, '.events' & '[' & $i & '].awayTeam.name')

					Local $SplitTeams = _ReturnTeams()
					$Matched = 0

					For $t = 0 To UBound($SplitTeams) - 1
						If StringInStr($MarketList[$d][0], $SplitTeams[$t]) Then
							$Matched = $Matched + 1
						EndIf
					Next

					If $Matched >= 2 Then
						_ArrayAdd($aFinalArray, $MarketList[$d][0] & "|" & $HomeTeam & " v " & $AwayTeam1 & "|" & $i)
					EndIf

					If UBound($aFinalArray) > 0 Then

						For $f = 0 To UBound($aFinalArray) - 1
							$FuzzyResult = _StringFuzzyCompareDamLevDist((StringReplace($aFinalArray[$f][0], " - Match Odds", "")), _StringReplaceAccent($aFinalArray[$f][1]))
							$aFinalArray[$f][3] = $FuzzyResult
						Next

						For $f = 0 To UBound($aFinalArray) - 1
							If StringInStr($aFinalArray[$f][0], "(W)") And StringInStr($aFinalArray[$f][1], "(W)") = 0 Then
								If StringInStr($aFinalArray[$f][1], " W ") = 0 Then
									$aFinalArray[$f][3] = 100
									;MsgBox("", "", "1")
								EndIf
							EndIf


							If StringInStr($aFinalArray[$f][1], "(W)") And StringInStr($aFinalArray[$f][0], "(W)") = 0 Then
								If StringInStr($aFinalArray[$f][0], " W ") = 0 Then
									$aFinalArray[$f][3] = 100
									;MsgBox("", "", "2")
								EndIf
							EndIf

							If StringInStr($aFinalArray[$f][1], " W ") And StringInStr($aFinalArray[$f][0], "(W)") = 0 Then
								If StringInStr($aFinalArray[$f][0], " W ") = 0 Then
									$aFinalArray[$f][3] = 100
									;MsgBox("", "", "3")
								EndIf
							EndIf

							If StringLen($aFinalArray[$f][0]) = 3 And StringLeft($aFinalArray[$f][0], 1) = "U" And StringInStr($aFinalArray[$f][0], $aFinalArray[$f][1]) = 0 Then
								$aFinalArray[$f][3] = 100
								;MsgBox("", "", "4")
							EndIf

							If StringInStr($aFinalArray[$f][1],"U16") And StringInStr($aFinalArray[$f][0],"U16") = 0 Then
								$aFinalArray[$f][3] = 100
								;MsgBox("", "", "4")
							EndIf

							If StringInStr($aFinalArray[$f][1],"U17") And StringInStr($aFinalArray[$f][0],"U17") = 0 Then
								$aFinalArray[$f][3] = 100
								;MsgBox("", "", "4")
							EndIf

							If StringInStr($aFinalArray[$f][1],"U19") And StringInStr($aFinalArray[$f][0],"U19") = 0 Then
								$aFinalArray[$f][3] = 100
								;MsgBox("", "", "4")
							EndIf

							If StringInStr($aFinalArray[$f][1],"U20") And StringInStr($aFinalArray[$f][0],"U20") = 0 Then
								$aFinalArray[$f][3] = 100
								;MsgBox("", "", "4")
							EndIf

							If StringInStr($aFinalArray[$f][1],"U21") And StringInStr($aFinalArray[$f][0],"U21") = 0 Then
								$aFinalArray[$f][3] = 100
								;MsgBox("", "", "4")
							EndIf

							If StringInStr($aFinalArray[$f][1],"U23") And StringInStr($aFinalArray[$f][0],"U23") = 0 Then
								$aFinalArray[$f][3] = 100
								;MsgBox("", "", "4")
							EndIf



						Next


						;Sort results array to find closest match. If only one match, check fuzzy result is OK
						_ArraySort($aFinalArray, 0, 0, 0, 3)
						;_ArrayDisplay($aFinalArray)

						If $aFinalArray[0][3] < 18 Or (UBound($aFinalArray) = 1 And $aFinalArray[0][3] < 22) Then
							$MarketList[$d][1] = Json_Get($object, '.events' & '[' & $aFinalArray[0][2] & '].id')
						EndIf
					EndIf
				Next
			EndIf
		Next
	EndIf


	;Loop through known markets and pull the stats

	;If we have markets, process them
	If UBound($MarketList) > 0 Then

		For $f = UBound($MarketList) - 1 To 0 Step -1
			If $MarketList[$f][1] = "" Then
				;If no ID matched then remove the market
				_ArrayDelete($MarketList, $f)
			EndIf
		Next

		;Create a new temp file
		FileDelete("C:\Temp\Sofascore_Final_Build.csv")
		FileWriteLine("C:\Temp\Sofascore_Final_Build.csv", "1")
		$File = FileOpen("C:\Temp\Sofascore_Final_Build.csv", 1)

		For $i = UBound($MarketList) - 1 To 0 Step -1

			$URL = "https://api.sofascore.com/api/v1/event/" & $MarketList[$i][1]
			$data = _INetGetSource($URL)
			;Json_Dump($data)
			$object = json_decode($data)

			If Json_Get($object, '.event.status.description') <> "Ended" Then

				;MsgBox("", "", "Wait")

				;Calls function to filter out unwanted match types (Women, U19 etc)
				;If _MatchCheck(Json_Get($object, '.events.tournament.name')) = "Yes" Then


				;Set starting values for Score
				$HomeScore = 0
				$AwayScore = 0

				$HomeScore = Json_Get($object, '.event.homeScore.current')
				$AwayScore = Json_Get($object, '.event.awayScore.current')


				$BuildString = $MarketList[$i][0] & ",*,*,*,E,HomeScore," & $HomeScore & ",E,AwayScore," & $AwayScore & ","
				_GetStats()
				_GetPressure()

				FileWriteLine($File, $BuildString)
				ConsoleWrite(_NowTime() & " " & $MarketList[$i][0] & @CRLF)
			Else
				;Remove from market list and stop gathering data if match ended
				_ArrayDelete($MarketList, $i)
			EndIf

		Next

		FileClose($File)
		;Copy & Overwrite our temp file to master file in one hit (prevents file read/write contention between BA & script)
		FileCopy("C:\Temp\Sofascore_Final_Build.csv", "C:\Temp\Sofascore_Final.csv", 1)
	EndIf

	Sleep(10000) ;00 seconds

WEnd

Func _GetStats()

	$URL = "https://api.sofascore.com/api/v1/event/" & $MarketList[$i][1] & "/statistics"
	$data3 = _INetGetSource($URL)

	If $data3 <> "" Then

		;Set starting values for Stats
		$PossessionHome = 0
		$PossessionAway = 0
		$SOTHome = 0
		$SOTAway = 0
		$SOFFTHome = 0
		$SOFFTAway = 0
		$CornersHome = 0
		$CornersAway = 0
		$BigChanceHome = 0
		$BigChanceAway = 0
		$PassesHome = 0
		$PassesAway = 0

		;#########Uncomment the next line (remove the ";") to view available stats in the console on each loop
		;Json_Dump($data3)

		$object3 = json_decode($data3)

		Local $GroupCount = Json_Get($object3, '.statistics[0].groups')

		For $c = 0 To UBound($GroupCount)

			If Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].name') = "Ball possession" Then
				$PossessionHome = StringReplace(Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].home '), "%", "")
				$PossessionAway = StringReplace(Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].away'), "%", "")
				;MsgBox("", "", $PossessionHome & ":" & $PossessionAway)
			EndIf

			If Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[1].name') = "Shots on target" Then
				$SOTHome = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[1].home')
				$SOTAway = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[1].away')
				;MsgBox("On", "On", $SOTHome & ":" & $SOTAway)
			EndIf

			If Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[2].name') = "Shots off target" Then
				$SOFFTHome = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[2].home')
				$SOFFTAway = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[2].away')
				;MsgBox("Off", "Off", $SOFFTHome & ":" & $SOFFTAway)
			EndIf

			If Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].name') = "Corner kicks" Then
				$CornersHome = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].home')
				$CornersAway = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].away')
				;MsgBox("Corners", "Corners", $CornersHome & ":" & $CornersAway)
			EndIf

			If Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].name') = "Big chances" Then
				$BigChanceHome = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].home')
				$BigChanceAway = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].away')
				;MsgBox("Chance", "Chance", $BigChanceHome & ":" & $BigChanceAway)
			EndIf

			If Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].name') = "Passes" Then
				$PassesHome = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].home')
				$PassesAway = Json_Get($object3, '.statistics[0].groups[' & $c & '].statisticsItems[0].away')
				;MsgBox("Passes", "Passes", $PassesHome & ":" & $PassesAway)
			EndIf

		Next


		$BuildString = $BuildString & "E,PossessionHome," & $PossessionHome & ",E,PossessionAway," & $PossessionAway & ","
		$BuildString = $BuildString & "E,SOTHome," & $SOTHome & ",E,SOTAway," & $SOTAway & ","
		$BuildString = $BuildString & "E,SOFFTHome," & $SOFFTHome & ",E,SOFFTAway," & $SOFFTAway & ","
		$BuildString = $BuildString & "E,CornersHome," & $CornersHome & ",E,CornersAway," & $CornersAway & ","
		$BuildString = $BuildString & "E,BigChanceHome," & $BigChanceHome & ",E,BigChanceAway," & $BigChanceAway & ","
		$BuildString = $BuildString & "E,PassesHome," & $PassesHome & ",E,PassesAway," & $PassesAway & ","

	EndIf

EndFunc   ;==>_GetStats


Func _GetPressure()

	$URL = "https://api.sofascore.com/api/v1/event/" & $MarketList[$i][1] & "/graph"
	$data2 = _INetGetSource($URL)
	$object2 = json_decode($data2)

	If $data2 <> "" Then

		;Set zero starting values for Graph
		$5MinAvgPressure = 0
		$10MinAvgPressure = 0
		$MatchAvgPressure = 0
		$Momentum1 = 0
		$Momentum2 = 0
		$Momentum3 = 0
		$Momentum4 = 0
		$Momentum5 = 0
		$Time = 0
		$5MinPeakResult = 0
		$10MinPeakResult = 0
		$5MinLowResult = 0
		$10MinLowResult = 0
		$1HHighResult1 = 0
		$1HHighResult2 = 0
		$1HLowResult1 = 0
		$1HLowResult2 = 0


		Local $Count = Json_Get($object2, '.graphPoints')
		$Time = UBound($Count) - 1

		If $Time > 10 Then

			Local $a5MinPeak[0], $a10MinPeak[0], $a1HMinPeak[0]

			For $w = 1 To 5
				_ArrayAdd($a5MinPeak, Json_Get($object2, '.graphPoints' & '[' & UBound($Count) - $w & '].value'))
			Next

			For $w = 1 To 10
				_ArrayAdd($a10MinPeak, Json_Get($object2, '.graphPoints' & '[' & UBound($Count) - $w & '].value'))
			Next


			If $Time > 45 And UBound($a1HMinPeak) = 0 Then
				For $a = 1 To 45
					_ArrayAdd($a1HMinPeak, Json_Get($object2, '.graphPoints' & '[' & $a & '].value'))
				Next
				_ArraySort($a1HMinPeak, 1)
				;_ArrayDisplay($a1HMinPeak)
				$1HHighResult1 = $a1HMinPeak[0]
				$1HHighResult2 = $a1HMinPeak[1]
				$1HLowResult1 = $a1HMinPeak[UBound($a1HMinPeak) - 1]
				$1HLowResult2 = $a1HMinPeak[UBound($a1HMinPeak) - 2]
			EndIf

			_ArraySort($a5MinPeak, 1)
			_ArraySort($a10MinPeak, 1)

			$5MinPeakResult = $a5MinPeak[0]
			$5MinLowResult = $a5MinPeak[4]
			$10MinPeakResult = $a10MinPeak[0]
			$10MinLowResult = $a10MinPeak[9]

			$Momentum1 = Json_Get($object2, '.graphPoints' & '[' & UBound($Count) - 1 & '].value')
			$Momentum2 = Json_Get($object2, '.graphPoints' & '[' & UBound($Count) - 2 & '].value')
			$Momentum3 = Json_Get($object2, '.graphPoints' & '[' & UBound($Count) - 3 & '].value')
			$Momentum4 = Json_Get($object2, '.graphPoints' & '[' & UBound($Count) - 4 & '].value')
			$Momentum5 = Json_Get($object2, '.graphPoints' & '[' & UBound($Count) - 5 & '].value')

			;5 Min Average
			$GraphTotal = 0
			$GraphCount = 0
			For $y = UBound($Count) - 1 To 0 Step -1
				$Convert = StringReplace(Json_Get($object2, '.graphPoints' & '[' & $y & '].value'), "-", "")
				$Convert = Json_Get($object2, '.graphPoints' & '[' & $y & '].value')
				$GraphTotal = $GraphTotal + $Convert
				$GraphCount = $GraphCount + 1

				If $GraphCount = 5 Then
					$GraphAverage = 0
					$GraphAverage = Round($GraphTotal / $GraphCount)
					If StringInStr($GraphAverage, "IND") Then
						$5MinAvgPressure = 0
					Else
						$5MinAvgPressure = $GraphAverage
					EndIf
				EndIf

				If $GraphCount = 10 Then
					$GraphAverage = 0
					$GraphAverage = Round($GraphTotal / $GraphCount)
					If StringInStr($GraphAverage, "IND") Then
						$10MinAvgPressure = 0
					Else
						$10MinAvgPressure = $GraphAverage
					EndIf

					ExitLoop
				EndIf
			Next

			;Match Average
			$GraphTotal = 0
			$GraphCount = 0
			For $y = UBound($Count) - 1 To 0 Step -1
				$Convert = StringReplace(Json_Get($object2, '.graphPoints' & '[' & $y & '].value'), "-", "")
				$Convert = Json_Get($object2, '.graphPoints' & '[' & $y & '].value')
				$GraphTotal = $GraphTotal + $Convert
				$GraphCount = $GraphCount + 1
			Next

			$GraphAverage = 0
			$GraphAverage = Round($GraphTotal / $GraphCount)
			If StringInStr($GraphAverage, "IND") Then
				$MatchAvgPressure = 0
			Else
				$MatchAvgPressure = $GraphAverage
			EndIf


		EndIf


		$BuildString = $BuildString & "E,Momentum1," & $Momentum1 & ",E,Momentum2," & $Momentum2 & ",E,Momentum3," & $Momentum3 & ",E,Momentum4," & $Momentum4 & ",E,Momentum5," & $Momentum5 & ","
		$BuildString = $BuildString & "E,5MinAvgPressure," & $5MinAvgPressure & ",E,10MinAvgPressure," & $10MinAvgPressure & ",E,MatchAvgPressure," & $MatchAvgPressure & ",E,Time," & $Time
		$BuildString = $BuildString & ",E,5MinPeak," & $5MinPeakResult & ",E,10MinPeak," & $10MinPeakResult & ",E,5MinLow," & $5MinLowResult & ",E,10MinLow," & $10MinLowResult & ",E,Time," & $Time
		$BuildString = $BuildString & ",E,1HHighResult1," & $1HHighResult1 & ",E,1HHighResult2," & $1HHighResult2 & ",E,1HLowResult1," & $1HLowResult1 & ",E,1HLowResult2," & $1HLowResult2



	EndIf
EndFunc   ;==>_GetPressure




Func _MatchCheck($Word)
	If StringInStr($Word, "Esports") Then
		Return "No"
		;ElseIf StringInStr($Word, "Friend") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "Women") Then
		;Return "No"
		;ElseIf StringInStr($Word, "(W)") Then
		;Return "No"
		;ElseIf StringInStr($Word, "Reserves") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "U16") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "U17") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "Youth") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "U19") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "U21") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "U20") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "Cup") Then
		;	Return "No"
		;ElseIf StringInStr($Word, "Copa") Then
		;	Return "No"
	Else
		Return "Yes"
	EndIf
EndFunc   ;==>_MatchCheck





Func _ReturnTeams()

	Local $TeamArray = StringSplit($HomeTeam, " ", 2)
	Local $AwayTeam = StringSplit($AwayTeam1, " ", 2)
	Local $TeamFinalFunc[0]
	_ArrayConcatenate($TeamArray, $AwayTeam)

	For $f = 0 To UBound($TeamArray) - 1
		$TeamArray[$f] = StringStripWS($TeamArray[$f], 8)
		$TeamArray[$f] = _StringReplaceAccent($TeamArray[$f])
	Next

	;_ArrayDisplay($TeamArray)


	For $x = 0 To UBound($TeamArray) - 1
		If StringLen($TeamArray[$x]) > 3 And _NameCheck($TeamArray[$x]) = "Yes" Then
			_ArrayAdd($TeamFinalFunc, StringLeft($TeamArray[$x], 6))
		EndIf
	Next

	;_ArrayDisplay($TeamFinalFunc)


	Return ($TeamFinalFunc)


EndFunc   ;==>_ReturnTeams

Func _StringReplaceAccent($sString)
	Local $exp, $rep
	Local $Pattern[29][2] = [ _
			["[ÀÁÂÃÅÆ]", "A"], ["[àáâãåąə]", "a"], ["Ä", "Ae"], ["[æä]", "ae"], _
			["Þ", "B"], ["þ", "b"], _
			["ÇĆ", "C"], ["[çćč]", "c"], _
			["[ÈÉÊË]", "E"], ["[èéêë]", "e"], _
			["[ÌÍÎÏ]", "I"], ["[ìíîïı]", "i"], _
			["Ñ", "N"], ["ñ", "n"], _
			["[ÒÓÔÕÖØ]", "O"], ["[ðòóôõöø]", "o"], _
			["ř", "r"], _
			["[ŠŚ]", "S"], ["[šş]", "s"], _
			["ß", "Ss"], _
			["Ț", "T"], _
			["[ÙÚÛ]", "U"], ["[ùúû]", "u"], ["Ü", "U"], ["ü", "ue"], _
			["Ý", "Y"], ["[ýýÿ]", "y"], _
			["Ž", "Z"], ["ž", "z"]]

	For $i = 0 To (UBound($Pattern) - 1)
		$exp = $Pattern[$i][0]
		If $exp = "" Then ContinueLoop
		$rep = $Pattern[$i][1]

		$sString = StringRegExpReplace($sString, $exp, $rep)
		If @error == 0 And @extended > 0 Then
			;ConsoleWrite($sString & @LF & "--> " & $exp & @LF)
		EndIf
	Next

	Return $sString
EndFunc   ;==>_StringReplaceAccent


Func _NameCheck($Word)
	If StringInStr($Word, "http") Then
		Return "No"
	ElseIf StringInStr($Word, "vs") Then
		Return "No"
	ElseIf StringInStr($Word, "Hapoel") Then
		Return "No"
	ElseIf StringInStr($Word, "Club") Then
		Return "No"
	ElseIf StringInStr($Word, "City") Then
		Return "No"
	ElseIf StringInStr($Word, "Town") Then
		Return "No"
	ElseIf StringInStr($Word, "U23") Then
		Return "No"
	ElseIf StringInStr($Word, "Utd") Then
		Return "No"
	ElseIf StringInStr($Word, "VPV") Then
		Return "No"
	ElseIf StringInStr($Word, "VPS") Then
		Return "No"
	ElseIf StringInStr($Word, "Citizen") Then
		Return "No"
	ElseIf StringInStr($Word, "Club") Then
		Return "No"
	ElseIf StringInStr($Word, "TSV") Then
		Return "No"
	ElseIf StringInStr($Word, "TSG") Then
		Return "No"
	ElseIf StringInStr($Word, "Tblisi") Then
		Return "No"
	ElseIf StringInStr($Word, "Women") Then
		Return "No"
	ElseIf StringInStr($Word, "U16") Then
		Return "No"
	ElseIf StringInStr($Word, "U17") Then
		Return "No"
	ElseIf StringInStr($Word, "U19") Then
		Return "No"
	ElseIf StringInStr($Word, "U21") Then
		Return "No"
	ElseIf StringInStr($Word, "U23") Then
		Return "No"
	ElseIf StringInStr($Word, "U20") Then
		Return "No"
	ElseIf StringInStr($Word, "(W)") Then
		Return "No"
	ElseIf StringInStr($Word, "United") Then
		Return "No"
	ElseIf StringInStr($Word, "Maccabi") Then
		Return "No"
	ElseIf StringInStr($Word, "Viit") Then
		Return "No"
	ElseIf StringInStr($Word, "USD") Then
		Return "No"
	ElseIf StringInStr($Word, "Beitar") Then
		Return "No"
	ElseIf StringInStr($Word, "Bucu") Then
		Return "No"
	ElseIf StringInStr($Word, "Buch") Then
		Return "No"
	ElseIf StringInStr($Word, "FCV") Then
		Return "No"
	ElseIf StringInStr($Word, "Spart") Then
		Return "No"
	ElseIf StringInStr($Word, "Unirea") Then
		Return "No"
	ElseIf StringInStr($Word, "Dinamo") Then
		Return "No"
	ElseIf StringInStr($Word, "Dynamo") Then
		Return "No"
	ElseIf StringInStr($Word, "Tblis") Then
		Return "No"
	ElseIf StringInStr($Word, "Youth") Then
		Return "No"
	ElseIf StringInStr($Word, "Atletico") Then
		Return "No"
	ElseIf StringInStr($Word, "Athletic") Then
		Return "No"
	ElseIf StringInStr($Word, "Real") Then
		Return "No"
	ElseIf StringInStr($Word, "Melbo") Then
		Return "No"
	ElseIf StringInStr($Word, "Ironi") Then
		Return "No"
	ElseIf StringInStr($Word, "Maccabi") Then
		Return "No"
	ElseIf StringInStr($Word, "Tel") Then
		Return "No"
	ElseIf StringInStr($Word, "Aviv") Then
		Return "No"
	ElseIf StringInStr($Word, "Ramat") Then
		Return "No"
	Else
		Return "Yes"
	EndIf
EndFunc   ;==>_NameCheck


Func _StringFuzzyCompareDamLevDist($sString1, $sString2)
	Local $iString1Len = StringLen($sString1)
	Local $iString2Len = StringLen($sString2)
	Select
		Case $iString1Len = 0
			SetError(1)
			Return -1
		Case $iString2Len = 0
			SetError(2)
			Return -1
	EndSelect

	Local $aiMatrix[$iString1Len + 1][$iString2Len + 1]
	Local $iString1Loop, $iString2Loop, $iCost

	For $iString1Loop = 0 To $iString1Len
		$aiMatrix[$iString1Loop][0] = $iString1Loop
	Next
	For $iString2Loop = 1 To $iString2Len
		$aiMatrix[0][$iString2Loop] = $iString2Loop
	Next

	For $iString1Loop = 1 To $iString1Len
		For $iString2Loop = 1 To $iString2Len
			If StringMid($sString1, $iString1Loop, 1) = StringMid($sString2, $iString2Loop, 1) Then
				$iCost = 0
			Else
				$iCost = 1
			EndIf
			$aiMatrix[$iString1Loop][$iString2Loop] = _Min(_Min($aiMatrix[$iString1Loop - 1][$iString2Loop] + 1, $aiMatrix[$iString1Loop][$iString2Loop - 1] + 1), $aiMatrix[$iString1Loop - 1][$iString2Loop - 1] + $iCost)
			If ($iString1Loop > 1) And ($iString2Loop > 1) And (StringMid($sString1, $iString1Loop, 1) = StringMid($sString2, $iString2Loop - 1, 1)) And (StringMid($sString1, $iString1Loop - 1, 1) = StringMid($sString2, $iString2Loop, 1)) Then
				$aiMatrix[$iString1Loop][$iString2Loop] = _Min($aiMatrix[$iString1Loop][$iString2Loop], $aiMatrix[$iString1Loop - 2][$iString2Loop - 2] + $iCost)
			EndIf
		Next
	Next
	Return $aiMatrix[$iString1Len][$iString2Len]
EndFunc   ;==>_StringFuzzyCompareDamLevDist





SS LTD 2nd Half V1.1.baf
You do not have the required permissions to view the files attached to this post.
User avatar
Euler
Posts: 24701
Joined: Wed Nov 10, 2010 1:39 pm
Location: Bet Angel HQ

Many thanks for posting this. If you need the moderators to amend or lock threads let us know.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Euler wrote:
Mon Mar 14, 2022 12:01 pm
Many thanks for posting this. If you need the moderators to amend or lock threads let us know.
Thanks Peter, will do
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Forgot to mention, the script will list all matches currently being monitored in the scite console, and the time of the check

Capture.JPG
if all working correctly your watch List should look like this:

Capture.JPG

Where the Basak match has stats data, and the PSM match only has the score
You do not have the required permissions to view the files attached to this post.
humanoid769
Posts: 91
Joined: Fri Nov 09, 2018 11:22 am

Excellent post thank you .. what version did you create the baf file as I can't import it into 1.58.0

Also I'm not quite clear on what the baf file attached to the Match odds should be doing..please advise

Thanks
User avatar
Frogmella
Posts: 220
Joined: Mon May 30, 2011 2:44 pm
Location: Towcester

Yep. The .baf file is not compatible with Bet Angel 1.58.

Does the market you attach it to matter? I would strip out the trading rules, I just want the stats in the overs/unders markets. I suppose the SV's are event shared so I could call them into Overs/Unders?

Once again, many, many thanks for doing this work.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

humanoid769 wrote:
Mon Mar 14, 2022 2:56 pm
Excellent post thank you .. what version did you create the baf file as I can't import it into 1.58.0

Also I'm not quite clear on what the baf file attached to the Match odds should be doing..please advise

Thanks
I'm using the latest beta 1.5.9.0_b1 so wont import in anything less than that I'm afraid

The baf is just a sample LTD file I knocked up to demo. If you only want the data in and out then you can delete everything but the 2 import/export CSV lines. Both of these need to be there for the script to function
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Frogmella wrote:
Mon Mar 14, 2022 4:31 pm
Yep. The .baf file is not compatible with Bet Angel 1.58.

Does the market you attach it to matter? I would strip out the trading rules, I just want the stats in the overs/unders markets. I suppose the SV's are event shared so I could call them into Overs/Unders?

Once again, many, many thanks for doing this work.
It's written to pattern match on the Match Odds markets but the SV's created are for the Event. So, you can load the MO markets and apply the baf, plus any others you want to trade in and use the SV's in other markets for that event
Its a bit of a headache to pattern match for all possible market names I'm afraid, so I went for MO as the most likely
Archery1969
Posts: 3193
Joined: Thu Oct 24, 2019 8:25 am
Location: Newport

Not sure this is working for me again.

The csv files are empty but everything is running. Not showing anything for the Crystal Palace v Man City game ?
You do not have the required permissions to view the files attached to this post.
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

Archery1969 wrote:
Mon Mar 14, 2022 8:24 pm
Not sure this is working for me again.

The csv files are empty but everything is running. Not showing anything for the Crystal Palace v Man City game ?
Should definitely be ok on that match. I have data.

Can you post the guardian log from that match, and check the content of c:\temp\output_csv

You've done "Tools-go" in Scite to run the file ?
Archery1969
Posts: 3193
Joined: Thu Oct 24, 2019 8:25 am
Location: Newport

sniffer66 wrote:
Mon Mar 14, 2022 8:34 pm
Archery1969 wrote:
Mon Mar 14, 2022 8:24 pm
Not sure this is working for me again.

The csv files are empty but everything is running. Not showing anything for the Crystal Palace v Man City game ?
Should definitely be ok on that match. I have data.

Can you post the guardian log from that match, and check the content of c:\temp\output_csv

You've done "Tools-go" in Scite to run the file ?
says cant find the file or its locked but it is in that directory.

4/03/2022 20:23:38: [G_Auto 1] : Unable to read file: C:\Temp\Sofascore_Final.csv. Check file exists and isn't locked.
User avatar
MemphisFlash
Posts: 2126
Joined: Fri May 16, 2014 10:12 pm
Location: Leicester

same message here
sniffer66
Posts: 1666
Joined: Thu May 02, 2019 8:37 am

You'll get that message now and again as it tries to read and write at the same time. But should only be rarely. Are you getting it all the time ie every refresh ?
Archery1969
Posts: 3193
Joined: Thu Oct 24, 2019 8:25 am
Location: Newport

sniffer66 wrote:
Mon Mar 14, 2022 8:53 pm
You'll get that message now and again as it tries to read and write at the same time. But should only be rarely. Are you getting it all the time ie every refresh ?
Yes, the log in guardian is full of the same message.
User avatar
MemphisFlash
Posts: 2126
Joined: Fri May 16, 2014 10:12 pm
Location: Leicester

Capture.JPG
You do not have the required permissions to view the files attached to this post.
Locked

Return to “Bet Angel Automation - Football”