Compare commits
3 Commits
6462e742d9
...
a859ffa91a
Author | SHA1 | Date | |
---|---|---|---|
a859ffa91a | |||
53523eb330 | |||
d1371bcdce |
20
readme.md
20
readme.md
@ -1,16 +1,14 @@
|
|||||||
## worked on so far
|
* setup postgres db with a username and password and database
|
||||||
|
* add this to .bashrc to quickly invoke command line connection `export PGD="psql -U ptrowbridge -d ubm -p 5433 -h 192.168.1.110"`
|
||||||
setup
|
setup
|
||||||
----------------------------------------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
the basic assumption is a single sales table is available to work with that has a lot of related data that came from master data tables originally.
|
* setup the application tables `$PGD -f setup_sql/schema.sql`
|
||||||
the goal then is to break that back apart to whatever degree is necessary.
|
* create a table of data to forecast
|
||||||
|
* edit `target_info.sql` to reflect the name of the table from previous step
|
||||||
* _**run**_ `schema.sql` and `perd.sql` to setup basic tables
|
* `$PGD -f setup_sql/target_info.sql` to populate the meta table
|
||||||
* create a table fc.live as copied from target (will need to have columns `version` and `iter` added if not existing)
|
* fill out the `target_meta` table in the database to model the forecast table
|
||||||
* _**run**_ `target_info.sql` to populate the `fc.target_meta` table that holds all the columns and their roles
|
* `PGD -f setup_sql/build_maste_tables.sql` to create master data tables from forecast data
|
||||||
* fill in flags on table `fc.target_meta` to show how the data is related
|
* `./routes/baseline/generate_route_sql.sh` to create the baseline sql used by the /baseline route
|
||||||
* _**run**_ `build_master_tables.sql` to generate foreign key based master data
|
|
||||||
|
|
||||||
|
|
||||||
routes
|
routes
|
||||||
----------------------------------------------------------------------------------------------------------------------------------------------------
|
----------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -49,8 +49,6 @@ WHERE
|
|||||||
dtype = 'date'
|
dtype = 'date'
|
||||||
AND fkey IS NOT NULL;
|
AND fkey IS NOT NULL;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS fc.sql(cmd text PRIMARY KEY, t text );
|
|
||||||
|
|
||||||
-------------------------------build a column list-----------------------------------------
|
-------------------------------build a column list-----------------------------------------
|
||||||
SELECT
|
SELECT
|
||||||
string_agg('o.'||format('%I',cname),E'\n ,' ORDER BY opos ASC)
|
string_agg('o.'||format('%I',cname),E'\n ,' ORDER BY opos ASC)
|
||||||
@ -107,11 +105,11 @@ FROM
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
$$||_order_date||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date
|
$$||format('%I',_order_date)||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date
|
||||||
--...or any open orders currently booked before cutoff....
|
--...or any open orders currently booked before cutoff....
|
||||||
OR ($$||_order_status||$$ IN (app_openstatus_code) and $$||_order_date||$$ <= 'app_openorder_cutoff'::date)
|
OR ($$||format('%I',_order_status)||$$ IN ('app_openstatus_code') and $$||format('%I',_order_date)||$$ <= 'app_openorder_cutoff'::date)
|
||||||
--...or anything that shipped in that period
|
--...or anything that shipped in that period
|
||||||
OR ($$||_ship_date||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date)
|
OR ($$||format('%I',_ship_date)||$$ BETWEEN 'app_baseline_from_date'::date AND 'app_baseline_to_date'::date)
|
||||||
)
|
)
|
||||||
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
$$::text
|
$$::text
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
--assumes schema fc already exists
|
CREATE SCHEMA IF NOT EXISTS fc;
|
||||||
|
|
||||||
--DROP TABLE IF EXISTS fc.target_meta;
|
--DROP TABLE IF EXISTS fc.target_meta;
|
||||||
CREATE TABLE IF NOT EXISTS fc.target_meta (
|
CREATE TABLE IF NOT EXISTS fc.target_meta (
|
||||||
@ -15,7 +15,7 @@ CREATE TABLE IF NOT EXISTS fc.target_meta (
|
|||||||
);
|
);
|
||||||
|
|
||||||
--ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk;
|
--ALTER TABLE fc.target_meta DROP CONSTRAINT IF EXISTS target_meta_pk;
|
||||||
ALTER TABLE fc.target_meta ADD CONSTRAINT IF NOT EXISTS target_meta_pk PRIMARY KEY (tname, cname);
|
ALTER TABLE fc.target_meta ADD CONSTRAINT target_meta_pk PRIMARY KEY (tname, cname);
|
||||||
|
|
||||||
COMMENT ON TABLE fc.target_meta IS 'target table layout info';
|
COMMENT ON TABLE fc.target_meta IS 'target table layout info';
|
||||||
COMMENT ON COLUMN fc.target_meta.tname IS 'schema.table_name of target sales data table';
|
COMMENT ON COLUMN fc.target_meta.tname IS 'schema.table_name of target sales data table';
|
||||||
@ -35,3 +35,5 @@ CREATE TABLE IF NOT EXISTS fc.log (
|
|||||||
);
|
);
|
||||||
|
|
||||||
COMMENT ON TABLE fc.log IS 'forecast change log';
|
COMMENT ON TABLE fc.log IS 'forecast change log';
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS fc.sql(cmd text PRIMARY KEY, t text );
|
||||||
|
Loading…
Reference in New Issue
Block a user