Skip to content

Commit

Permalink
docs: remove coverage, fix typos, and update solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilbottom authored Jun 7, 2024
1 parent 5d1a152 commit bd1d8a4
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/generate-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- run: pipx install poetry
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with: { python-version: 3.11, cache: poetry }
- run: poetry install --with docs
- run: poetry run mkdocs gh-deploy --force
20 changes: 1 addition & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
ci:
autoupdate_schedule: quarterly
skip: ["poetry-lock", "sourcery", "pylint", "pytest", "coverage-badge"]
skip: ["poetry-lock", "sourcery", "pylint"]

repos:
- repo: meta
Expand Down Expand Up @@ -93,21 +93,3 @@ repos:
types: ["python"]
args: ["-rn", "--rcfile=pyproject.toml"]
exclude: "^.*$" # Exclude everything for now

# Testing and coverage
- repo: local
hooks:
- id: pytest
name: Run unit tests
entry: pytest tests
language: system
pass_filenames: false
always_run: true
exclude: "^.*$" # Exclude everything for now
- id: coverage-badge
name: Generate coverage badge
entry: coverage-badge -o coverage.svg -f
language: system
pass_filenames: false
always_run: true
exclude: "^.*$" # Exclude everything for now
21 changes: 0 additions & 21 deletions coverage.svg

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ The solution can be found at:
<!-- prettier-ignore -->
>? TIP: **Hint 2**
>
> Use the difference between two `ROW_NUMBER()` functions to create a group for each user and event type. Partition on `user_id` for one and partitioning on both `user_id` and `event_id` for the other, ordering both by `event_id`.
> Use the difference between two `ROW_NUMBER()` functions to create a group for each user and event type. Partition on `user_id` for one and partition on both `user_id` and `event_type` for the other, ordering both by `event_id`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
```sql
with temperatures as (
select
site_id,
reading_datetime,
temperature,
sum(temperature) over (
partition by site_id
order by reading_datetime rows between 2 preceding and 2 following
) as sum_temps
from readings
qualify 5 = count(*) over (
partition by site_id
order by reading_datetime rows between 2 preceding and 2 following
)
)
select
* exclude (sum_temps),
round((sum_temps - temperature) / 4, 4) as average_temperature,
round(100 * (temperature - average_temperature) / temperature, 4) as percentage_increase
from temperatures
where percentage_increase > 10
order by
site_id,
reading_datetime
```
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
```sql
with temps as (
with temperatures as (
select
site_id,
reading_datetime,
temperature,
(
avg(temperature) over rows_before_site_reading
+ avg(temperature) over rows_after_site_reading
) / 2 as average_temperature,
(
count(temperature) over rows_before_site_reading
+ count(temperature) over rows_after_site_reading
) as count_of_rows
(sum(temperature) over rows_around_site_reading - temperature) / 4 as average_temperature,
count(*) over rows_around_site_reading as count_of_rows
from readings
window
rows_before_site_reading as (
partition by site_id
order by reading_datetime
rows between 2 preceding and 1 preceding
),
rows_after_site_reading as (
partition by site_id
order by reading_datetime
rows between 1 following and 2 following
)
window rows_around_site_reading as (
partition by site_id
order by reading_datetime rows between 2 preceding and 2 following
)
)
select
site_id,
reading_datetime,
temperature,
round(average_temperature, 4) as average_temperature,
round(100.0 * (temperature - average_temperature) / average_temperature, 4) as percentage_increase
from temps
round(100.0 * (temperature - average_temperature) / temperature, 4) as percentage_increase
from temperatures
where 1=1
and count_of_rows = 4
and (temperature - average_temperature) / average_temperature > 0.1
and count_of_rows = 5
and (temperature - average_temperature) / temperature > 0.1
order by
site_id,
reading_datetime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Some SQL solutions per database are provided below.
>
--8<-- "docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--duckdb.sql"

<!-- prettier-ignore -->
> SUCCESS: **Snowflake**
>
--8<-- "docs/challenging-sql-problems/solutions/bronze/temperature-anomaly-detection--snowflake.sql"

<!-- prettier-ignore -->
> SUCCESS: **SQL Server**
>
Expand Down

0 comments on commit bd1d8a4

Please sign in to comment.