Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MBetterc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mbetter
MBetterc
Commits
03d2e1c8
Commit
03d2e1c8
authored
May 14, 2026
by
Your Name
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix settlement and report sync accounting
parent
b57de374
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
114 deletions
+205
-114
client.py
mbetterclient/api_client/client.py
+5
-4
games_thread.py
mbetterclient/core/games_thread.py
+68
-110
test_reports_sync_summary.py
test_reports_sync_summary.py
+48
-0
test_settlement_consistency.py
test_settlement_consistency.py
+84
-0
No files found.
mbetterclient/api_client/client.py
View file @
03d2e1c8
...
...
@@ -1746,6 +1746,7 @@ class ReportsSyncResponseHandler(ResponseHandler):
total_payin
=
0.0
total_payout
=
0.0
total_bets
=
0
unique_match_ids
=
set
()
for
bet
in
bets
:
# Ensure bet_details are loaded (handle lazy loading)
...
...
@@ -1756,15 +1757,15 @@ class ReportsSyncResponseHandler(ResponseHandler):
if
bet_details
:
total_payin
+=
sum
(
d
.
amount
for
d
in
bet_details
)
total_bets
+=
len
(
bet_details
)
# Add win amounts for winning bets (result is 'win', not 'won')
total_payout
+=
sum
(
d
.
win_amount
for
d
in
bet_details
if
d
.
result
==
'win'
)
unique_match_ids
.
update
(
d
.
match_id
for
d
in
bet_details
if
getattr
(
d
,
'match_id'
,
None
)
is
not
None
)
return
{
'total_payin'
:
float
(
total_payin
),
'total_payout'
:
float
(
total_payout
),
'net_profit'
:
float
(
total_payin
-
total_payout
),
'total_bets'
:
total_bets
,
'total_matches'
:
len
(
stat
s
)
'total_matches'
:
len
(
unique_match_id
s
)
}
def
_calculate_backoff_time
(
self
,
retry_count
:
int
)
->
int
:
...
...
@@ -3183,4 +3184,4 @@ class APIClient(ThreadedComponent):
return
shlex
.
join
(
cmd_parts
)
except
AttributeError
:
# Fallback for Python < 3.8
return
' '
.
join
(
shlex
.
quote
(
arg
)
for
arg
in
cmd_parts
)
\ No newline at end of file
return
' '
.
join
(
shlex
.
quote
(
arg
)
for
arg
in
cmd_parts
)
mbetterclient/core/games_thread.py
View file @
03d2e1c8
This diff is collapsed.
Click to expand it.
test_reports_sync_summary.py
0 → 100644
View file @
03d2e1c8
from
pathlib
import
Path
from
types
import
SimpleNamespace
from
mbetterclient.api_client.client
import
ReportsSyncResponseHandler
from
mbetterclient.core.message_bus
import
MessageBus
from
mbetterclient.database.manager
import
DatabaseManager
from
mbetterclient.database.models
import
BetDetailModel
,
BetModel
def
_build_handler
(
tmp_path
:
Path
):
db_path
=
tmp_path
/
"reports_sync_summary.db"
db_manager
=
DatabaseManager
(
str
(
db_path
))
assert
db_manager
.
initialize
()
handler
=
ReportsSyncResponseHandler
(
db_manager
=
db_manager
,
user_data_dir
=
str
(
tmp_path
),
api_client
=
SimpleNamespace
(
settings
=
SimpleNamespace
(
rustdesk_id
=
None
)),
message_bus
=
MessageBus
(),
)
return
handler
,
db_manager
def
test_calculate_summary_uses_settled_rows_and_unique_matches
(
tmp_path
):
handler
,
db_manager
=
_build_handler
(
tmp_path
)
session
=
db_manager
.
get_session
()
try
:
bet
=
BetModel
(
uuid
=
'bet-1'
,
fixture_id
=
'fixture-1'
,
paid
=
True
,
paid_out
=
False
)
session
.
add
(
bet
)
session
.
flush
()
session
.
add_all
([
BetDetailModel
(
bet_id
=
'bet-1'
,
match_id
=
10
,
match_number
=
1
,
outcome
=
'UNDER'
,
amount
=
10.0
,
win_amount
=
20.0
,
result
=
'win'
),
BetDetailModel
(
bet_id
=
'bet-1'
,
match_id
=
10
,
match_number
=
1
,
outcome
=
'OVER'
,
amount
=
15.0
,
win_amount
=
0.0
,
result
=
'lost'
),
BetDetailModel
(
bet_id
=
'bet-1'
,
match_id
=
11
,
match_number
=
2
,
outcome
=
'WIN1'
,
amount
=
25.0
,
win_amount
=
75.0
,
result
=
'win'
),
BetDetailModel
(
bet_id
=
'bet-1'
,
match_id
=
11
,
match_number
=
2
,
outcome
=
'KO1'
,
amount
=
5.0
,
win_amount
=
0.0
,
result
=
'cancelled'
),
])
session
.
commit
()
loaded_bet
=
session
.
query
(
BetModel
)
.
filter_by
(
uuid
=
'bet-1'
)
.
first
()
summary
=
handler
.
_calculate_summary
([
loaded_bet
],
stats
=
[])
assert
summary
[
'total_payin'
]
==
50.0
assert
summary
[
'total_payout'
]
==
95.0
assert
summary
[
'net_profit'
]
==
-
45.0
assert
summary
[
'total_bets'
]
==
3
assert
summary
[
'total_matches'
]
==
2
finally
:
session
.
close
()
db_manager
.
close
()
test_settlement_consistency.py
0 → 100644
View file @
03d2e1c8
from
pathlib
import
Path
from
mbetterclient.core.games_thread
import
GamesThread
from
mbetterclient.core.message_bus
import
MessageBus
from
mbetterclient.database.manager
import
DatabaseManager
from
mbetterclient.database.models
import
BetDetailModel
,
MatchModel
,
MatchOutcomeModel
def
_build_games_thread
(
tmp_path
:
Path
):
db_path
=
tmp_path
/
"settlement_consistency.db"
db_manager
=
DatabaseManager
(
str
(
db_path
))
assert
db_manager
.
initialize
()
message_bus
=
MessageBus
()
games_thread
=
GamesThread
(
"test_games_thread"
,
message_bus
,
db_manager
)
return
games_thread
,
db_manager
def
_seed_match
(
session
):
match
=
MatchModel
(
match_number
=
1
,
fighter1_township
=
'A'
,
fighter2_township
=
'B'
,
venue_kampala_township
=
'Kampala'
,
filename
=
'fixture.txt'
,
file_sha1sum
=
'fixture-sha1'
,
fixture_id
=
'fixture-1'
,
active_status
=
True
,
status
=
'done'
,
result
=
'WIN1'
,
under_over_result
=
'UNDER'
,
winning_outcomes
=
'["WIN1", "KO1"]'
,
)
session
.
add
(
match
)
session
.
flush
()
session
.
add_all
([
MatchOutcomeModel
(
match_id
=
match
.
id
,
column_name
=
'UNDER'
,
float_value
=
2.0
),
MatchOutcomeModel
(
match_id
=
match
.
id
,
column_name
=
'OVER'
,
float_value
=
3.0
),
MatchOutcomeModel
(
match_id
=
match
.
id
,
column_name
=
'WIN1'
,
float_value
=
4.0
),
MatchOutcomeModel
(
match_id
=
match
.
id
,
column_name
=
'KO1'
,
float_value
=
5.0
),
MatchOutcomeModel
(
match_id
=
match
.
id
,
column_name
=
'WIN2'
,
float_value
=
6.0
),
])
session
.
add_all
([
BetDetailModel
(
bet_id
=
'bet-under'
,
match_id
=
match
.
id
,
match_number
=
1
,
outcome
=
'UNDER'
,
amount
=
10.0
,
result
=
'pending'
),
BetDetailModel
(
bet_id
=
'bet-over'
,
match_id
=
match
.
id
,
match_number
=
1
,
outcome
=
'OVER'
,
amount
=
11.0
,
result
=
'pending'
),
BetDetailModel
(
bet_id
=
'bet-win1'
,
match_id
=
match
.
id
,
match_number
=
1
,
outcome
=
'WIN1'
,
amount
=
12.0
,
result
=
'pending'
),
BetDetailModel
(
bet_id
=
'bet-ko1'
,
match_id
=
match
.
id
,
match_number
=
1
,
outcome
=
'KO1'
,
amount
=
13.0
,
result
=
'pending'
),
BetDetailModel
(
bet_id
=
'bet-win2'
,
match_id
=
match
.
id
,
match_number
=
1
,
outcome
=
'WIN2'
,
amount
=
14.0
,
result
=
'pending'
),
])
session
.
commit
()
return
match
.
id
def
test_ensure_all_bets_resolved_settles_two_extraction_channels
(
tmp_path
):
games_thread
,
db_manager
=
_build_games_thread
(
tmp_path
)
session
=
db_manager
.
get_session
()
try
:
match_id
=
_seed_match
(
session
)
finally
:
session
.
close
()
games_thread
.
_ensure_all_bets_resolved
(
match_id
,
'WIN1'
)
session
=
db_manager
.
get_session
()
try
:
rows
=
{
row
.
outcome
:
row
for
row
in
session
.
query
(
BetDetailModel
)
.
filter_by
(
match_id
=
match_id
)
.
all
()
}
assert
rows
[
'UNDER'
]
.
result
==
'win'
assert
rows
[
'UNDER'
]
.
win_amount
==
20.0
assert
rows
[
'OVER'
]
.
result
==
'lost'
assert
rows
[
'OVER'
]
.
win_amount
==
0.0
assert
rows
[
'WIN1'
]
.
result
==
'win'
assert
rows
[
'WIN1'
]
.
win_amount
==
48.0
assert
rows
[
'KO1'
]
.
result
==
'win'
assert
rows
[
'KO1'
]
.
win_amount
==
65.0
assert
rows
[
'WIN2'
]
.
result
==
'lost'
assert
rows
[
'WIN2'
]
.
win_amount
==
0.0
assert
session
.
query
(
BetDetailModel
)
.
filter_by
(
match_id
=
match_id
,
result
=
'pending'
)
.
count
()
==
0
finally
:
session
.
close
()
db_manager
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment