Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# End of https://www.toptal.com/developers/gitignore/api/python
63 changes: 56 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# hackathon-season2

## USAGE
To generate CSV from XML:
> python xml2csv.py

```text
usage: xml2csv.py [-h] [--xml XML] [--csv CSV] [--convert-default]

optional arguments:
-h, --help show this help message and exit
--xml XML Specify the name of a xml file to read from.
--csv CSV Specify the name of a csv file to write to.
--convert-default Convert active 3 years experience+ Airhostess, Pilot, Steward to csv file without duplicate ID and passport number.
```

To execute DAL and generate JSON:
> python csv2sqlite.py
```text
usage: csv2sqlite.py [-h] [--csv CSV] [--json JSON] [--database DATABASE] [--table-name TABLE_NAME] [--region-param REGION_PARAM] [--dept-param DEPT_PARAM] [--nation-param NATION_PARAM]

optional arguments:
-h, --help show this help message and exit
--csv CSV Specify a csv file.
--json JSON Specify a json outfile.
--database DATABASE Specify the name of a database file to write to.
--table-name TABLE_NAME
Specify the name of a table
--region-param REGION_PARAM
Specify parameter for SQLite View region-based query
--dept-param DEPT_PARAM
Specify parameter for SQLite View department-based query
--nation-param NATION_PARAM
Specify parameter for SQLite View nationality-based query

```

## เลข Status จะมีตามนี้ครับ
- 1 = Active
- 2 = Resigned
Expand Down Expand Up @@ -28,15 +63,29 @@
- Creative ตอนทำ Data visualization
- ผลลัพธ์จาก SQLlite ต้องได้เป็น **JSON** format

**ตัวอย่าง Data visualization**
[**Data visualization**](data-visualization.ipynb)

*Gender2 is data after database migration*

![alt text](images/1.png)
![alt text](images/2.png)
![alt text](images/3.png)
![alt text](images/4.png)
![alt text](images/5.png)
![alt text](images/6.png)
![alt text](images/7.png)
![alt text](images/8.png)
![alt text](images/9.png)
![alt text](images/10.png)


[dev-mountain-visualization](https://dev-moutain-dataviz.netlify.app/)


## ตัวอย่างการสร้าง PR
ทีม Dev mountain
## การสร้าง PR
ทีม นอนต่อเลยได้ไหม
สมาชิก
- [annibuliful](https://github.com/annibuliful)
- [lordbenz](https://github.com/lordbenz)
- [N.SX](https://github.com/rsxss)
- [Sathipp](https://github.com/Sathipp)
- [Jiruschai](https://github.com/JirusAnun)

Repo: [hackathon](https://github.com/devmountaintechfest/hackathon-season2)
Repo: [hackathon](https://github.com/rsxss/hackathon-season2)
146 changes: 146 additions & 0 deletions csv2sqlite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import argparse
import csv
import collections
import json
import sqlite3

from contextlib import closing


def _json_dumps(objects):
output = {}
for i, obj in enumerate(objects):
output[i] = []
for emp in map(EMPLOYEE_RECORD._make, iter(obj)):
output[i].append(emp._asdict())
return json.dumps(output, indent=2)


def main():
with closing(sqlite3.connect(DATABASE)) as conn, open(
CSV_FILE, "r"
) as infile, open(JSON_FILE, "w") as outfile:
csv_dict_reader = csv.DictReader(infile)
payload = (
list(map(lambda struct: record[struct], TABLE_SCHEMA))
for record in csv_dict_reader
)

with conn as cur:
cur.execute(
f"CREATE TABLE IF NOT EXISTS {TABLE_NAME}({JOINED_TABLE_SCHEMA})"
)
cur.execute(
f"CREATE VIEW IF NOT EXISTS `VIEW_EMP_REGION` AS SELECT * FROM {TABLE_NAME} ORDER BY REGION"
)
cur.execute(
f"CREATE VIEW IF NOT EXISTS `VIEW_EMP_DEPARTMENT` AS SELECT * FROM {TABLE_NAME} ORDER BY DEPT"
)
cur.execute(
f"CREATE VIEW IF NOT EXISTS `VIEW_EMP_NATIONALITY` AS SELECT * FROM {TABLE_NAME} ORDER BY NATIONALITY"
)

try:
cur.executemany(
f'INSERT INTO {TABLE_NAME} VALUES (?{", ?" * (len(TABLE_SCHEMA) - 1)})',
payload,
)
except sqlite3.IntegrityError:
pass

result_sets = [
cur.execute(
"SELECT * FROM `VIEW_EMP_REGION` WHERE REGION = ?",
(args.region_param,),
),
cur.execute(
"SELECT * FROM `VIEW_EMP_DEPARTMENT` WHERE DEPT = ?",
(args.dept_param,),
),
cur.execute(
"SELECT * FROM `VIEW_EMP_NATIONALITY` WHERE NATIONALITY = ?",
(args.nation_param,),
),
]
outfile.write(_json_dumps(result_sets))


if __name__ == "__main__":
parser = argparse.ArgumentParser()

parser.add_argument(
"--csv",
default="data-devclub-1.csv",
help="Specify a csv file."
)
parser.add_argument(
"--json",
default="data-devclub-1.json",
help="Specify a json outfile."
)
parser.add_argument(
"--database",
default="data-devclub-1.db",
help="Specify the name of a database file to write to.",
)
parser.add_argument(
"--table-name",
default="TBL_DEVCLUB",
help="Specify the name of a table"
)
parser.add_argument(
"--region-param",
default="Europe",
help="Specify parameter for SQLite View region-based query",
)
parser.add_argument(
"--dept-param",
default="Flight Planning",
help="Specify parameter for SQLite View department-based query",
)
parser.add_argument(
"--nation-param",
default="Ukraine",
help="Specify parameter for SQLite View nationality-based query",
)

args = parser.parse_args()

if not args.csv:
print("[-] Please specify a csv file.")
exit(1)

if not args.database:
print("[-] Please specify the name of a database file to write to.")
exit(1)

if not args.table_name:
print("[-] Please specify the name of a table.")
exit(1)

CSV_FILE = args.csv
JSON_FILE = args.json
DATABASE = args.database
TABLE_NAME = args.table_name
TABLE_SCHEMA = {
"EMPID": "INTEGER PRIMARY KEY",
"PASSPORT": "CHAR(11) NOT NULL UNIQUE",
"FIRSTNAME": "VARCHAR(255)",
"LASTNAME": "VARCHAR(255)",
"GENDER": "INT2",
"BIRTHDAY": "CHAR(10)",
"NATIONALITY": "VARCHAR(56)",
"HIRED": "CHAR(10)",
"DEPT": "VARCHAR(56)",
"POSITION": "VARCHAR(56)",
"STATUS": "TINYINT",
"REGION": "VARCHAR(85)",
}

JOINED_TABLE_SCHEMA = ",\n".join(
(f"{struct} {domain}" for struct, domain in TABLE_SCHEMA.items())
)

EMPLOYEE_RECORD = collections.namedtuple("EmployeeRecord", ",".join(TABLE_SCHEMA))

main()
2 changes: 2 additions & 0 deletions data-devclub-1-France.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EMPID,PASSPORT,FIRSTNAME,LASTNAME,GENDER,BIRTHDAY,NATIONALITY,HIRED,DEPT,POSITION,STATUS,REGION
93,UXL43IOW6OV,Honorato,Maxwell,1,09-03-1982,France,04-02-2017,Aircraft Maintenance,Airhostess,1,Europe
2 changes: 2 additions & 0 deletions data-devclub-1-Germany.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EMPID,PASSPORT,FIRSTNAME,LASTNAME,GENDER,BIRTHDAY,NATIONALITY,HIRED,DEPT,POSITION,STATUS,REGION
29,CMK62UAD3VK,Rowan,Leonard,1,15-07-1974,Germany,27-03-2004,Aircraft Maintenance,Pilot,1,Ocenia
Loading