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
read_shp <- function(filepath) { | |
# If zipped | |
if (stringr::str_ends(filepath, ".zip")) { | |
temp1 <- tempfile() | |
unzip(zipfile = filepath, exdir = temp1) | |
d <- sf::read_sf(temp1) | |
unlink(temp1, recursive = TRUE) | |
return(d) | |
} | |
# If not zipped |
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
color_name | hex_rgb | decimal_rgb | type | |
---|---|---|---|---|
aliceblue | #F0F8FF | 240,248,255 | extended | |
antiquewhite | #FAEBD7 | 250,235,215 | extended | |
aqua | #00FFFF | 0,255,255 | basic | |
aquamarine | #7FFFD4 | 127,255,212 | extended | |
azure | #F0FFFF | 240,255,255 | extended | |
beige | #F5F5DC | 245,245,220 | extended | |
bisque | #FFE4C4 | 255,228,196 | extended | |
black | #000000 | 0,0,0 | basic | |
blanchedalmond | #FFEBCD | 255,235,205 | extended |
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
ts_to_df <- function(ts_data) { | |
dates <- xts:::as.Date.POSIXct(zoo::yearmon(time(ts_data))) | |
values <- zoo::coredata(ts_data) |> | |
tibble::as_tibble() | |
tibble::tibble(date = dates) |> | |
dplyr::bind_cols(values) | |
} | |
HoltWinters_to_df <- function(fcst) { | |
xs <- ts_to_df(fcst$model$x) |> |
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 datetime as dt | |
import getpass | |
import os | |
import subprocess | |
import zlib | |
from pathlib import Path | |
def compute_crc32(filepath: Path) -> dict[str, str]: |
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: |
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
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 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
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" |
NewerOlder