Skip to content

Commit

Permalink
Oryx updates for 2022-05-06
Browse files Browse the repository at this point in the history
  • Loading branch information
scarnecchia committed May 7, 2022
1 parent fb8b8b4 commit da98018
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
78 changes: 39 additions & 39 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,42 +1,3 @@
heads[l] %>% stringr::str_extract("captured:\\d+") %>%
stringr::str_remove_all("[:alpha:]|[:punct:]")
totals[l, "damaged"] <-
heads[l] %>% stringr::str_extract("damaged: \\d+") %>%
stringr::str_remove_all("[:alpha:]|[:punct:]")
}
totals_df <- totals %>%
dplyr::mutate(
dplyr::across(destroyed:damaged, ~ as.double(tidyr::replace_na(.x, "0"))),
type_total = destroyed + abandoned + captured + damaged,
row_id = 1:n(),
country = dplyr::case_when(row_id < ukr_pos ~ "Russia",
row_id >= ukr_pos ~ "Ukraine")
) %>%
select(-row_id) %>%
dplyr::mutate(
equipment = replace(equipment, rus_pos, "All Types"),
equipment = replace(equipment, ukr_pos, "All Types")
) %>%
dplyr::rename(equipment_type = equipment)
heads <-
get_data(
"https://www.oryxspioenkop.com/2022/02/attack-on-europe-documenting-equipment.html",
"article div"
) %>%
rvest::html_elements("h3") %>%
rvest::html_text2()
# Drop the empty cell padding
heads <- heads[nchar(heads) > 0]
# Get the positons of the Russia and Ukraine headers
rus_pos <- heads %>% stringr::str_which("Russia") %>% as.double()
ukr_pos <- heads %>% stringr::str_which("Ukraine") %>% as.double()
totals <- tibble(
country = character(),
equipment = character(),
destroyed = character(),
abandoned = character(),
captured = character(),
damaged = character()
)
library(rvest)
library(dplyr)
Expand Down Expand Up @@ -510,3 +471,42 @@ file = glue::glue("outputfiles/totals_by_system_wide.csv"))
total_by_type <- totals_by_type() %>%
readr::write_csv(., file = glue::glue("outputfiles/totals_by_type.csv"))
rmarkdown::render("index.Rmd")
renv::restore()
library(rvest)
library(dplyr)
library(tidyr)
library(lubridate)
library(purrr)
library(magrittr)
library(tibble)
library(stringr)
library(readr)
library(glue)
library(logr)
library(ggplot2)
library(scales)
library(ggthemes)
source("R/functions.R")
source("R/scrape_data.R")
source("R/totals_by_type.R")
source("R/per_event.R")
source("R/daily_count.R")
russia_url <- "https://www.oryxspioenkop.com/2022/02/attack-on-europe-documenting-equipment.html"
ukraine_url <- "https://www.oryxspioenkop.com/2022/02/attack-on-europe-documenting-ukrainian.html"
# tmp <-
# file.path("outputfiles", sprintf("scrape_oryx_%s.log", format(Sys.time(), "%Y%m%dT%H%M%S")))
#lf <- logr::log_open(tmp)
today <- format(Sys.Date(), "%Y-%m-%d")
totals_by_system <- create_data() %>%
readr::write_csv(., file = glue::glue("outputfiles/totals_by_system.csv"))
View(totals_by_system)
#' Write Event Tables
create_event_tables(totals_by_system, status)
totals_by_system_wide <- total_by_system_wide(totals_by_system) %>%
readr::write_csv(.,
file = glue::glue("outputfiles/totals_by_system_wide.csv"))
total_by_type <- totals_by_type() %>%
readr::write_csv(., file = glue::glue("outputfiles/totals_by_type.csv"))
daily_count <- daily_count() %>%
readr::write_csv(., file = "outputfiles/daily_count.csv")
rmarkdown::render("index.Rmd")
3 changes: 1 addition & 2 deletions R/scrape_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ create_data <- function() {

previous %>% readr::write_csv("inputfiles/totals_by_system.csv.bak")

data %>% readr::write_csv(glue::glue(
"inputfiles/totals_by_system{lubridate::today()+1}.csv"))
data %>% readr::write_csv(glue::glue("inputfiles/totals_by_system{lubridate::today()+1}.csv"))
} else {
data <- previous
}
Expand Down

0 comments on commit da98018

Please sign in to comment.