pysus 0.1.1__py3.5-linux-x86_64.egg
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- EGG-INFO/PKG-INFO +23 -0
- EGG-INFO/SOURCES.txt +18 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/native_libs.txt +2 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/requires.txt +3 -0
- EGG-INFO/top_level.txt +1 -0
- _readdbc.cpython-35m-x86_64-linux-gnu.so +0 -0
- pysus/__init__.py +0 -0
- pysus/__pycache__/__init__.cpython-35.pyc +0 -0
- pysus/preprocessing/__init__.py +8 -0
- pysus/preprocessing/__pycache__/__init__.cpython-35.pyc +0 -0
- pysus/preprocessing/__pycache__/decoders.cpython-35.pyc +0 -0
- pysus/preprocessing/decoders.py +36 -0
- pysus/tests/__init__.py +8 -0
- pysus/tests/__pycache__/__init__.cpython-35.pyc +0 -0
- pysus/tests/__pycache__/test_decoders.cpython-35.pyc +0 -0
- pysus/tests/__pycache__/test_utilities.cpython-35.pyc +0 -0
- pysus/tests/test_decoders.py +35 -0
- pysus/tests/test_utilities.py +18 -0
- pysus/utilities/__init__.py +6 -0
- pysus/utilities/__pycache__/__init__.cpython-35.pyc +0 -0
- pysus/utilities/__pycache__/_build_readdbc.cpython-35.pyc +0 -0
- pysus/utilities/__pycache__/_readdbc.cpython-35.pyc +0 -0
- pysus/utilities/__pycache__/readdbc.cpython-35.pyc +0 -0
- pysus/utilities/_build_readdbc.py +32 -0
- pysus/utilities/_readdbc.cpython-35m-x86_64-linux-gnu.so +0 -0
- pysus/utilities/_readdbc.py +7 -0
- pysus/utilities/readdbc.py +45 -0
EGG-INFO/PKG-INFO
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Metadata-Version: 1.0
|
|
2
|
+
Name: PySUS
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Tools for dealing with Brazil's Public health data
|
|
5
|
+
Home-page: UNKNOWN
|
|
6
|
+
Author: Flavio Codeco Coelho
|
|
7
|
+
Author-email: fccoelho@gmail.com
|
|
8
|
+
License: gpl-v3
|
|
9
|
+
Description: # PySUS
|
|
10
|
+
|
|
11
|
+
This package collects a set of utilities for handling with public databases published by Brazil's DATASUS
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Decode encoded patient age to any time unit (years, months, etc)
|
|
16
|
+
- Convert `.dbc` files to DBF databases or read them into pandas dataframes. DBC files are basically DBFs compressed by a proprietary algorithm.
|
|
17
|
+
|
|
18
|
+
## Instalation
|
|
19
|
+
|
|
20
|
+
`
|
|
21
|
+
$ sudo pip install PySUS`
|
|
22
|
+
|
|
23
|
+
Platform: UNKNOWN
|
EGG-INFO/SOURCES.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
setup.py
|
|
2
|
+
PySUS.egg-info/PKG-INFO
|
|
3
|
+
PySUS.egg-info/SOURCES.txt
|
|
4
|
+
PySUS.egg-info/dependency_links.txt
|
|
5
|
+
PySUS.egg-info/not-zip-safe
|
|
6
|
+
PySUS.egg-info/requires.txt
|
|
7
|
+
PySUS.egg-info/top_level.txt
|
|
8
|
+
pysus/__init__.py
|
|
9
|
+
pysus/preprocessing/__init__.py
|
|
10
|
+
pysus/preprocessing/decoders.py
|
|
11
|
+
pysus/tests/__init__.py
|
|
12
|
+
pysus/tests/test_decoders.py
|
|
13
|
+
pysus/tests/test_utilities.py
|
|
14
|
+
pysus/utilities/__init__.py
|
|
15
|
+
pysus/utilities/_build_readdbc.py
|
|
16
|
+
pysus/utilities/_readdbc.cpython-35m-x86_64-linux-gnu.so
|
|
17
|
+
pysus/utilities/readdbc.py
|
|
18
|
+
pysus/utilities/c-src/blast.c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
EGG-INFO/native_libs.txt
ADDED
EGG-INFO/not-zip-safe
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
EGG-INFO/requires.txt
ADDED
EGG-INFO/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pysus
|
|
Binary file
|
pysus/__init__.py
ADDED
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#-*- coding:utf-8 -*-
|
|
2
|
+
u"""
|
|
3
|
+
This module contains a set of functions to decode
|
|
4
|
+
commonly encoded variables
|
|
5
|
+
Created on 19/07/16
|
|
6
|
+
by fccoelho
|
|
7
|
+
license: GPL V3 or Later
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__docformat__ = 'restructuredtext en'
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
@np.vectorize
|
|
14
|
+
def decodifica_idade(idade, unidade='Y'):
|
|
15
|
+
"""
|
|
16
|
+
Em tabelas do SINAN frequentemente a idade é representada como um inteiro que precisa ser parseado
|
|
17
|
+
para retornar a idade em uma unidade cronológica padrão.
|
|
18
|
+
:param unidade: unidade da idade: 'Y': anos, 'M' meses, 'D': dias, 'H': horas
|
|
19
|
+
:param idade: inteiro ou sequencia de inteiros codificados.
|
|
20
|
+
:return:
|
|
21
|
+
"""
|
|
22
|
+
fator = {'Y': 1, 'M': 12, 'D': 365, 'H': 365*24}
|
|
23
|
+
if idade >= 4000: #idade em anos
|
|
24
|
+
idade_anos = idade - 4000
|
|
25
|
+
elif idade >= 3000 and idade < 4000: #idade em meses
|
|
26
|
+
idade_anos = (idade-3000)/12
|
|
27
|
+
elif idade >= 2000 and idade < 3000: #idade em dias
|
|
28
|
+
idade_anos = (idade-2000)/365
|
|
29
|
+
elif idade >= 1000 and idade < 2000: # idade em horas
|
|
30
|
+
idade_anos = (idade-1000)/(365*24)
|
|
31
|
+
else:
|
|
32
|
+
#print(idade)
|
|
33
|
+
idade_anos = np.nan
|
|
34
|
+
#raise ValueError("Idade inválida")
|
|
35
|
+
idade_dec = idade_anos/fator[unidade]
|
|
36
|
+
return idade_dec
|
pysus/tests/__init__.py
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding:utf-8 -*-
|
|
2
|
+
u"""
|
|
3
|
+
Created on 19/07/16
|
|
4
|
+
by fccoelho
|
|
5
|
+
license: GPL V3 or Later
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import unittest
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
from numpy.testing import *
|
|
12
|
+
|
|
13
|
+
from pysus.preprocessing import decoders
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestDecoder(unittest.TestCase):
|
|
17
|
+
def test_decodifica_idade_retorna_em_anos(self):
|
|
18
|
+
res = decoders.decodifica_idade(4010, unidade='Y')
|
|
19
|
+
self.assertEqual(res, 10)
|
|
20
|
+
res = decoders.decodifica_idade(3120, unidade='Y')
|
|
21
|
+
self.assertEqual(res, 10)
|
|
22
|
+
res = decoders.decodifica_idade(2365, unidade='Y')
|
|
23
|
+
self.assertAlmostEqual(res, 1, places=4)
|
|
24
|
+
res = decoders.decodifica_idade(1480, unidade='Y')
|
|
25
|
+
self.assertAlmostEqual(res, 0.0547, places=3)
|
|
26
|
+
|
|
27
|
+
def test_decodifica_lista_idades_retorna_em_anos(self):
|
|
28
|
+
res = decoders.decodifica_idade([4010] * 3, unidade='Y')
|
|
29
|
+
assert_array_equal(res, np.array([10] * 3))
|
|
30
|
+
res = decoders.decodifica_idade([3120] * 4, unidade='Y')
|
|
31
|
+
assert_array_equal(res, np.array([10] * 4))
|
|
32
|
+
res = decoders.decodifica_idade([2365] * 2, unidade='Y')
|
|
33
|
+
assert_array_equal(res, np.array([1, 1]))
|
|
34
|
+
res = decoders.decodifica_idade([1480] * 5, unidade='Y')
|
|
35
|
+
assert_array_almost_equal(res, np.array([0.0547] * 5), decimal=3)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
u"""
|
|
2
|
+
Created on 17/08/16
|
|
3
|
+
by fccoelho
|
|
4
|
+
license: GPL V3 or Later
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import unittest
|
|
8
|
+
|
|
9
|
+
import pandas as pd
|
|
10
|
+
|
|
11
|
+
from pysus.utilities.readdbc import read_dbc
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestReadDbc(unittest.TestCase):
|
|
15
|
+
def test_read_dbc(self):
|
|
16
|
+
df = read_dbc(b'test_data/sids.dbc')
|
|
17
|
+
self.assertIsInstance(df, pd.DataFrame)
|
|
18
|
+
self.assertGreater(df.size, 0)
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
u"""
|
|
2
|
+
Created on 16/08/16
|
|
3
|
+
by fccoelho
|
|
4
|
+
license: GPL V3 or Later
|
|
5
|
+
"""
|
|
6
|
+
import os
|
|
7
|
+
from cffi import FFI
|
|
8
|
+
|
|
9
|
+
ffibuilder = FFI()
|
|
10
|
+
|
|
11
|
+
PATH = os.path.dirname(__file__)
|
|
12
|
+
|
|
13
|
+
with open(os.path.join(PATH, 'c-src/dbc2dbf.c'),'r') as f:
|
|
14
|
+
ffibuilder.set_source("pysus.utilities._readdbc",
|
|
15
|
+
f.read(),
|
|
16
|
+
libraries=["c"],
|
|
17
|
+
sources=[os.path.join(PATH, "c-src/blast.c")],
|
|
18
|
+
include_dirs=[os.path.join(PATH, "c-src/")]
|
|
19
|
+
)
|
|
20
|
+
ffibuilder.cdef(
|
|
21
|
+
"""
|
|
22
|
+
static unsigned inf(void *how, unsigned char **buf);
|
|
23
|
+
static int outf(void *how, unsigned char *buf, unsigned len);
|
|
24
|
+
void dbc2dbf(char** input_file, char** output_file);
|
|
25
|
+
"""
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
with open(os.path.join(PATH, "c-src/blast.h")) as f:
|
|
29
|
+
ffibuilder.cdef(f.read(), override=True)
|
|
30
|
+
|
|
31
|
+
if __name__ == "__main__":
|
|
32
|
+
ffibuilder.compile(verbose=True)
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
def __bootstrap__():
|
|
2
|
+
global __bootstrap__, __loader__, __file__
|
|
3
|
+
import sys, pkg_resources, imp
|
|
4
|
+
__file__ = pkg_resources.resource_filename(__name__, '_readdbc.cpython-35m-x86_64-linux-gnu.so')
|
|
5
|
+
__loader__ = None; del __bootstrap__, __loader__
|
|
6
|
+
imp.load_dynamic(__name__,__file__)
|
|
7
|
+
__bootstrap__()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
u"""
|
|
2
|
+
Created on 16/08/16
|
|
3
|
+
by fccoelho
|
|
4
|
+
license: GPL V3 or Later
|
|
5
|
+
"""
|
|
6
|
+
import os
|
|
7
|
+
from tempfile import NamedTemporaryFile
|
|
8
|
+
|
|
9
|
+
import pandas as pd
|
|
10
|
+
from dbfread import DBF
|
|
11
|
+
|
|
12
|
+
from pysus.utilities._readdbc import ffi, lib
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def read_dbc(filename, encoding='utf-8'):
|
|
16
|
+
"""
|
|
17
|
+
Opens a DATASUS .dbc file and return its contents as a pandas
|
|
18
|
+
Dataframe.
|
|
19
|
+
:param filename: .dbc filename
|
|
20
|
+
:param encoding: encoding of the data
|
|
21
|
+
:return: Pandas Dataframe.
|
|
22
|
+
"""
|
|
23
|
+
with NamedTemporaryFile() as tf:
|
|
24
|
+
dbc2dbf(filename, tf.name.encode())
|
|
25
|
+
dbf = DBF(tf.name, encoding=encoding)
|
|
26
|
+
df = pd.DataFrame(list(dbf))
|
|
27
|
+
return df
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def dbc2dbf(infile, outfile):
|
|
31
|
+
"""
|
|
32
|
+
Converts a DATASUS dbc file to a DBF database.
|
|
33
|
+
:param infile: .dbc file name
|
|
34
|
+
:param outfile: name of the .dbf file to be created.
|
|
35
|
+
"""
|
|
36
|
+
p = ffi.new('char[]', os.path.abspath(infile))
|
|
37
|
+
q = ffi.new('char[]', os.path.abspath(outfile))
|
|
38
|
+
|
|
39
|
+
lib.dbc2dbf([p], [q])
|
|
40
|
+
|
|
41
|
+
print(os.path.exists(outfile))
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
dbc2dbf(b'/tmp/DNRJ2014.dbc', b'/tmp/output.dbf')
|
|
45
|
+
|