This file contains hidden or 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 logging | |
| from logging import handlers | |
| from pathlib import Path | |
| def setup_logging(logger_name: str, log_filepath: Path): | |
| logger = logging.getLogger(logger_name) | |
| logger.setLevel(logging.DEBUG) | |
| logger.propagate = False |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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$ |
NewerOlder