Pin the dependencies ...

... after upgrading:
- alembic
- matplotlib
- pandas
- rpy2
- sqlalchemy
- statsmodels
- dev dependencies
  + coverage     + factory-boy    + faker                 + nox
  + packaging    + pre-commit     + flake8-annotations    + pytest
  + pytest-cov   + sphinx
- research dependencies
  + numpy        + pyty
- transient dependencies
  + astpretty    + atomicwrites   + bleach                + chardet
  + colorlog     + darglint       + flake8-comprehensions + gitpython
  + identify     + ipykernel      + ipython               + jedi
  + jinja2       + jupyter-client + jupyter-core          + mako
  + nbformat     + nest-asyncio   + notebook              + parso
  + pluggy       + prompt-toolkit + ptyprocess            + pygments
  + pyyaml       + pyzmq          + requests              + smmap
  + terminado    + textfixtures   + snowballstemmer       + typed-ast
  + urllib3      + virtualenv

- fix SQL statements written in raw text
This commit is contained in:
Alexander Hess 2021-02-04 12:21:41 +01:00
parent 50b35a8284
commit 0da86e5f07
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
3 changed files with 504 additions and 481 deletions

866
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -218,14 +218,16 @@ class City(meta.Base):
all_zip_codes = sorted( all_zip_codes = sorted(
row[0] row[0]
for row in db.session.execute( for row in db.session.execute(
f""" -- # noqa:S608 sa.text(
SELECT DISTINCT f""" -- # noqa:S608
zip_code SELECT DISTINCT
FROM zip_code
{config.CLEAN_SCHEMA}.addresses FROM
WHERE {config.CLEAN_SCHEMA}.addresses
city_id = {self.id}; WHERE
""", city_id = {self.id};
""",
),
) )
) )
cmap = utils.make_random_cmap(len(all_zip_codes), bright=False) cmap = utils.make_random_cmap(len(all_zip_codes), bright=False)

View file

@ -6,6 +6,7 @@ import datetime as dt
from typing import Tuple from typing import Tuple
import pandas as pd import pandas as pd
import sqlalchemy as sa
from urban_meal_delivery import config from urban_meal_delivery import config
from urban_meal_delivery import db from urban_meal_delivery import db
@ -68,64 +69,68 @@ class OrderHistory:
# `data` is probably missing "pixel_id"-"start_at" pairs. # `data` is probably missing "pixel_id"-"start_at" pairs.
# This happens when there is no demand in the `Pixel` in the given `time_step`. # This happens when there is no demand in the `Pixel` in the given `time_step`.
data = pd.read_sql_query( data = pd.read_sql_query(
f"""-- # noqa:E501,WPS221 sa.text(
SELECT f""" -- # noqa:WPS221
pixel_id,
start_at,
COUNT(*) AS n_orders
FROM (
SELECT SELECT
pixel_id, pixel_id,
placed_at_without_seconds - minutes_to_be_cut AS start_at start_at,
COUNT(*) AS n_orders
FROM ( FROM (
SELECT SELECT
pixels.pixel_id, pixel_id,
DATE_TRUNC('MINUTE', orders.placed_at) AS placed_at_without_seconds, placed_at_without_seconds - minutes_to_be_cut AS start_at
((
EXTRACT(MINUTES FROM orders.placed_at)::INTEGER % {self._time_step}
)::TEXT || ' MINUTES')::INTERVAL
AS minutes_to_be_cut
FROM ( FROM (
SELECT SELECT
id, pixels.pixel_id,
placed_at, DATE_TRUNC('MINUTE', orders.placed_at)
pickup_address_id AS placed_at_without_seconds,
FROM ((
{config.CLEAN_SCHEMA}.orders EXTRACT(MINUTES FROM orders.placed_at)::INTEGER
% {self._time_step}
)::TEXT || ' MINUTES')::INTERVAL
AS minutes_to_be_cut
FROM (
SELECT
id,
placed_at,
pickup_address_id
FROM
{config.CLEAN_SCHEMA}.orders
INNER JOIN (
SELECT
id AS address_id
FROM
{config.CLEAN_SCHEMA}.addresses
WHERE
city_id = {self._grid.city.id}
) AS in_city
ON orders.pickup_address_id = in_city.address_id
WHERE
ad_hoc IS TRUE
) AS
orders
INNER JOIN ( INNER JOIN (
SELECT SELECT
id AS address_id address_id,
pixel_id
FROM FROM
{config.CLEAN_SCHEMA}.addresses {config.CLEAN_SCHEMA}.addresses_pixels
WHERE WHERE
city_id = {self._grid.city.id} grid_id = {self._grid.id}
) AS in_city AND
ON orders.pickup_address_id = in_city.address_id city_id = {self._grid.city.id} -- -> sanity check
WHERE ) AS pixels
ad_hoc IS TRUE ON orders.pickup_address_id = pixels.address_id
) AS ) AS placed_at_aggregated_into_start_at
orders ) AS pixel_start_at_combinations
INNER JOIN ( GROUP BY
SELECT pixel_id,
address_id, start_at
pixel_id ORDER BY
FROM pixel_id,
{config.CLEAN_SCHEMA}.addresses_pixels start_at;
WHERE """,
grid_id = {self._grid.id} ), # noqa:WPS355
AND
city_id = {self._grid.city.id} -- redundant -> sanity check
) AS pixels
ON orders.pickup_address_id = pixels.address_id
) AS placed_at_aggregated_into_start_at
) AS pixel_start_at_combinations
GROUP BY
pixel_id,
start_at
ORDER BY
pixel_id,
start_at;
""",
con=db.connection, con=db.connection,
index_col=['pixel_id', 'start_at'], index_col=['pixel_id', 'start_at'],
) )