Spaces:
Sleeping
Sleeping
phantomas34 commited on
Commit Β·
f814daa
1
Parent(s): 94be514
Seed IMS tables (follow-ups, NLP scores, projects) into DuckDB for Client/Revenue Intelligence
Browse files- Dockerfile +1 -0
- data/bid___follow_up.csv +0 -0
- data/follow_up_scores.csv +0 -0
- data/pm___project_file.csv +0 -0
- data/project_file.csv +0 -0
- seed_data.R +41 -0
Dockerfile
CHANGED
|
@@ -13,6 +13,7 @@ RUN install2.r --error --skipinstalled --ncpus -1 \
|
|
| 13 |
WORKDIR /srv/shiny-server
|
| 14 |
COPY global.R ui.R server.R mod_cohort_analysis.R seed_data.R ./
|
| 15 |
COPY Bid_SalesAnalysisByEstimatorByMonth_121125.csv ./
|
|
|
|
| 16 |
|
| 17 |
EXPOSE 7860
|
| 18 |
CMD ["R", "-e", "shiny::runApp('/srv/shiny-server', host='0.0.0.0', port=7860)"]
|
|
|
|
| 13 |
WORKDIR /srv/shiny-server
|
| 14 |
COPY global.R ui.R server.R mod_cohort_analysis.R seed_data.R ./
|
| 15 |
COPY Bid_SalesAnalysisByEstimatorByMonth_121125.csv ./
|
| 16 |
+
COPY data ./data/
|
| 17 |
|
| 18 |
EXPOSE 7860
|
| 19 |
CMD ["R", "-e", "shiny::runApp('/srv/shiny-server', host='0.0.0.0', port=7860)"]
|
data/bid___follow_up.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/follow_up_scores.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/pm___project_file.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/project_file.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
seed_data.R
CHANGED
|
@@ -23,3 +23,44 @@ local({
|
|
| 23 |
dbWriteTable(conn, "monthly_sales", monthly_sales, overwrite = TRUE)
|
| 24 |
poolReturn(conn)
|
| 25 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
dbWriteTable(conn, "monthly_sales", monthly_sales, overwrite = TRUE)
|
| 24 |
poolReturn(conn)
|
| 25 |
})
|
| 26 |
+
|
| 27 |
+
# ββ IMS TABLES (Client & Revenue Intelligence) β seeded from data/*.csv ββββββ
|
| 28 |
+
# Defensive: any missing/bad file is skipped so app startup never fails.
|
| 29 |
+
local({
|
| 30 |
+
conn <- poolCheckout(db_pool)
|
| 31 |
+
on.exit(poolReturn(conn))
|
| 32 |
+
|
| 33 |
+
load_csv <- function(tbl) {
|
| 34 |
+
f <- file.path("data", paste0(tbl, ".csv"))
|
| 35 |
+
if (!file.exists(f)) { message(sprintf("[seed] skip %s (no file)", tbl)); return(FALSE) }
|
| 36 |
+
ok <- tryCatch({
|
| 37 |
+
dbExecute(conn, sprintf(
|
| 38 |
+
"CREATE OR REPLACE TABLE %s AS SELECT * FROM read_csv_auto('%s', header=true, nullstr='NA', sample_size=-1)",
|
| 39 |
+
tbl, f)); TRUE
|
| 40 |
+
}, error = function(e) { message(sprintf("[seed] load %s FAILED: %s", tbl, conditionMessage(e))); FALSE })
|
| 41 |
+
if (ok) message(sprintf("[seed] loaded %s (%s rows)", tbl,
|
| 42 |
+
dbGetQuery(conn, sprintf("SELECT COUNT(*) n FROM %s", tbl))$n))
|
| 43 |
+
ok
|
| 44 |
+
}
|
| 45 |
+
retype <- function(tbl, cols, type) for (c in cols) tryCatch(
|
| 46 |
+
dbExecute(conn, sprintf("ALTER TABLE %s ALTER COLUMN %s TYPE %s", tbl, c, type)),
|
| 47 |
+
error = function(e) message(sprintf("[seed] %s.%s -> %s skipped: %s", tbl, c, type, conditionMessage(e))))
|
| 48 |
+
|
| 49 |
+
if (load_csv("bid___follow_up"))
|
| 50 |
+
retype("bid___follow_up", c("bidfudate"), "DATE")
|
| 51 |
+
|
| 52 |
+
if (load_csv("follow_up_scores")) {
|
| 53 |
+
retype("follow_up_scores", c("follow_up_date"), "DATE")
|
| 54 |
+
retype("follow_up_scores", c("rule_score","award_probability"), "DOUBLE")
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
if (load_csv("pm___project_file")) {
|
| 58 |
+
retype("pm___project_file", c("projectdatecreated","substantialcompletiondate","finalcompletiondate"), "DATE")
|
| 59 |
+
retype("pm___project_file", c("billingcompletepercent"), "DOUBLE")
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
if (load_csv("project_file")) {
|
| 63 |
+
retype("project_file", c("contractdate"), "DATE")
|
| 64 |
+
retype("project_file", c("contractamt"), "DOUBLE")
|
| 65 |
+
}
|
| 66 |
+
})
|