Skip to content

Commit df15c43

Browse files
committed
dboperations module initial version added, some minor changes in plotek.py and combinations.py
1 parent 2812170 commit df15c43

5 files changed

Lines changed: 148 additions & 34 deletions

File tree

.idea/workspace.xml

Lines changed: 80 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

combinations.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@
44
# Combinations and probability of win module
55
# author: Bart Grzybicki <[email protected]>
66

7-
87
def splitthousands(s, sep = ','):
98
if len(s) <= 3: return s
109
return splitthousands(s[:-3], sep) + sep + s[-3:]
1110

12-
1311
def factorial(x):
1412
if x == 0:
1513
return 1
1614
else:
1715
return x * factorial(x-1)
1816

19-
2017
def combinations(nums, numsdrawed):
2118
n = factorial(nums)
2219
k = factorial(numsdrawed) * factorial(nums - numsdrawed)
2320
comb = n / k
2421
comb = int(comb)
2522
return comb
2623

27-
2824
def matched(nums, numsdrawed, matched, k = 20):
2925
n = nums
3026
r = numsdrawed

dboperations.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# SQLite3 db operations module
5+
# author: Bart Grzybicki <[email protected]>
6+
7+
import sqlite3
8+
9+
def create_db(db_name):
10+
try:
11+
db = sqlite3.connect(db_name)
12+
c = db.cursor()
13+
14+
c.execute('''CREATE TABLE DL_RAZEM
15+
(ID TEXT PRIMARY KEY,
16+
DATA TEXT,
17+
LICZBY TEXT);''')
18+
19+
c.execute('''CREATE TABLE EL
20+
(ID TEXT PRIMARY KEY,
21+
DATA TEXT,
22+
LICZBY TEXT);''')
23+
24+
c.execute('''CREATE TABLE ML
25+
(ID TEXT PRIMARY KEY,
26+
DATA TEXT,
27+
LICZBY TEXT);''')
28+
except sqlite3.Error as e:
29+
print('Błąd utworzenia bazy danych!')
30+
finally:
31+
if db:
32+
db.close()
33+
34+
def insert(db_name, table, data_dict):
35+
try:
36+
db = sqlite3.connect(db_name)
37+
c = db.cursor()
38+
39+
if table == 'DL_RAZEM':
40+
c.execute('''INSERT INTO DL_RAZEM(ID, DATA, LICZBY)
41+
VALUES(?, ?, ?)''', (data_dict['id'], data_dict['data'], data_dict['liczby'],))
42+
elif table == 'EL':
43+
c.execute('''INSERT INTO EL(ID, DATA, LICZBY)
44+
VALUES(?, ?, ?)''', (data_dict['id'], data_dict['data'], data_dict['liczby'],))
45+
elif table == 'ML':
46+
c.execute('''INSERT INTO ML(ID, DATA, LICZBY)
47+
VALUES(?, ?, ?)''', (data_dict['id'], data_dict['data'], data_dict['liczby'],))
48+
db.commit()
49+
except sqlite3.Error as e:
50+
print('Błąd SQLite3: ' + e.args[0])
51+
print('Błąd importu losowań do bazy danych!')
52+
finally:
53+
if db:
54+
db.close()
55+
56+
def main():
57+
db = 'test.db'
58+
tbl = 'ML'
59+
#liczby = [1, 2, 3, 4, 5, 6]
60+
liczby = '1,2,3,4,5,6'
61+
data = {'id': '999', 'data': '2014.11.07', 'liczby': liczby}
62+
print('dboperations module')
63+
create_db(db)
64+
insert(db, tbl, data)
65+
66+
if __name__ == '__main__':
67+
main()

plotek.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import random, os, platform, sys, csv, shutil
99
# importing local modules:
10-
import combinations
10+
import combinations, dboperations
1111

1212
try:
1313
# For Python 3.0 and later

test.db

7 KB
Binary file not shown.

0 commit comments

Comments
 (0)