This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unicodedata | |
def strip_accents(s): | |
return ''.join(c for c in unicodedata.normalize('NFD', s) | |
if unicodedata.category(c) != 'Mn') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sqrt | |
import numpy | |
# https://stackoverflow.com/a/48085583 | |
def cubic_interp1d(x0, x, y): | |
""" | |
Interpolate a 1-D function using cubic splines. | |
x0 : a float or an 1d-array | |
x : (N,) array_like |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecs | |
import os.path | |
def read(rel_path): | |
here = os.path.abspath(os.path.dirname(__file__)) | |
with codecs.open(os.path.join(here, rel_path), 'r') as fp: | |
return fp.read() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Tuple | |
from pyproj import Proj | |
def convert_utm_to_longlat(x: int, y: int, zone: int, south: bool = False) -> Tuple[float, float]: | |
longlat_proj = Proj(proj="utm", zone=zone, ellps="WGS84", south=south) | |
long, lat = longlat_proj(x, y, inverse=True) | |
return long, lat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt update | |
apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev liblzma-dev | |
PYTHON_VERSION=3.10.1 | |
N_PROCESSORS=$(nproc) | |
wget https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz | |
tar -xf "Python-$PYTHON_VERSION.tgz" | |
cd "Python-$PYTHON_VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def convert_brl_date(value: float, date: datetime.date) -> float: | |
"""Convert brazillian currency to Real (BRL), given the date of the value. | |
Works with dates from 1942-11-01 to today. | |
""" | |
if date >= datetime.date(1994, 7, 1): # R$ | |
return value | |
elif date >= datetime.date(1993, 8, 1): # CR$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
decodificar_datasus_idade <- function(nu_idade_n) { | |
nu_idade_n <- as.character(nu_idade_n) | |
nu_idade_n[nu_idade_n == "000" | nu_idade_n == "999"] <- NA | |
unidade <- substr(nu_idade_n, 1, 1) | |
idade <- ifelse( | |
unidade == 1, | |
as.numeric(substr(nu_idade_n, 2, 3)) / (24*365), # horas | |
ifelse( | |
unidade == 2, | |
as.numeric(substr(nu_idade_n, 2, 3)) / 365, # dias |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import csv | |
import json | |
# Converts the JSON output of a PowerBI query to a CSV file | |
def extract(input_file, output_file): | |
input_json = read_json(input_file) | |
data = input_json["results"][0]["result"]["data"] | |
dm0 = data["dsr"]["DS"][0]["PH"][0]["DM0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import re | |
import shutil | |
import zipfile | |
from pathlib import Path | |
def decompress(filepath: Path) -> Path: | |
dest_filepath = Path(filepath.stem) | |
with zipfile.ZipFile(filepath, "r") as zf: |
OlderNewer