mirror of
https://github.com/jakobkordez/s5_practice.git
synced 2025-05-16 00:30:29 +00:00
346 lines
12 KiB
Plaintext
346 lines
12 KiB
Plaintext
{
|
||
"cells": [
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 1,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"import re\n",
|
||
"import json"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"imageRefs = {\n",
|
||
" 213: 0,\n",
|
||
" 214: 1,\n",
|
||
" 215: 2,\n",
|
||
" 216: 1,\n",
|
||
" 217: 4,\n",
|
||
" 218: 5,\n",
|
||
" 219: 6,\n",
|
||
" 220: 7,\n",
|
||
" 221: 8,\n",
|
||
" 222: 9,\n",
|
||
" 223: 10,\n",
|
||
" 224: 11,\n",
|
||
" 225: 12,\n",
|
||
" 226: 13,\n",
|
||
" 227: 14,\n",
|
||
" 228: 15,\n",
|
||
" 229: 16,\n",
|
||
" 230: 17,\n",
|
||
" 231: 18,\n",
|
||
" 232: 19,\n",
|
||
" 233: 20,\n",
|
||
" 234: 21,\n",
|
||
" 235: 22,\n",
|
||
" 236: 23,\n",
|
||
" 237: 24,\n",
|
||
" 238: 25,\n",
|
||
" 240: 26,\n",
|
||
" 241: 27,\n",
|
||
" 242: 28,\n",
|
||
" 243: 29,\n",
|
||
" 244: 30,\n",
|
||
" 245: 31,\n",
|
||
" 246: 32,\n",
|
||
" 247: 33,\n",
|
||
" 248: 34,\n",
|
||
" 249: 35,\n",
|
||
" 250: 36,\n",
|
||
" 256: 37,\n",
|
||
" 257: 38,\n",
|
||
" 258: 39,\n",
|
||
" 259: 40,\n",
|
||
" 260: 41,\n",
|
||
" 430: 77,\n",
|
||
" 431: 78,\n",
|
||
" 432: 79,\n",
|
||
" 433: 80,\n",
|
||
" 461: 81,\n",
|
||
" 462: 82,\n",
|
||
" 475: 83,\n",
|
||
" 476: 84,\n",
|
||
" 477: 85,\n",
|
||
" 478: 86,\n",
|
||
" 479: 87,\n",
|
||
" 482: 42,\n",
|
||
" 483: 43,\n",
|
||
" 484: 44,\n",
|
||
" 485: 45,\n",
|
||
" 486: 46,\n",
|
||
" 487: 47,\n",
|
||
" 488: 48,\n",
|
||
" 503: 49,\n",
|
||
" 504: 50,\n",
|
||
" 509: 51,\n",
|
||
" 510: 52,\n",
|
||
" 511: 53,\n",
|
||
" 518: 54,\n",
|
||
" 523: 55,\n",
|
||
" 524: 56,\n",
|
||
" 530: 57,\n",
|
||
" 531: 58,\n",
|
||
" 532: 59,\n",
|
||
" 533: 60,\n",
|
||
" 543: 61,\n",
|
||
" 544: 62,\n",
|
||
" 545: 63,\n",
|
||
" 546: 64,\n",
|
||
" 563: 65,\n",
|
||
" 564: 66,\n",
|
||
" 565: 67,\n",
|
||
" 574: 68,\n",
|
||
" 575: 69,\n",
|
||
" 577: 70,\n",
|
||
" 580: 71,\n",
|
||
" 585: 72,\n",
|
||
" 586: 73,\n",
|
||
" 587: 74,\n",
|
||
" 588: 75,\n",
|
||
" 589: 76,\n",
|
||
" 683: 88,\n",
|
||
" 692: 89,\n",
|
||
" 696: 90,\n",
|
||
" 697: 91,\n",
|
||
" 698: 92,\n",
|
||
" 704: 93,\n",
|
||
" 705: 94,\n",
|
||
" 707: 95,\n",
|
||
" 751: 96,\n",
|
||
" 752: 97,\n",
|
||
" 753: 98,\n",
|
||
" 760: 99,\n",
|
||
" 764: 100,\n",
|
||
" 766: 101,\n",
|
||
" 767: 102,\n",
|
||
" 769: 103,\n",
|
||
" 770: 104,\n",
|
||
" 845: 105,\n",
|
||
" 846: 106,\n",
|
||
" 848: 107,\n",
|
||
" 849: 108,\n",
|
||
" 851: 109,\n",
|
||
" 852: 110,\n",
|
||
" 853: 111,\n",
|
||
" 854: 112,\n",
|
||
" 855: 113,\n",
|
||
" 856: 114,\n",
|
||
" 885: 115,\n",
|
||
" 886: 116,\n",
|
||
" 887: 117,\n",
|
||
" 888: 118,\n",
|
||
" 889: 119,\n",
|
||
" 934: 120,\n",
|
||
"}"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": null,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"f = [\n",
|
||
" 'C:/Users/Jakob/Documents/Ham/Izpitna vprašanja/A_01.txt',\n",
|
||
" 'C:/Users/Jakob/Documents/Ham/Izpitna vprašanja/A_02.txt',\n",
|
||
" 'C:/Users/Jakob/Documents/Ham/Izpitna vprašanja/A_03.txt',\n",
|
||
" 'C:/Users/Jakob/Documents/Ham/Izpitna vprašanja/A_04.txt',\n",
|
||
"]\n",
|
||
"\n",
|
||
"q_split = re.compile(r'\\n(?=\\d+\\.)')\n",
|
||
"ql_split = re.compile(r'\\n\\s*')\n",
|
||
"a_split = re.compile(r'\\n\\s*(?=[A-Z]\\.)')\n",
|
||
"invalid_chars = re.compile(r'[^\\w\\s\\d\\n\\.?!:;,蚞ȊŽ/\"\\-–\\(\\)\\[\\]»«…=*%+\\\\\\{\\}$∞<>]')\n",
|
||
"\n",
|
||
"def map_a(s: str):\n",
|
||
" a = [re.sub(r'\\s+', ' ', ss.strip()) for ss in a_split.split(s)]\n",
|
||
" for i in range(len(a)):\n",
|
||
" if ord(a[i][0])-ord('A') != i:\n",
|
||
" raise Exception(s)\n",
|
||
" return [aa[2:].lstrip().rstrip('. ') for aa in a]\n",
|
||
"\n",
|
||
"def map_q(s: str):\n",
|
||
" t = ql_split.split(s)\n",
|
||
" ca = t[0][-1]\n",
|
||
" if ca < 'A' or ca > 'Z':\n",
|
||
" raise Exception(s)\n",
|
||
" t[0] = t[0][:-1].strip()\n",
|
||
" return ' '.join(t), ord(ca)-ord('A')\n",
|
||
"\n",
|
||
"def map_qa(s: str):\n",
|
||
" s = s.strip()\n",
|
||
" if invalid_chars.search(s):\n",
|
||
" raise Exception(s)\n",
|
||
" i = s.find('.')\n",
|
||
" id = int(s[:i])\n",
|
||
" s = s[i+1:].strip()\n",
|
||
" i = re.search(r'\\n{2,}', s)\n",
|
||
" if i == None:\n",
|
||
" q = ' '.join(ql_split.split(s))\n",
|
||
" a = ca = None\n",
|
||
" else:\n",
|
||
" i = i.start()\n",
|
||
" q, ca = map_q(s[:i].strip())\n",
|
||
" a = map_a(s[i+2:].strip())\n",
|
||
" img = imageRefs.get(id)\n",
|
||
" if img != None:\n",
|
||
" img = f'image-{img:03d}.png'\n",
|
||
" return {'id': id, 'question': q, 'image': img, 'answers': a, 'correct': ca}\n",
|
||
"\n",
|
||
"q = []\n",
|
||
"for ff in f:\n",
|
||
" with open(ff, encoding='utf-8') as file:\n",
|
||
" q.extend(map(map_qa, q_split.split(file.read())))\n",
|
||
"\n",
|
||
"for i in range(len(q)):\n",
|
||
" if q[i]['id'] != i + 1:\n",
|
||
" raise Exception(f'{q[i-1][\"id\"]} != {i+1}')\n",
|
||
"for qa in q:\n",
|
||
" if qa['answers'] != None and len(qa['answers']) != 3:\n",
|
||
" raise Exception(qa)\n",
|
||
"\n",
|
||
"print(len(q), 'questions')\n",
|
||
"with open('../assets/questions.json', 'w', encoding='utf-8') as file:\n",
|
||
" json.dump(q, file, ensure_ascii=False, indent=2)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 2,
|
||
"metadata": {},
|
||
"outputs": [],
|
||
"source": [
|
||
"# Add categories\n",
|
||
"categories = [\n",
|
||
" {'id': 1, 'title': 'Zgodovina radioamaterstva, IARU in ZRS', 'questions': [(1, 12)]},\n",
|
||
" {'id': 2, 'title': 'Osnovni pojmi o radijskih komunikacijah', 'questions': [(13, 24)]},\n",
|
||
" {'id': 3, 'title': 'Razdelitev frekvenc, moči, regioni, code', 'questions': [(25, 128), (239, 239)]},\n",
|
||
" {'id': 4, 'title': 'Mednarodni in slovenski predpisi', 'questions': [(129, 149)]},\n",
|
||
" {'id': 5, 'title': 'Q-kod in kratice', 'questions': [(150, 168), (173, 201), (251, 255), (261, 268), (299, 299)]},\n",
|
||
" {'id': 6, 'title': 'Operaterstvo', 'questions': [(169, 172), (283, 298), (375, 385), (388, 394)]},\n",
|
||
" {'id': 7, 'title': 'Prefiksi in sufiksi', 'questions': [(202, 212)]},\n",
|
||
" {'id': 9, 'title': 'Risanje', 'questions': [(240, 250), (256, 260)]},\n",
|
||
" {'id': 10, 'title': 'RST sistem', 'questions': [(269, 282)]},\n",
|
||
" {'id': 11, 'title': 'Digitalne komunikacije', 'questions': [(300, 312)]},\n",
|
||
" {'id': 12, 'title': 'Radioamaterski dnevnik', 'questions': [(313, 325)]},\n",
|
||
" {'id': 13, 'title': 'QSL kartice', 'questions': [(326, 337)]},\n",
|
||
" {'id': 14, 'title': 'Časocvne cone in UTC', 'questions': [(338, 344)]},\n",
|
||
" {'id': 15, 'title': 'Univerzalni lokator', 'questions': [(345, 350)]},\n",
|
||
" {'id': 16, 'title': 'Radioamaterska tekmovanja in diplome', 'questions': [(351, 362), (386, 387)]},\n",
|
||
" {'id': 17, 'title': 'Ham spirit in ARON', 'questions': [(363, 374)]},\n",
|
||
" {'id': 18, 'title': 'Fizika, elektrotehnika', 'questions': [(395, 454), (465, 492)]},\n",
|
||
" {'id': 19, 'title': 'Valovanje', 'questions': [(455, 464), (777, 804)]},\n",
|
||
" {'id': 20, 'title': 'Električna moč in izkoristek', 'questions': [(493, 504)]},\n",
|
||
" {'id': 21, 'title': 'Tuljave in kondenzatorji', 'questions': [(505, 541)]},\n",
|
||
" {'id': 22, 'title': 'Električni filtri', 'questions': [(542, 569)]},\n",
|
||
" {'id': 23, 'title': 'Polprevodniki in elektronike', 'questions': [(570, 591)]},\n",
|
||
" {'id': 24, 'title': 'Mikrofon in zvočnik', 'questions': [(592, 594)]},\n",
|
||
" {'id': 25, 'title': 'Električni sklopi', 'questions': [(595, 609)]},\n",
|
||
" {'id': 26, 'title': 'Digitalna obdelava signalov', 'questions': [(610, 624)]},\n",
|
||
" {'id': 27, 'title': 'Radijski valovi in signali', 'questions': [(625, 668)]},\n",
|
||
" {'id': 28, 'title': 'Radijski oddajniki', 'questions': [(669, 707)]},\n",
|
||
" {'id': 29, 'title': 'Radijski sprejemniki', 'questions': [(708, 776)]},\n",
|
||
" {'id': 30, 'title': 'Razširjanje radijskih valov', 'questions': [(805, 835)]},\n",
|
||
" {'id': 31, 'title': 'Antene', 'questions': [(213, 233), (836, 868)]},\n",
|
||
" {'id': 32, 'title': 'Napajanje anten', 'questions': [(234, 238), (869, 900)]},\n",
|
||
" {'id': 33, 'title': 'Motnje', 'questions': [(901, 904)]},\n",
|
||
" {'id': 34, 'title': 'Varnost pri delu', 'questions': [(905, 908)]},\n",
|
||
" {'id': 35, 'title': 'Meritve', 'questions': [(909, 970)]},\n",
|
||
"]\n",
|
||
"\n",
|
||
"with open('../assets/questions.json', encoding='utf-8') as file:\n",
|
||
" q = json.load(file)\n",
|
||
"\n",
|
||
"if type(q) is not list:\n",
|
||
" q = q['questions']\n",
|
||
"\n",
|
||
"q = {'categories': categories, 'questions': q}\n",
|
||
"\n",
|
||
"with open('../assets/questions.json', 'w', encoding='utf-8') as file:\n",
|
||
" json.dump(q, file, ensure_ascii=False, indent=2)"
|
||
]
|
||
},
|
||
{
|
||
"cell_type": "code",
|
||
"execution_count": 5,
|
||
"metadata": {},
|
||
"outputs": [
|
||
{
|
||
"name": "stdout",
|
||
"output_type": "stream",
|
||
"text": [
|
||
"{'id': 116, 'question': 'Katere modulacije smemo uporabljati na 30-meterskem pasu?', 'image': None, 'answers': ['CW in fone', 'CW, digimode in fone', 'CW in digimode'], 'correct': 2}\n",
|
||
"{'id': 394, 'question': 'Kateri je najpogostejši način, ki ga uporabljajo DX postaje pri svojem delu?', 'image': None, 'answers': ['Najpogosteje se uporablja tako imenovani »simpleks pileup«', 'DX postaje najpogosteje uporabljajo SPLIT način dela. Poslušajo nad (UP) ali pod (DOWN) svojo oddajno frekvenco', 'DX postaje vedno poslušajo in oddajajo na isti frekvenci, saj je možno tako narediti največ zvez v eni minuti'], 'correct': 1}\n",
|
||
"{'id': 427, 'question': 'Kako se imenuje enota za merjenje električne upornosti?', 'image': None, 'answers': ['Amper [A]', 'Watt [W]', 'Ohm [Ω]'], 'correct': 2}\n",
|
||
"{'id': 491, 'question': 'Izračunaj moč, ki se troši na bremenu z upornostjo 1 ohm, če nanj priključimo napetost 10V.', 'image': None, 'answers': ['100 W', '10 W', '1 W'], 'correct': 0}\n",
|
||
"{'id': 642, 'question': 'S prijateljem vzpostavimo zvezo v telegrafiji (CW) in nato v telefoniji (najprej SSB in potem še FM). Kateri od uporabljenih signalov ima NAJVEČJO pasovno širino?', 'image': None, 'answers': ['CW signal', 'SSB signal', 'FM signal'], 'correct': 2}\n",
|
||
"{'id': 643, 'question': 'S prijateljem vzpostavimo zvezo v telegrafiji (CW) in nato v telefoniji (najprej SSB in potem še FM). Kateri od uporabljenih signalov ima NAJMANJŠO pasovno širino?', 'image': None, 'answers': ['CW signal', 'SSB signal', 'FM signal'], 'correct': 0}\n",
|
||
"---\n",
|
||
"---\n",
|
||
"970 970\n"
|
||
]
|
||
}
|
||
],
|
||
"source": [
|
||
"with open('../assets/questions.json', encoding='utf-8') as file:\n",
|
||
" q = json.load(file)\n",
|
||
"\n",
|
||
"for qq in q['questions']:\n",
|
||
" if 'upor' in qq['question'] and any(map(lambda a: 'W' in a, qq['answers'])):\n",
|
||
" print(qq)\n",
|
||
"\n",
|
||
"print('---')\n",
|
||
"\n",
|
||
"cmp = set()\n",
|
||
"for c in q['categories']:\n",
|
||
" for f, t in c['questions']:\n",
|
||
" all = list(range(f, t+1))\n",
|
||
" if len(cmp.intersection(all)) != 0:\n",
|
||
" print(f, t, c['title'])\n",
|
||
" print(cmp.intersection(all))\n",
|
||
" print()\n",
|
||
" cmp.update(all)\n",
|
||
"\n",
|
||
"print('---')\n",
|
||
"\n",
|
||
"all = set(range(1, q['questions'][-1]['id']+1))\n",
|
||
"print(len(all), len(cmp))\n",
|
||
"if cmp != all:\n",
|
||
" print(all.difference(cmp))"
|
||
]
|
||
}
|
||
],
|
||
"metadata": {
|
||
"interpreter": {
|
||
"hash": "11938c6bc6919ae2720b4d5011047913343b08a43b18698fd82dedb0d4417594"
|
||
},
|
||
"kernelspec": {
|
||
"display_name": "Python 3.9.7 64-bit",
|
||
"language": "python",
|
||
"name": "python3"
|
||
},
|
||
"language_info": {
|
||
"codemirror_mode": {
|
||
"name": "ipython",
|
||
"version": 3
|
||
},
|
||
"file_extension": ".py",
|
||
"mimetype": "text/x-python",
|
||
"name": "python",
|
||
"nbconvert_exporter": "python",
|
||
"pygments_lexer": "ipython3",
|
||
"version": "3.9.5"
|
||
},
|
||
"orig_nbformat": 4
|
||
},
|
||
"nbformat": 4,
|
||
"nbformat_minor": 2
|
||
}
|