Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from eccentricOrange:20-incorporate-crse-and-r…
Browse files Browse the repository at this point in the history
…eddit-feedback

20-incorporate-crse-and-reddit-feedback
  • Loading branch information
eccentricOrange authored May 9, 2022
2 parents 6020a4f + 5fc3277 commit 54b81c6
Show file tree
Hide file tree
Showing 14 changed files with 2,003 additions and 1,206 deletions.
75 changes: 0 additions & 75 deletions .github/workflows/build.yml

This file was deleted.

162 changes: 162 additions & 0 deletions .github/workflows/test-build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: Test, build and release

on: [push]

jobs:

# test with pytest
test:
name: pytest
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

# build SQLite from source, because I need 3.35<=
- run: |
wget https://sqlite.org/2022/sqlite-autoconf-3380500.tar.gz
tar -xvf sqlite-autoconf-3380500.tar.gz
- run: |
./configure
make
sudo make install
export PATH="/usr/local/lib:$PATH"
working-directory: sqlite-autoconf-3380500
# run pytest
- uses: actions/setup-python@v2
with:
python-version: '3.10'
- run: pip install -r requirements.txt pytest
- run: pytest
env:
LD_LIBRARY_PATH: /usr/local/lib

# build executable for linux
build-linux:
name: build for linux
runs-on: ubuntu-latest
needs: test

steps:

# setup
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: |
pip install pyinstaller
mkdir bin
mkdir build
# build
- run: |
pyinstaller --distpath bin --clean --onefile --name npbc_updater-linux-x64 npbc_updater.py
pip install -r requirements.txt
pyinstaller --distpath bin --clean --add-data "data/schema.sql:." --onefile --name npbc_cli-linux-x64 npbc_cli.py
# upload artifacts
- uses: actions/upload-artifact@v2
with:
path: bin
name: npbc_cli-linux-x64
- uses: actions/upload-artifact@v2
with:
path: bin
name: npbc_updater-linux-x64

# build executable for windows
build-windows:
name: build for windows
runs-on: windows-latest
needs: test

steps:

# setup
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: |
pip install pyinstaller
mkdir bin
mkdir build
# build
- run: |
pyinstaller --distpath bin --clean --onefile --name npbc_updater-windows-x64 npbc_updater.py
pip install -r requirements.txt
pyinstaller --distpath bin --clean --add-data "data/schema.sql;." --onefile --name npbc_cli-windows-x64 npbc_cli.py
# upload artifacts
- uses: actions/upload-artifact@v2
with:
path: bin
name: npbc_cli-windows-x64
- uses: actions/upload-artifact@v2
with:
path: bin
name: npbc_updater-windows-x64

# build executable for macos
build-macos:
name: build for macos
runs-on: macos-latest
needs: test

steps:

# setup
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- run: |
pip install pyinstaller
mkdir bin
mkdir build
# build
- run: |
pyinstaller --distpath bin --clean --onefile --name npbc_updater-macos-x64 npbc_updater.py
pip install -r requirements.txt
pyinstaller --distpath bin --clean --add-data "data/schema.sql:." --onefile --name npbc_cli-macos-x64 npbc_cli.py
# upload artifacts
- uses: actions/upload-artifact@v2
with:
path: bin
name: npbc_cli-macos-x64
- uses: actions/upload-artifact@v2
with:
path: bin
name: npbc_updater-macos-x64

# create release from tag
release:

# ensure that build is complete for all platforms
needs:
- build-linux
- build-macos
- build-windows

# run only if we're on a tag beginning with 'v' ('v1.2.5', for example)
if: startsWith(github.ref, 'refs/tags/v')

runs-on: ubuntu-latest
permissions:
contents: write

steps:

# download the artifacts
- run: mkdir bin
- uses: actions/download-artifact@v2
with:
path: bin

# do the release
- uses: ncipollo/release-action@v1
with:
artifacts: "bin/npbc*/*"
token: ${{ secrets.GITHUB_TOKEN }}
generateReleaseNotes: true
artifactErrorsFailBuild: true
prerelease: false
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ __pycache__
*build
*dist
.vs
exp
exp*
*legacy*
npbc.db
pyenv-install
bin
.vscode
.vscode
.pytest_cache
data/*
!data/test.sql
!data/schema.sql
.env
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This app calculates your monthly newspaper bill.
2. Each newspaper may or may not be delivered on a given day
3. Each newspaper has a name, and a number called a key
4. You may register any dates when you didn't receive a paper in advance using the `addudl` command
5. Once you calculate, the results are displayed and copied to your clipboard
5. Once you calculate, the results are displayed and logged.

## Installation
1. From [the latest release](https://github.com/eccentricOrange/npbc/releases/latest), download the "updater" file for your operating system in any folder, and make it executable.
Expand Down
65 changes: 40 additions & 25 deletions data/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,51 @@ CREATE TABLE IF NOT EXISTS papers (
name TEXT NOT NULL,
CONSTRAINT unique_paper_name UNIQUE (name)
);
CREATE TABLE IF NOT EXISTS papers_days_delivered (
paper_id INTEGER NOT NULL,

CREATE TABLE IF NOT EXISTS papers_days (
paper_day_id INTEGER PRIMARY KEY AUTOINCREMENT,
paper_id INTEGER NOT NULL REFERENCES papers(paper_id),
day_id INTEGER NOT NULL,
delivered INTEGER NOT NULL,
FOREIGN KEY(paper_id) REFERENCES papers(paper_id),
CONSTRAINT unique_paper_day UNIQUE (paper_id, day_id)
);
CREATE TABLE IF NOT EXISTS papers_days_cost(
paper_id INTEGER NOT NULL,
day_id INTEGER NOT NULL,
cost INTEGER,
FOREIGN KEY(paper_id) REFERENCES papers(paper_id),
CONSTRAINT unique_paper_day UNIQUE (paper_id, day_id)

CREATE TABLE IF NOT EXISTS papers_days_delivered (
papers_days_delivered_id INTEGER PRIMARY KEY AUTOINCREMENT,
paper_day_id INTEGER NOT NULL REFERENCES papers_days(paper_day_id),
delivered INTEGER NOT NULL CHECK (delivered IN (0, 1))
);

CREATE TABLE IF NOT EXISTS papers_days_cost (
papers_days_cost_id INTEGER PRIMARY KEY AUTOINCREMENT,
paper_day_id INTEGER NOT NULL REFERENCES papers_days(paper_day_id),
cost REAL
);

CREATE TABLE IF NOT EXISTS undelivered_strings (
entry_id INTEGER PRIMARY KEY AUTOINCREMENT,
year INTEGER NOT NULL,
month INTEGER NOT NULL,
paper_id INTEGER NOT NULL,
string TEXT NOT NULL,
FOREIGN KEY (paper_id) REFERENCES papers(paper_id)
string_id INTEGER PRIMARY KEY AUTOINCREMENT,
year INTEGER NOT NULL CHECK (year >= 0),
month INTEGER NOT NULL CHECK (month >= 0 AND month <= 12),
paper_id INTEGER NOT NULL REFERENCES papers(paper_id),
string TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS undelivered_dates (
entry_id INTEGER PRIMARY KEY AUTOINCREMENT,

CREATE TABLE IF NOT EXISTS logs (
log_id INTEGER PRIMARY KEY AUTOINCREMENT,
paper_id INTEGER NOT NULL REFERENCES papers(paper_id),
timestamp TEXT NOT NULL,
year INTEGER NOT NULL,
month INTEGER NOT NULL,
paper_id INTEGER NOT NULL,
dates TEXT NOT NULL,
FOREIGN KEY (paper_id) REFERENCES papers(paper_id)
month INTEGER NOT NULL CHECK (month >= 0 AND month <= 12),
year INTEGER NOT NULL CHECK (year >= 0),
CONSTRAINT unique_log UNIQUE (timestamp, paper_id, month, year)
);

CREATE TABLE IF NOT EXISTS undelivered_dates_logs (
undelivered_dates_log_id INTEGER PRIMARY KEY AUTOINCREMENT,
log_id INTEGER NOT NULL REFERENCES logs(log_id),
date_not_delivered TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS search_strings ON undelivered_strings(year, month);
CREATE INDEX IF NOT EXISTS paper_names ON papers(name);

CREATE TABLE IF NOT EXISTS cost_logs (
cost_log_id INTEGER PRIMARY KEY AUTOINCREMENT,
log_id INTEGER NOT NULL REFERENCES logs(log_id),
cost REAL NOT NULL
);
31 changes: 31 additions & 0 deletions data/test.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
INSERT INTO papers (name)
VALUES
('paper1'),
('paper2'),
('paper3');

INSERT INTO papers_days (paper_id, day_id)
VALUES
(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6),
(2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6),
(3, 0), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6);

INSERT INTO papers_days_delivered (paper_day_id, delivered)
VALUES
(01, 0), (02, 1), (03, 0), (04, 0), (05, 0), (06, 1), (07, 1),
(08, 0), (09, 0), (10, 0), (11, 0), (12, 1), (13, 0), (14, 1),
(15, 1), (16, 1), (17, 0), (18, 0), (19, 1), (20, 1), (21, 1);

INSERT INTO papers_days_cost (paper_day_id, cost)
VALUES
(01, 0.0), (02, 6.4), (03, 0.0), (04, 0.0), (05, 0.0), (06, 7.9), (07, 4.0),
(08, 0.0), (09, 0.0), (10, 0.0), (11, 0.0), (12, 3.4), (13, 0.0), (14, 8.4),
(15, 2.4), (16, 4.6), (17, 0.0), (18, 0.0), (19, 3.4), (20, 4.6), (21, 6.0);

INSERT INTO undelivered_strings (year, month, paper_id, string)
VALUES
(2020, 11, 1, '5'),
(2020, 11, 1, '6-12'),
(2020, 11, 2, 'sundays'),
(2020, 11, 3, '2-tuesday'),
(2020, 10, 3, 'all');
Loading

0 comments on commit 54b81c6

Please sign in to comment.