Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Babyfut
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PR-Baby-A18
Babyfut
Commits
283f06ef
Commit
283f06ef
authored
Dec 10, 2018
by
Antoine Lima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More privacy measure
+ Renamed onRasp to ON_RASP
parent
4cfbe44c
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
108 additions
and
101 deletions
+108
-101
babyfut.py
babyfut.py
+10
-3
core/database.py
core/database.py
+13
-2
core/input.py
core/input.py
+5
-5
core/player.py
core/player.py
+34
-23
core/replay.py
core/replay.py
+6
-6
modules/leaderboard.py
modules/leaderboard.py
+8
-9
translations/babyfut_fr.ts
translations/babyfut_fr.ts
+27
-48
ui/mainwin.py
ui/mainwin.py
+1
-1
ui/playerlist.ui
ui/playerlist.ui
+4
-4
No files found.
babyfut.py
View file @
283f06ef
...
...
@@ -5,11 +5,10 @@
"""
import
os
OnRasp
=
os
.
uname
()[
1
]
==
'raspberrypi'
from
os.path
import
dirname
,
abspath
,
join
,
exists
import
glob
import
sys
import
logging
from
os.path
import
dirname
,
abspath
,
join
from
PyQt5
import
QtCore
from
PyQt5.QtWidgets
import
QMainWindow
,
QApplication
...
...
@@ -27,6 +26,9 @@ def getMainWin():
return
widget
return
None
ON_RASP
=
os
.
uname
()[
1
]
==
'raspberrypi'
IMG_PATH
=
getContent
(
'img'
)
if
__name__
==
'__main__'
:
__package__
=
'Babyfut'
from
Babyfut.ui.mainwin
import
MainWin
...
...
@@ -43,6 +45,9 @@ if __name__=='__main__':
app
=
QApplication
(
sys
.
argv
)
myapp
=
MainWin
()
if
not
exists
(
IMG_PATH
):
os
.
makedirs
(
IMG_PATH
)
if
ReplayThread
.
isCamAvailable
():
threadReplay
=
ReplayThread
(
Side
.
Left
)
threadReplay
.
start
()
...
...
@@ -65,3 +70,5 @@ if __name__=='__main__':
finally
:
GPIOThread
.
clean
()
Database
.
instance
().
close
()
for
f
in
glob
.
glob
(
join
(
IMG_PATH
,
'*'
)):
os
.
remove
(
f
)
core/database.py
View file @
283f06ef
...
...
@@ -33,6 +33,9 @@ class Database():
def
_cursor
(
self
):
return
self
.
_connection
.
cursor
()
def
rfid_exists
(
self
,
rfid
):
return
bool
(
self
.
_cursor
.
execute
(
'SELECT rfid FROM Players WHERE rfid==?'
,
(
rfid
,)).
fetchone
())
def
select_one
(
self
,
query
,
*
args
):
res
=
self
.
_cursor
.
execute
(
query
,
args
).
fetchone
()
if
not
res
:
...
...
@@ -58,13 +61,21 @@ class Database():
def
select_all_rfid
(
self
,
debug
=
False
):
from
Babyfut.core.settings
import
Settings
if
Settings
[
'app.mode'
]
==
'prod'
:
return
self
.
_cursor
.
execute
(
'SELECT rfid FROM Players WHERE rfid>0'
).
fetchall
()
return
self
.
_cursor
.
execute
(
'SELECT rfid FROM Players WHERE rfid>0
AND private==0
'
).
fetchall
()
else
:
return
self
.
_cursor
.
execute
(
'SELECT rfid FROM Players WHERE rfid<-1'
).
fetchall
()
return
self
.
_cursor
.
execute
(
'SELECT rfid FROM Players WHERE rfid<-1
AND private==0
'
).
fetchall
()
def
delete_player
(
self
,
playerID
):
self
.
_cursor
.
execute
(
'DELETE FROM Players WHERE id==?'
,
(
playerID
,))
self
.
_connection
.
commit
()
def
delete_playerpic
(
self
,
playerID
):
self
.
_cursor
.
execute
(
'UPDATE Players SET pic=null WHERE id==?'
,
(
playerID
,))
self
.
_connection
.
commit
()
def
make_player_private
(
self
,
playerID
):
self
.
_cursor
.
execute
(
'UPDATE Players SET private=1 WHERE id==?'
,
(
playerID
,))
self
.
_connection
.
commit
()
def
close
(
self
):
self
.
_connection
.
close
()
core/input.py
View file @
283f06ef
...
...
@@ -8,10 +8,10 @@ import logging
import
pyautogui
# PyPi library
from
threading
import
Thread
from
Babyfut.babyfut
import
O
nRasp
from
Babyfut.babyfut
import
O
N_RASP
from
Babyfut.core.player
import
Side
if
O
nRasp
:
if
O
N_RASP
:
import
RPi.GPIO
as
GPIO
class
GPIOThread
(
Thread
):
...
...
@@ -29,7 +29,7 @@ class GPIOThread(Thread):
self
.
dispatcher
=
dispatcher
self
.
continueRunning
=
True
if
O
nRasp
:
if
O
N_RASP
:
GPIO
.
setwarnings
(
False
)
GPIO
.
setmode
(
GPIO
.
BCM
)
...
...
@@ -39,7 +39,7 @@ class GPIOThread(Thread):
GPIO
.
add_event_detect
(
pin
,
GPIO
.
RISING
,
callback
=
self
.
handleButtonPress
)
def
run
(
self
):
if
O
nRasp
:
if
O
N_RASP
:
try
:
while
self
.
continueRunning
:
pass
...
...
@@ -59,5 +59,5 @@ class GPIOThread(Thread):
@
staticmethod
def
clean
():
if
O
nRasp
:
if
O
N_RASP
:
GPIO
.
cleanup
()
core/player.py
View file @
283f06ef
...
...
@@ -62,8 +62,6 @@ class Player():
_placeholder_pic_path
=
':ui/img/placeholder_head.jpg'
_first_time
=
True
# Debug
def
__init__
(
self
,
id
,
rfid
,
fname
,
lname
,
pic_path
,
stats
):
self
.
id
=
id
self
.
rfid
=
rfid
...
...
@@ -76,33 +74,37 @@ class Player():
def
fromRFID
(
rfid
):
db
=
Database
.
instance
()
try
:
# Retrieve generic informations
id
,
fname
,
lname
,
pic
=
db
.
select_one
(
Player
.
__query_infos
,
rfid
)
if
db
.
rfid_exists
(
rfid
):
try
:
# Retrieve generic informations
id
,
fname
,
lname
,
pic
=
db
.
select_one
(
Player
.
__query_infos
,
rfid
)
# Ask for consent
if
rfid
==-
2
and
Player
.
_first_time
:
consentDialog
=
ConsentDialog
(
getMainWin
()
)
consentDialog
.
exec
(
)
# Retrieve stats
stats
=
{}
stats
[
'time_played'
],
stats
[
'goals_scored'
],
stats
[
'games_played'
]
=
db
.
select_one
(
Player
.
__query_time_goals_games
,
id
,
id
)
stats
[
'victories'
],
=
db
.
select_one
(
Player
.
__query_victories
,
id
)
if
not
consentDialog
.
result
()
==
QDialog
.
Accepted
:
Player
.
_first_time
=
False
return
PlayerGuest
for
key
,
val
in
stats
.
items
()
:
if
val
==
None
:
stats
[
key
]
=
0
# Retrieve stats
stats
=
{}
stats
[
'time_played'
],
stats
[
'goals_scored'
],
stats
[
'games_played'
]
=
db
.
select_one
(
Player
.
__query_time_goals_games
,
id
,
id
)
stats
[
'victories'
],
=
db
.
select_one
(
Player
.
__query_victories
,
id
)
return
Player
(
id
,
rfid
,
fname
,
lname
,
pic
,
stats
)
for
key
,
val
in
stats
.
items
()
:
if
val
==
None
:
stats
[
key
]
=
0
except
DatabaseError
as
e
:
logging
.
warn
(
'DB Error: {}'
.
format
(
e
))
return
PlayerGuest
return
Player
(
id
,
rfid
,
fname
,
lname
,
pic
,
stats
)
else
:
### Retrieve player from API
# Ask for consent
consentDialog
=
ConsentDialog
(
getMainWin
())
consentDialog
.
exec
()
except
DatabaseError
as
e
:
logging
.
warn
(
'DB Error: {}'
.
format
(
e
))
return
PlayerGuest
if
consentDialog
.
result
()
==
QDialog
.
Accepted
:
print
(
'todo'
)
return
PlayerGuest
else
:
return
PlayerGuest
def
displayImg
(
self
,
container_widget
):
self
.
pic_container
=
container_widget
...
...
@@ -110,6 +112,7 @@ class Player():
if
self
.
pic_path
.
startswith
(
'http'
):
# Download from the internet
container_widget
.
setStyleSheet
(
'border-image: url({});'
.
format
(
Player
.
_placeholder_pic_path
))
# TODO DOWNLOAD
else
:
# Already downloaded and stored locally
container_widget
.
setStyleSheet
(
'border-image: url({});'
.
format
(
self
.
pic_path
))
...
...
@@ -121,6 +124,14 @@ class Player():
pass
# DONT SAVE PIC PATH, IT IS CHANGED FOR THE LOCAL PATH
def
forgetPicture
():
self
.
pic_path
=
Player
.
_placeholder_pic_path
Database
.
instance
().
delete_playerpic
(
self
.
id
)
def
make_private
():
self
.
private
=
True
Database
.
instance
().
make_player_private
(
self
.
id
)
@
property
def
name
(
self
):
return
'{} {}'
.
format
(
self
.
fname
,
self
.
lname
.
upper
())
...
...
core/replay.py
View file @
283f06ef
...
...
@@ -6,10 +6,10 @@
from
threading
import
Thread
,
Event
from
Babyfut.babyfut
import
getContent
,
O
nRasp
from
Babyfut.babyfut
import
getContent
,
O
N_RASP
from
Babyfut.core.settings
import
Settings
if
O
nRasp
:
if
O
N_RASP
:
import
picamera
class
Replay
(
Thread
):
...
...
@@ -22,7 +22,7 @@ class Replay(Thread):
self
.
stop_flag
=
Event
()
self
.
stopped_flag
=
Event
()
if
O
nRasp
:
if
O
N_RASP
:
self
.
cam
=
picamera
.
PiCamera
()
self
.
cam
.
resolution
=
Settings
[
'picam.resolution'
]
self
.
cam
.
framerate
=
Settings
[
'picam.fps'
]
...
...
@@ -31,11 +31,11 @@ class Replay(Thread):
self
.
stream
=
picamera
.
PiCameraCircularIO
(
self
.
cam
,
seconds
=
Settings
[
'replay.duration'
])
def
start_recording
(
self
):
if
O
nRasp
:
if
O
N_RASP
:
self
.
start_flag
.
set
()
def
stop_recording
(
self
):
if
O
nRasp
:
if
O
N_RASP
:
self
.
stop_flag
.
set
()
self
.
stopped_flag
.
wait
()
...
...
@@ -78,4 +78,4 @@ class Replay(Thread):
@
staticmethod
def
isCamAvailable
():
return
O
nRasp
# and other checks (ToDo)
return
O
N_RASP
# and other checks (ToDo)
modules/leaderboard.py
View file @
283f06ef
...
...
@@ -29,12 +29,10 @@ class LeaderboardItemWidget(QWidget):
self
.
ui
.
lblFName
.
setText
(
player
.
fname
)
self
.
ui
.
lblLName
.
setText
(
player
.
lname
)
self
.
ui
.
lblVictories
.
setText
(
self
.
ui
.
lblVictories
.
text
().
replace
(
'####'
,
str
(
player
.
stats
[
'victories'
])))
self
.
ui
.
lblGamesPlayed
.
setText
(
self
.
ui
.
lblGamesPlayed
.
text
().
replace
(
'####'
,
str
(
player
.
stats
[
'games_played'
])))
self
.
ui
.
lblGoalsScored
.
setText
(
self
.
ui
.
lblGoalsScored
.
text
().
replace
(
'####'
,
str
(
player
.
stats
[
'goals_scored'
])))
self
.
ui
.
lblMinutesPlayed
.
setText
(
self
.
ui
.
lblMinutesPlayed
.
text
().
replace
(
'####'
,
str
(
player
.
stats
[
'time_played'
])))
self
.
ui
.
pushButton
.
clicked
.
connect
(
lambda
:
logging
.
debug
(
'clicked'
))
self
.
ui
.
lblVictories
.
setText
(
self
.
ui
.
lblVictories
.
text
().
format
(
player
.
stats
[
'victories'
]
))
self
.
ui
.
lblGamesPlayed
.
setText
(
self
.
ui
.
lblGamesPlayed
.
text
().
format
(
player
.
stats
[
'games_played'
]
))
self
.
ui
.
lblGoalsScored
.
setText
(
self
.
ui
.
lblGoalsScored
.
text
().
format
(
player
.
stats
[
'goals_scored'
]
))
self
.
ui
.
lblMinutesPlayed
.
setText
(
self
.
ui
.
lblMinutesPlayed
.
text
().
replace
(
'{}'
,
'{0:.2f}'
).
format
(
player
.
stats
[
'time_played'
]
/
60
))
class
DeleteDialog
(
QDialog
):
class
Actions
(
Enum
):
...
...
@@ -50,7 +48,7 @@ class DeleteDialog(QDialog):
self
.
ui
.
lblTitle
.
setText
(
self
.
ui
.
lblTitle
.
text
().
format
(
player
.
name
))
def
check
(
self
,
rfid
):
return
rfid
==
-
self
.
player
.
id
return
rfid
==
self
.
player
.
rf
id
def
action
(
self
):
dict_actions
=
{
...
...
@@ -91,6 +89,7 @@ class LeaderboardModule(Module):
def
load
(
self
):
logging
.
debug
(
'Loading LeaderboardModule'
)
self
.
selectedSort
=
0
self
.
loadList
()
self
.
setFocus
()
...
...
@@ -109,9 +108,9 @@ class LeaderboardModule(Module):
if
action
==
DeleteDialog
.
Actions
.
DeleteAll
:
Database
.
instance
().
delete_player
(
self
.
deleteDialog
.
player
.
id
)
elif
action
==
DeleteDialog
.
Actions
.
DeletePicture
:
logging
.
error
(
'Unimplemented action: delete picture'
)
self
.
deleteDialog
.
player
.
forgetPicture
(
)
elif
action
==
DeleteDialog
.
Actions
.
HideAccount
:
logging
.
error
(
'Unimplemented action: Hide account'
)
self
.
deleteDialog
.
player
.
make_private
(
)
else
:
logging
.
error
(
'Unknown action {}'
.
format
(
action
))
...
...
translations/babyfut_fr.ts
View file @
283f06ef
...
...
@@ -7,16 +7,6 @@
<
source
>
Dialog
<
/source
>
<
translation
>
Supression
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/delete_dialog_ui.py
"
line
=
"
48
"
/>
<
source
>
Deleting
{}
&
apos
;
s
profile
<
/source
>
<
translation
type
=
"
obsolete
"
>
Supression
du
profil
de
{}
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/delete_dialog_ui.py
"
line
=
"
49
"
/>
<
source
>
Pass
your
badge
to
validate
this
...
<
/source
>
<
translation
type
=
"
obsolete
"
>
Passez
votre
badge
pour
valider
la
supression
...
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/consent_dialog_ui.py
"
line
=
"
39
"
/>
<
source
>
Consent
Approval
Needed
<
/source
>
...
...
@@ -215,31 +205,6 @@
<
source
>
Surname
<
/source
>
<
translation
>
Prénom
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/options_ui.py
"
line
=
"
229
"
/>
<
source
>
Fran
&
#
xe7
;
ais
<
/source
>
<
translation
type
=
"
obsolete
"
>
Français
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
97
"
/>
<
source
>
####
&
#
xa0
;
Victories
<
/source
>
<
translation
type
=
"
obsolete
"
>
####
Victoires
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
98
"
/>
<
source
>
####
&
#
xa0
;
Goals
Scored
<
/source
>
<
translation
type
=
"
obsolete
"
>
####
Buts
Marqués
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
99
"
/>
<
source
>
####
&
#
xa0
;
Games
Played
<
/source
>
<
translation
type
=
"
obsolete
"
>
####
Parties
Jouées
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
100
"
/>
<
source
>
####
Minutes
Played
<
/source
>
<
translation
>
####
Minutes
Jouées
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/privacy_ui.py
"
line
=
"
53
"
/>
<
source
>
Privacy
<
/source
>
...
...
@@ -260,24 +225,38 @@
<
source
>
{}
Goals
Scored
<
/source
>
<
translation
>
{}
Buts
Marqués
<
/translation
>
<
/message
>
<
message
encoding
=
"
UTF-8
"
>
<
location
filename
=
"
../ui/options_ui.py
"
line
=
"
229
"
/>
<
source
>
Français
<
/source
>
<
translation
type
=
"
unfinished
"
><
/translation
>
<
/message
>
<
message
encoding
=
"
UTF-8
"
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
97
"
/>
<
source
>
####
Victories
<
/source
>
<
translation
type
=
"
unfinished
"
><
/translation
>
<
source
>
{}
Victories
<
/source
>
<
comment
>
Form
<
/comment
>
<
translation
>
{}
Victoires
<
/translation
>
<
/message
>
<
message
encoding
=
"
UTF-8
"
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
98
"
/>
<
source
>
####
Goals
Scored
<
/source
>
<
translation
type
=
"
unfinished
"
><
/translation
>
<
source
>
{}
Goals
Scored
<
/source
>
<
comment
>
Form
<
/comment
>
<
translation
>
{}
Buts
Marqués
<
/translation
>
<
/message
>
<
message
encoding
=
"
UTF-8
"
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
99
"
/>
<
source
>
####
Games
Played
<
/source
>
<
source
>
{}
Games
Played
<
/source
>
<
comment
>
Form
<
/comment
>
<
translation
>
{}
Parties
Jouées
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/playerlist_ui.py
"
line
=
"
100
"
/>
<
source
>
{}
Minutes
Played
<
/source
>
<
comment
>
Form
<
/comment
>
<
translation
>
{}
Minutes
Jouées
<
/translation
>
<
/message
>
<
message
>
<
location
filename
=
"
../ui/options_ui.py
"
line
=
"
229
"
/>
<
source
>
Fran
&
#
xe7
;
ais
<
/source
>
<
translation
type
=
"
obsolete
"
>
Français
<
/translation
>
<
/message
>
<
message
encoding
=
"
UTF-8
"
>
<
location
filename
=
"
../ui/options_ui.py
"
line
=
"
229
"
/>
<
source
>
Français
<
/source
>
<
translation
type
=
"
unfinished
"
><
/translation
>
<
/message
>
<
/context
>
...
...
ui/mainwin.py
View file @
283f06ef
...
...
@@ -7,7 +7,6 @@
import
os
from
os.path
import
join
,
dirname
,
abspath
import
logging
OnRasp
=
os
.
uname
()[
1
]
==
'raspberrypi'
from
PyQt5
import
QtWidgets
from
PyQt5.QtWidgets
import
QGraphicsBlurEffect
,
QApplication
...
...
@@ -27,6 +26,7 @@ class MainWin(QtWidgets.QMainWindow):
self
.
ui
.
setupUi
(
self
)
self
.
lang
=
MainWin
.
DEFAULT_LANG
self
.
_retranslateUI
()
self
.
setWindowTitle
(
'Babyfut'
)
#Background blur
bgBlur
=
QGraphicsBlurEffect
()
...
...
ui/playerlist.ui
View file @
283f06ef
...
...
@@ -129,7 +129,7 @@
<item>
<widget
class=
"QLabel"
name=
"lblVictories"
>
<property
name=
"text"
>
<string
>
####
Victories
</string>
<string
comment=
"Form"
>
{}
Victories
</string>
</property>
</widget>
</item>
...
...
@@ -149,7 +149,7 @@
<item>
<widget
class=
"QLabel"
name=
"lblGoalsScored"
>
<property
name=
"text"
>
<string
>
####
Goals Scored
</string>
<string
comment=
"Form"
>
{}
Goals Scored
</string>
</property>
</widget>
</item>
...
...
@@ -169,7 +169,7 @@
<item>
<widget
class=
"QLabel"
name=
"lblGamesPlayed"
>
<property
name=
"text"
>
<string
>
####
Games Played
</string>
<string
comment=
"Form"
>
{}
Games Played
</string>
</property>
</widget>
</item>
...
...
@@ -189,7 +189,7 @@
<item>
<widget
class=
"QLabel"
name=
"lblMinutesPlayed"
>
<property
name=
"text"
>
<string
>
####
Minutes Played
</string>
<string
comment=
"Form"
>
{}
Minutes Played
</string>
</property>
</widget>
</item>
...
...
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