Compare commits
No commits in common. "5653972b8d0cc964b95f7fccd9de241fbcee012b" and "cee41ca595a929b6a6ab6de70834e02756f1e36b" have entirely different histories.
5653972b8d
...
cee41ca595
@ -30,3 +30,8 @@ for id in data_dict:
|
|||||||
print(results)
|
print(results)
|
||||||
dict(sorted(results.items(), key=lambda item: item[0]))
|
dict(sorted(results.items(), key=lambda item: item[0]))
|
||||||
print(results)
|
print(results)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"url": "https://beta.alkator.cz/api/station/register",
|
|
||||||
"station_id": "1",
|
|
||||||
"login_url": "https://beta.alkator.cz/api/login",
|
|
||||||
"racers_url": "https://beta.alkator.cz/api/racers",
|
|
||||||
"card_register": "https://beta.alkator.cz/api/card/register",
|
|
||||||
"card_unregister": "https://beta.alkator.cz/api/card/card_unregister",
|
|
||||||
"login": "station_register@alkator.cz",
|
|
||||||
"password": "password_heslo"
|
|
||||||
}
|
|
@ -1,8 +1,6 @@
|
|||||||
import gi
|
import gi
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import datetime
|
|
||||||
import collections
|
|
||||||
import usb.core
|
import usb.core
|
||||||
import usb.util
|
import usb.util
|
||||||
import requests
|
import requests
|
||||||
@ -11,6 +9,12 @@ import json
|
|||||||
gi.require_version('Gtk', '4.0')
|
gi.require_version('Gtk', '4.0')
|
||||||
from gi.repository import Gtk, Gio, Gdk
|
from gi.repository import Gtk, Gio, Gdk
|
||||||
|
|
||||||
|
DEBUG = False
|
||||||
|
|
||||||
|
if DEBUG == True:
|
||||||
|
index = 2
|
||||||
|
else:
|
||||||
|
index = 1
|
||||||
activeCards = []
|
activeCards = []
|
||||||
|
|
||||||
TIME = 600
|
TIME = 600
|
||||||
@ -20,56 +24,8 @@ USB_TIMEOUT = 5 # Timeout in ms
|
|||||||
USB_VENDOR = 0xffff # Vendor-ID:
|
USB_VENDOR = 0xffff # Vendor-ID:
|
||||||
USB_PRODUCT = 0x0035 # Product-ID
|
USB_PRODUCT = 0x0035 # Product-ID
|
||||||
|
|
||||||
db = {}
|
with open('people.json', 'r') as f:
|
||||||
|
db = json.load(f)
|
||||||
queue_to_send = []
|
|
||||||
|
|
||||||
with open('config.json', 'r') as f:
|
|
||||||
config = json.load(f)
|
|
||||||
|
|
||||||
session = requests.Session()
|
|
||||||
session.post(config['login_url'], {'email':config['login'], 'password': config['password']})
|
|
||||||
|
|
||||||
def refreshDb():
|
|
||||||
global db
|
|
||||||
resp = session.get(config['racers_url'])
|
|
||||||
if resp.status_code == 200:
|
|
||||||
json = resp.json()
|
|
||||||
db = {}
|
|
||||||
for racer in json:
|
|
||||||
if racer["card_id"]:
|
|
||||||
db[racer["card_id"]] = racer
|
|
||||||
|
|
||||||
|
|
||||||
def refreshDbEvery3mins():
|
|
||||||
while True:
|
|
||||||
refreshDb()
|
|
||||||
time.sleep(3 * 60)
|
|
||||||
|
|
||||||
|
|
||||||
Thread(target=refreshDbEvery3mins).start()
|
|
||||||
|
|
||||||
|
|
||||||
def sendQueueToSend():
|
|
||||||
global queue_to_send
|
|
||||||
while True:
|
|
||||||
if len(queue_to_send) > 0:
|
|
||||||
to_send = queue_to_send.pop()
|
|
||||||
|
|
||||||
response = session.post(config['url'],
|
|
||||||
to_send, 'application/json'
|
|
||||||
)
|
|
||||||
if response.status_code != 200:
|
|
||||||
if response.status_code == 400:
|
|
||||||
continue
|
|
||||||
queue_to_send.append(to_send) #try again later
|
|
||||||
time.sleep(1)
|
|
||||||
else:
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
|
|
||||||
Thread(target=sendQueueToSend).start()
|
|
||||||
|
|
||||||
|
|
||||||
class UsbCardReader():
|
class UsbCardReader():
|
||||||
def __init__(self, **kargs):
|
def __init__(self, **kargs):
|
||||||
@ -103,17 +59,17 @@ class UsbCardReader():
|
|||||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
receivedNumber = 10 * receivedNumber + receivedDigit
|
||||||
|
|
||||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
||||||
if receivedNumber not in db:
|
try:
|
||||||
refreshDb()
|
with open('people.json', 'r') as f:
|
||||||
if receivedNumber in db:
|
db = json.load(f)
|
||||||
if receivedNumber not in activeCards:
|
for i in db:
|
||||||
activeCards.append(receivedNumber)
|
if db[i] == receivedNumber:
|
||||||
win.arb(db[receivedNumber])
|
if i not in activeCards:
|
||||||
print('Card is active now')
|
activeCards.append(i)
|
||||||
|
win.arb(i)
|
||||||
else:
|
else:
|
||||||
print('Card is already active')
|
print("Card is active now")
|
||||||
else:
|
except Exception as e: print(e)
|
||||||
print(f'Card {receivedNumber} not found in db')
|
|
||||||
receivedNumber = 0
|
receivedNumber = 0
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@ -124,9 +80,9 @@ class UsbCardReader():
|
|||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
|
||||||
class GridRow():
|
class GridRow():
|
||||||
def __init__(self, parent, racer, index):
|
def __init__(self, parent, runner, index):
|
||||||
global queue_to_send
|
self.id = runner
|
||||||
self.id = racer['starting_number']
|
self.index = index
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|
||||||
self.grid = Gtk.Grid()
|
self.grid = Gtk.Grid()
|
||||||
@ -136,7 +92,7 @@ class GridRow():
|
|||||||
else:
|
else:
|
||||||
self.grid.set_name("darkgrid")
|
self.grid.set_name("darkgrid")
|
||||||
|
|
||||||
self.runid = Gtk.Label(label=str(racer["starting_number"]), name="gridlabel")
|
self.runid = Gtk.Label(label=str(runner), name="gridlabel")
|
||||||
self.runid.set_justify(2)
|
self.runid.set_justify(2)
|
||||||
self.runid.set_width_chars(10)
|
self.runid.set_width_chars(10)
|
||||||
|
|
||||||
@ -151,12 +107,6 @@ class GridRow():
|
|||||||
countdown=threading.Thread(target=self.updateTime)
|
countdown=threading.Thread(target=self.updateTime)
|
||||||
countdown.start()
|
countdown.start()
|
||||||
|
|
||||||
queue_to_send.append({
|
|
||||||
'card_id': racer['card_id'],
|
|
||||||
'station_id': config['station_id'],
|
|
||||||
'time': datetime.datetime.now().strftime('%d.%m.%Y %H:%M:%S.%f')
|
|
||||||
})
|
|
||||||
|
|
||||||
def printIndex(self, button):
|
def printIndex(self, button):
|
||||||
print(self.index)
|
print(self.index)
|
||||||
|
|
||||||
@ -188,6 +138,12 @@ class GridWindow(Gtk.ApplicationWindow):
|
|||||||
css_provider.load_from_file(Gio.File.new_for_path("style.css"))
|
css_provider.load_from_file(Gio.File.new_for_path("style.css"))
|
||||||
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||||
|
|
||||||
|
button1 = Gtk.Button(label='addrow')
|
||||||
|
button2 = Gtk.Button(label='rmrow')
|
||||||
|
|
||||||
|
button1.connect("clicked", self.arb)
|
||||||
|
button2.connect("clicked", self.rrb)
|
||||||
|
|
||||||
runlabel = Gtk.Label(label="ID", name="gridlabel")
|
runlabel = Gtk.Label(label="ID", name="gridlabel")
|
||||||
runlabel.set_justify(2)
|
runlabel.set_justify(2)
|
||||||
cntlabel = Gtk.Label(label="Countdown", name="gridlabel")
|
cntlabel = Gtk.Label(label="Countdown", name="gridlabel")
|
||||||
@ -196,15 +152,24 @@ class GridWindow(Gtk.ApplicationWindow):
|
|||||||
self.runners = []
|
self.runners = []
|
||||||
|
|
||||||
self.grid = Gtk.Grid()
|
self.grid = Gtk.Grid()
|
||||||
|
if DEBUG == True:
|
||||||
|
self.grid.attach(button1, 0, 0, 1, 1)
|
||||||
|
self.grid.attach(button2, 1, 0, 2, 1)
|
||||||
|
self.grid.attach(runlabel, 0, 1, 1, 1)
|
||||||
|
self.grid.attach(cntlabel, 1, 1, 2, 1)
|
||||||
|
else:
|
||||||
self.grid.attach(runlabel, 0, 0, 1, 1)
|
self.grid.attach(runlabel, 0, 0, 1, 1)
|
||||||
self.grid.attach(cntlabel, 1, 0, 2, 1)
|
self.grid.attach(cntlabel, 1, 0, 2, 1)
|
||||||
|
|
||||||
self.set_child(self.grid)
|
self.set_child(self.grid)
|
||||||
|
|
||||||
def arb(self, racer):
|
def arb(self, personId):
|
||||||
self.runners.append(GridRow(self, racer, len(activeCards)))
|
global index
|
||||||
|
self.runners.append(GridRow(self, personId, index))
|
||||||
|
index += 1
|
||||||
|
|
||||||
def rrb(self, button):
|
def rrb(self, button):
|
||||||
|
global index
|
||||||
self.remRow()
|
self.remRow()
|
||||||
|
|
||||||
def addRow(self, runner, index):
|
def addRow(self, runner, index):
|
||||||
@ -215,9 +180,10 @@ class GridWindow(Gtk.ApplicationWindow):
|
|||||||
self.grid.attach(runb, 1, index, 1, 1)
|
self.grid.attach(runb, 1, index, 1, 1)
|
||||||
|
|
||||||
def remRow(self):
|
def remRow(self):
|
||||||
global activeCards
|
global index, activeCards
|
||||||
if len(activeCards) > 0:
|
if index > 1:
|
||||||
self.grid.remove_row(1)
|
self.grid.remove_row(1)
|
||||||
|
index -= 1
|
||||||
del activeCards[0]
|
del activeCards[0]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,134 +0,0 @@
|
|||||||
import sys
|
|
||||||
import datetime
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
import usb.core
|
|
||||||
import usb.util
|
|
||||||
from PyQt6 import QtWidgets, uic, QtGui
|
|
||||||
|
|
||||||
app = QtWidgets.QApplication(sys.argv)
|
|
||||||
|
|
||||||
TIME = 600
|
|
||||||
|
|
||||||
USB_IF = 0 # Interface
|
|
||||||
USB_TIMEOUT = 5 # Timeout in ms
|
|
||||||
USB_VENDOR = 0xffff # Vendor-ID:
|
|
||||||
USB_PRODUCT = 0x0035 # Product-ID
|
|
||||||
|
|
||||||
with open('config.json', 'r') as f:
|
|
||||||
config = json.load(f)
|
|
||||||
|
|
||||||
session = requests.Session()
|
|
||||||
session.post(config['login_url'], {'email':config['login'], 'password': config['password']})
|
|
||||||
|
|
||||||
|
|
||||||
last_card = 1111
|
|
||||||
last_time = datetime.datetime.now()
|
|
||||||
|
|
||||||
|
|
||||||
response = session.get(config['racers_url'])
|
|
||||||
|
|
||||||
racers = response.json()
|
|
||||||
|
|
||||||
|
|
||||||
def register_racer():
|
|
||||||
card_id = last_card
|
|
||||||
index = window.racers.currentIndex()
|
|
||||||
racer_id = int(index.data().split(' ')[-1])
|
|
||||||
try:
|
|
||||||
starting_number = int(window.starting_number.text())
|
|
||||||
except Exception:
|
|
||||||
raise
|
|
||||||
|
|
||||||
response = session.post(config['card_register'], json={'racer_id': racer_id, 'starting_number': starting_number, 'card_id': last_card})
|
|
||||||
if response.status_code != 200:
|
|
||||||
raise Exception(response.status_code, response.content)
|
|
||||||
|
|
||||||
racer = list(filter(lambda x: x['racer_id'] == racer_id, racers))[0]
|
|
||||||
racer['card_id'] = card_id
|
|
||||||
racer['starting_number'] = starting_number
|
|
||||||
updateRacers()
|
|
||||||
|
|
||||||
|
|
||||||
def unregister_racer():
|
|
||||||
card_id = last_card
|
|
||||||
time = last_time
|
|
||||||
|
|
||||||
response = session.post(config['url'], json={'card_id': card_id, 'time': time.strftime('%d.%m.%Y %H:%M:%S.%f'), 'station_id': config['station_id']})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
window = uic.loadUi("registrace.ui")
|
|
||||||
window.register_racer.clicked.connect(register_racer)
|
|
||||||
window.unregister_racer.clicked.connect(unregister_racer)
|
|
||||||
window.show()
|
|
||||||
|
|
||||||
|
|
||||||
model = QtGui.QStandardItemModel()
|
|
||||||
window.racers.setModel(model)
|
|
||||||
|
|
||||||
def updateRacers():
|
|
||||||
model.clear()
|
|
||||||
for racer in racers:
|
|
||||||
if racer['starting_number'] or racer['card_id']:
|
|
||||||
continue
|
|
||||||
item = QtGui.QStandardItem(f"{racer['last_name']} {racer['first_name']} {racer['date_of_birth']} {racer['racer_id']}")
|
|
||||||
model.appendRow(item)
|
|
||||||
|
|
||||||
|
|
||||||
updateRacers()
|
|
||||||
|
|
||||||
|
|
||||||
def updateLastCard(card_id):
|
|
||||||
window.lastCard.setText(str(card_id))
|
|
||||||
|
|
||||||
|
|
||||||
class UsbCardReader():
|
|
||||||
def __init__(self, **kargs):
|
|
||||||
# Find the HID device by vendor/product ID
|
|
||||||
self.dev = usb.core.find(idVendor=USB_VENDOR, idProduct=USB_PRODUCT)
|
|
||||||
# Get and store the endpoint
|
|
||||||
self.endpoint = self.dev[0][(0,0)][0]
|
|
||||||
if self.dev.is_kernel_driver_active(USB_IF) is True:
|
|
||||||
self.dev.detach_kernel_driver(USB_IF)
|
|
||||||
# Claim the device
|
|
||||||
usb.util.claim_interface(self.dev, USB_IF)
|
|
||||||
self.receivedNumber = 0
|
|
||||||
|
|
||||||
cardread=threading.Thread(target=self.read)
|
|
||||||
cardread.start()
|
|
||||||
|
|
||||||
def read(self):
|
|
||||||
global last_card, last_time
|
|
||||||
|
|
||||||
print("Waiting for card")
|
|
||||||
receivedNumber = 0
|
|
||||||
|
|
||||||
while True:
|
|
||||||
control = None
|
|
||||||
try:
|
|
||||||
control = self.dev.read(self.endpoint.bEndpointAddress, self.endpoint.wMaxPacketSize, USB_TIMEOUT)
|
|
||||||
if (control[2] != 40) & (control[2] != 0):
|
|
||||||
receivedDigit = control[2] - 29
|
|
||||||
if receivedDigit == 10:
|
|
||||||
receivedDigit = 0
|
|
||||||
receivedNumber = 10 * receivedNumber + receivedDigit
|
|
||||||
|
|
||||||
if (( control[0] == 0 )) & (( control[2] == 40 )) & (( not receivedNumber == 0 )):
|
|
||||||
updateLastCard(receivedNumber)
|
|
||||||
if last_card != receivedNumber:
|
|
||||||
last_time = datetime.datetime.now()
|
|
||||||
last_card = receivedNumber
|
|
||||||
receivedNumber = 0
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
exit()
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
time.sleep(0.001)
|
|
||||||
|
|
||||||
UsbCardReader()
|
|
||||||
|
|
||||||
app.exec()
|
|
@ -1,71 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>Frame</class>
|
|
||||||
<widget class="QFrame" name="Frame">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>315</width>
|
|
||||||
<height>289</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string>Registrace závodníků</string>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="5" column="0">
|
|
||||||
<widget class="QLineEdit" name="lastCard"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QPushButton" name="register_racer">
|
|
||||||
<property name="text">
|
|
||||||
<string>Registrovat</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QPushButton" name="unregister_racer">
|
|
||||||
<property name="text">
|
|
||||||
<string>Dokončit</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLineEdit" name="starting_number"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="text">
|
|
||||||
<string>startovní číslo</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="text">
|
|
||||||
<string>číslo karty</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="6" column="0">
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1" rowspan="7">
|
|
||||||
<widget class="QListView" name="racers"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<resources/>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
@ -90,6 +90,7 @@ def main():
|
|||||||
elif rw == '':
|
elif rw == '':
|
||||||
s.write('r\r'.encode())
|
s.write('r\r'.encode())
|
||||||
read(s)
|
read(s)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print('Invalid option')
|
print('Invalid option')
|
||||||
|
|
||||||
|
@ -406,3 +406,4 @@ class PN532:
|
|||||||
_COMMAND_INDATAEXCHANGE, params=params, response_length=1
|
_COMMAND_INDATAEXCHANGE, params=params, response_length=1
|
||||||
)
|
)
|
||||||
return response[0] == 0x00
|
return response[0] == 0x00
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user