Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve duplicate data issue in data preparation scripts #163

Open
hepplerj opened this issue Dec 16, 2024 · 1 comment
Open

Resolve duplicate data issue in data preparation scripts #163

hepplerj opened this issue Dec 16, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@hepplerj
Copy link
Member

While working on #146 I've discovered an issue with the weekly data getting duplicate data, which I discovered with some new CONSTRAINT checks in PostgreSQL. I'll want to 1) make sure this isn't present in the DataScribe export first; and then, 2) resolve where the data is duplicated and ensure it's getting addressed properly.

@hepplerj hepplerj added the bug Something isn't working label Dec 16, 2024
@hepplerj hepplerj self-assigned this Dec 16, 2024
@hepplerj
Copy link
Member Author

hepplerj commented Dec 16, 2024

A quick check of the data as it loads shows there are no duplicate items. I checked with the following:

# After initial data loads, check each source of weekly bills
check_weekly_source <- function(data, source_name) {
  message(sprintf("\n=== Checking %s Weekly Bills Source Data ===", source_name))
  
  # Check for complete duplicates
  total_rows <- nrow(data)
  distinct_rows <- nrow(distinct(data))
  duplicates <- total_rows - distinct_rows
  
  # Check for duplicates based on key fields
  key_dupes <- data %>%
    group_by(`DataScribe Item #`, Year) %>%
    filter(n() > 1)
  
  message(sprintf("Total rows: %d", total_rows))
  message(sprintf("Distinct rows: %d", distinct_rows))
  message(sprintf("Complete duplicate rows: %d", duplicates))
  message(sprintf("Rows with duplicate keys: %d", nrow(key_dupes)))
  
  if(nrow(key_dupes) > 0) {
    message("\nSample of rows with duplicate keys:")
    print(head(key_dupes, 5))
  }
  
  return(duplicates > 0 || nrow(key_dupes) > 0)
}

# Check each source
check_weekly_source(`1669_1670_Wellcome_weeklybills_parishes`, "Wellcome")
check_weekly_source(Laxton_1700_weeklybills_causes, "Laxton")
check_weekly_source(BLV1_weeklybills_parishes, "Bodleian V1")
check_weekly_source(BLV2_weeklybills_parishes, "Bodleian V2")
check_weekly_source(BLV3_weeklybills_parishes, "Bodleian V3")

Which leads me to think the rbind I do in the weeks data is causing some duplication of records.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant