viewof workflowType = Inputs.radio(
["Manual Workflow", "Local Automation", "Client Request"],
{label: null, value: "Manual Workflow"}
)200 OK ... getting your data straight from the source
Automating data workflows
viewof workflowType = Inputs.radio(
["Manual Workflow", "Local Automation", "Client Request"],
{label: null, value: "Manual Workflow"}
)workflowType == "Manual Workflow" ?
mermaid`
%%{init: {'theme': 'base', 'themeVariables': {'fontFamily': 'Century Gothic', 'fontSize': '13px', 'clusterBkg': 'transparent', 'clusterBorder': '#000000'}, 'flowchart': {'nodeSpacing': 38, 'rankSpacing': 35, 'padding': 20, 'diagramPadding': 30}}}%%
flowchart LR
subgraph Web["Source"]
A[("Database")]
end
subgraph Local["Local"]
B[["csv"]]
C["Software"]
E[["svg"]]
end
subgraph Server["Server"]
G{{"Backend"}}
end
subgraph Client["Client"]
H["Browser"]
I[/"Viz"/]
end
A -.->|"πͺ<br>Download"| B
B -.->|"πͺ<br>Import"| C
C -.->|"πͺ<br>Processing"| E
E -.->|"πͺ<br>Upload"| G
G <--> H
H --> I
style Web fill:#336699,color:#fff
style Local fill:#e52320,color:#fff
style Server fill:#9C6B91,color:#fff
style Client fill:#2d8659,color:#fff
style blank1 fill:transparent,stroke:transparent,color:transparent
style A fill:#f5f5f5,stroke:#000,color:#000
style B fill:#f5f5f5,stroke:#000,color:#000
style C fill:#f5f5f5,stroke:#000,color:#000
style E fill:#f5f5f5,stroke:#000,color:#000
style G fill:#f5f5f5,stroke:#000,color:#000
style H fill:#f5f5f5,stroke:#000,color:#000
style I fill:#f5f5f5,stroke:#000,color:#000
` :
workflowType == "Local Automation" ?
mermaid`
%%{init: {'theme': 'base', 'themeVariables': {'fontFamily': 'Century Gothic', 'fontSize': '13px', 'clusterBkg': 'transparent', 'clusterBorder': '#000000'}, 'flowchart': {'nodeSpacing': 15, 'rankSpacing': 35, 'padding': 20, 'diagramPadding': 30}}}%%
flowchart LR
subgraph Local["Local"]
B["Automated Script"]
end
subgraph Web["Source"]
A[("Database")]
end
subgraph Server["Server"]
G{{"Backend"}}
end
subgraph Client["Client"]
H["Browser"]
I[/"Viz"/]
end
B -->|"π€<br>API Request"| A
A -->|"π€<br>API Response"| B
B -->|"π€<br>Upload"| G
G <--> H
H --> I
style Web fill:#336699,color:#fff
style Local fill:#e52320,color:#fff
style Server fill:#9C6B91,color:#fff
style Client fill:#2d8659,color:#fff
style A fill:#f5f5f5,stroke:#000,color:#000
style B fill:#f5f5f5,stroke:#000,color:#000
style G fill:#f5f5f5,stroke:#000,color:#000
style H fill:#f5f5f5,stroke:#000,color:#000
style I fill:#f5f5f5,stroke:#000,color:#000
` :
mermaid`
%%{init: {'theme': 'base', 'themeVariables': {'fontFamily': 'Century Gothic', 'fontSize': '13px', 'clusterBkg': 'transparent', 'clusterBorder': '#000000'}, 'flowchart': {'nodeSpacing': 15, 'rankSpacing': 35, 'padding': 20, 'diagramPadding': 30}}}%%
flowchart LR
subgraph Server["Server"]
G{{"Backend"}}
end
subgraph Client["Client"]
B["Browser"]
C[/"Viz"/]
end
subgraph Web["Source"]
A[("Database")]
end
G <--> B
B -->|"π€<br>API Request"| A
A -->|"π€<br>API Response"| B
B --> C
style Web fill:#336699,color:#fff
style Client fill:#2d8659,color:#fff
style Server fill:#9C6B91,color:#fff
style blank1 fill:transparent,stroke:transparent,color:transparent
style A fill:#f5f5f5,stroke:#000,color:#000
style B fill:#f5f5f5,stroke:#000,color:#000
style C fill:#f5f5f5,stroke:#000,color:#000
style G fill:#f5f5f5,stroke:#000,color:#000
`https://ec.europa.eu/eurostat/api/dissemination/statistics/1.0/
{host_url}/{service}/{version}/
data/nama_10_gdp?format=JSON&time=2023&unit=CP_MEUR&na_item=B1GQ
{response_type}/{datasetCode}?{format}&{filters}
| geo | values |
|---|---|
| EU27_2020 | 17294868.6 |
| EA | 14702286.8 |
| EA21 | 14796811.9 |
| EA20 | 14702286.8 |
| EA19 | 14623100.4 |
| EA12 | 14230050.1 |
| BE | 603141.6 |
| geo | values |
|---|---|
| EU27_2020 | 17294868.6 |
| EA | 14702286.8 |
| EA21 | 14796811.9 |
| EA20 | 14702286.8 |
| EA19 | 14623100.4 |
| EA12 | 14230050.1 |
| BE | 603141.6 |
# Unix
crontab -e
βββββββββ minute (0β59)
β βββββββ hour (0β23)
β β βββββ day of month (1β31)
β β β βββ month (1β12)
β β β β β day of week (0β7, 0 and 7 = Sunday)
β β β β β
0 6 * * * Rscript /home/schmo/Github/test-project/update_data.R| review |
|---|
| One of the other reviewers has mentioned that after watching just 1 Oz episode you'll be hooked. They are right, as this is exactly what happened with.... |
| A wonderful little production. <br /><br />The filming technique is very unassuming- very old-time-BBC fashion and gives a comforting, and sometimes d.... |
| I thought this was a wonderful way to spend time on a too hot summer weekend, sitting in the air conditioned theater and watching a light-hearted come.... |
| Basically there's a family where a little boy (Jake) thinks there's a zombie in his closet & his parents are fighting all the time.<br /><br />This mo.... |
| Petter Mattei's "Love in the Time of Money" is a visually stunning film to watch. Mr. Mattei offers us a vivid portrait about human relations. This is.... |
prompts <- read_csv("data/imdb_small.csv") %>%
select(review) %>%
distinct() %>%
filter(row_number() <= 5)
system_role <- glue("
Classify movie reviews as positive or negative.
Only return the string 'positive' or 'negative'.
Do not respond with any explanations.
")
answers <- data.frame(
review = character(),
predicted = character()
)| review | predicted |
|---|---|
| One of the other reviewers has mentioned that after watching just 1 Oz episode you'll be hooked. The.... | positive |
| A wonderful little production. <br /><br />The filming technique is very unassuming- very old-time-B.... | positive |
| I thought this was a wonderful way to spend time on a too hot summer weekend, sitting in the air con.... | positive |
| Basically there's a family where a little boy (Jake) thinks there's a zombie in his closet & his par.... | negative |
| Petter Mattei's "Love in the Time of Money" is a visually stunning film to watch. Mr. Mattei offers .... | positive |
for (i in 1:nrow(prompts)) {
body <- list(
prompt = paste(
system_role,
"The review is:",
prompts$review[i]
),
max_tokens = 200,
temperature = 0,
stream = FALSE,
model = "llama3.2"
)
ollama_response <- POST(
url = "http://localhost:11434/api/generate",
body = body,
encode = "json"
)
answers[i, 1] <- prompts$review[i]
answers[i, 2] <- content(ollama_response)$response
progress <- round(i/nrow(prompts)*100)
if (i == 1) {cat(" Progress:\n")}
if (i%%10 == 0) {cat(glue(progress, "% \n"))}
}Storing, extracting and manipulating data efficiently
Going beyond csv
library(tidyverse)
library(arrow)
size_csv <-
file.size("data/synthetic_unemployment_data_large.csv")
start_time <- Sys.time()
data <- read_csv("data/synthetic_unemployment_data_large.csv")
end_time <- Sys.time()
time_csv <- end_time - start_time
write_parquet(
data,
"data/synthetic_unemployment_data_large.parquet",
compression = "gzip",
compression_level = 9
)
size_parquet <-
file.size("data/synthetic_unemployment_data_large.parquet")The csv file is 2847 MB large while the the parquet is 227 MB
Efficient data queries
library(duckdb)
library(glue)
con <- dbConnect(duckdb())
cols <- c("target_high", "benefits_amount", "unemployment_1m")
start_time <- Sys.time()
data <- dbGetQuery(con, glue("
SELECT {paste(cols, collapse = ', ')}
FROM 'data/synthetic_unemployment_data_large.parquet'
WHERE promised_employment == 0
"))
end_time <- Sys.time()
time_parquet <- end_time - start_time
dbDisconnect(con, shutdown = TRUE)It took us 15.6 seconds to read in the csv and only 0.4 seconds to make the DuckDB query!
dplyr - data manipulation (filter, select, mutate, summarize)tidyr - data tidying (pivot, separate, unite)magrittr - %>% operatorreadr - data import/exportstringr - string manipulationlubridate - date/time handling[i, j, by] syntax