-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from davewalker5/location-report
Location report
- Loading branch information
Showing
82 changed files
with
59,136 additions
and
2,167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
FROM python:3.10-slim-bullseye AS runtime | ||
|
||
COPY naturerecorderpy-1.0.16.0 /opt/naturerecorderpy-1.0.16.0 | ||
COPY naturerecorderpy-1.0.17.0 /opt/naturerecorderpy-1.0.17.0 | ||
|
||
WORKDIR /opt/naturerecorderpy-1.0.16.0 | ||
WORKDIR /opt/naturerecorderpy-1.0.17.0 | ||
|
||
RUN apt-get update -y | ||
RUN pip install -r requirements.txt | ||
RUN pip install nature_recorder-1.0.16-py3-none-any.whl | ||
RUN pip install nature_recorder-1.0.17-py3-none-any.whl | ||
|
||
ENV NATURE_RECORDER_DATA_FOLDER=/var/opt/naturerecorderpy-1.0.16.0 | ||
ENV NATURE_RECORDER_DB=/var/opt/naturerecorderpy-1.0.16.0/naturerecorder.db | ||
ENV NATURE_RECORDER_DATA_FOLDER=/var/opt/naturerecorderpy-1.0.17.0 | ||
ENV NATURE_RECORDER_DB=/var/opt/naturerecorderpy-1.0.17.0/naturerecorder.db | ||
|
||
ENTRYPOINT [ "python" ] | ||
CMD [ "-m", "naturerec_web" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ The logic Package | |
status_schemes | ||
status_ratings | ||
species_status_ratings | ||
reports | ||
job_statuses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
reports.py | ||
========== | ||
|
||
.. automodule:: naturerec_model.logic.reports | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
reports_blueprint.py | ||
==================== | ||
|
||
.. automodule:: naturerec_web.reports.reports_blueprint | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
request_utils.py | ||
================ | ||
|
||
.. automodule:: naturerec_web.request_utils | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Feature: Reporting | ||
Scenario: Report on numbers of individuals by location | ||
Given A set of sightings | ||
| Date | Location | Category | Species | Number | Gender | WithYoung | | ||
| TODAY | Test Location | Birds | Woodpigeon | 1 | Unknown | No | | ||
| TODAY | Test Location | Birds | Blackbird | 1 | Male | No | | ||
| TODAY | Test Location | Birds | Robin | 1 | Unknown | No | | ||
| TODAY | Test Location | Mammals | Grey Squirrel | 1 | Unknown | No | | ||
|
||
When I navigate to the individuals by location report page | ||
And I fill in the individuals by location report details | ||
| Location | Category | From | | ||
| Test Location | Birds | TODAY | | ||
|
||
And I click on the "Generate Report" button | ||
Then There will be 3 results in the report table | ||
|
||
Scenario: Report on numbers of individuals by location | ||
Given A set of sightings | ||
| Date | Location | Category | Species | Number | Gender | WithYoung | | ||
| TODAY | Test Location | Birds | Woodpigeon | 1 | Unknown | No | | ||
| TODAY | Test Location | Mammals | Grey Squirrel | 1 | Unknown | No | | ||
|
||
When I navigate to the sightings by location report page | ||
And I fill in the sightings by location report details | ||
| Location | Category | From | | ||
| Test Location | Birds | TODAY | | ||
|
||
And I click on the "Generate Report" button | ||
Then There will be 1 result in the report table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from behave import when, then | ||
from selenium.webdriver.common.by import By | ||
|
||
from features.steps.helpers import select_option, get_date_from_string, confirm_table_row_count | ||
from naturerec_model.model import Sighting | ||
|
||
|
||
@when("I navigate to the individuals by location report page") | ||
def _(context): | ||
url = context.flask_runner.make_url("reports/location/individuals") | ||
context.browser.get(url) | ||
assert "Individuals by Species & Location" in context.browser.title | ||
|
||
|
||
@when("I navigate to the sightings by location report page") | ||
def _(context): | ||
url = context.flask_runner.make_url("reports/location/sightings") | ||
context.browser.get(url) | ||
assert "Sightings by Species & Location" in context.browser.title | ||
|
||
|
||
@when("I fill in the individuals by location report details") | ||
@when("I fill in the sightings by location report details") | ||
def _(context): | ||
row = context.table.rows[0] | ||
select_option(context, "location", row["Location"], None) | ||
select_option(context, "category", row["Category"], None) | ||
from_date = get_date_from_string(row["From"]).strftime(Sighting.DATE_DISPLAY_FORMAT) | ||
context.browser.find_element(By.NAME, "from_date").send_keys(from_date) | ||
|
||
|
||
@then("There will be {number} results in the report table") | ||
@then("There will be {number} result in the report table") | ||
def _(context, number): | ||
confirm_table_row_count(context, number, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
This module contains the business logic for the pre-defined reports | ||
""" | ||
|
||
import datetime | ||
import pandas as pd | ||
from ..model import Engine, Sighting | ||
|
||
|
||
def location_individuals_report(from_date, location_id, category_id, to_date=None): | ||
""" | ||
Report on the total number of individuals seen, filtering by location, category and date range | ||
:param from_date: Start date for reporting | ||
:param location_id: Location id | ||
:param category_id: Category id | ||
:param to_date: End-date for reporting or None for today | ||
:return: A Pandas Dataframe containing the results | ||
""" | ||
# If the "to" date isn't set, make it today | ||
if not to_date: | ||
to_date = datetime.datetime.today() | ||
|
||
# Format the dates in the format required in a SQL query | ||
from_date_string = from_date.strftime(Sighting.DATE_FORMAT) | ||
to_date_string = to_date.strftime(Sighting.DATE_FORMAT) | ||
|
||
# Construct the query | ||
sql_query = f"SELECT sp.Name AS 'Species', SUM( IFNULL( s.Number, 1 ) ) AS 'Count' " \ | ||
f"FROM SIGHTINGS s " \ | ||
f"INNER JOIN LOCATIONS l ON l.Id = s.LocationId " \ | ||
f"INNER JOIN SPECIES sp ON sp.Id = s.SpeciesId " \ | ||
f"INNER JOIN CATEGORIES c ON c.Id = sp.CategoryId " \ | ||
f"WHERE Date BETWEEN '{from_date_string}' AND '{to_date_string}' " \ | ||
f"AND l.Id = {location_id} " \ | ||
f"AND c.Id = {category_id} " \ | ||
f"GROUP BY sp.Name" | ||
|
||
return pd.read_sql(sql_query, Engine).set_index("Species") | ||
|
||
|
||
def location_days_report(from_date, location_id, category_id, to_date=None): | ||
""" | ||
Report on the number of days on which a given species was seen, filtering by location, category and date range | ||
:param from_date: Start date for reporting | ||
:param location_id: Location id | ||
:param category_id: Category id | ||
:param to_date: End-date for reporting or None for today | ||
:return: A Pandas Dataframe containing the results | ||
""" | ||
# If the "to" date isn't set, make it today | ||
if not to_date: | ||
to_date = datetime.datetime.today() | ||
|
||
# Format the dates in the format required in a SQL query | ||
from_date_string = from_date.strftime(Sighting.DATE_FORMAT) | ||
to_date_string = to_date.strftime(Sighting.DATE_FORMAT) | ||
|
||
# Construct the query | ||
sql_query = f"SELECT sp.Name AS 'Species', COUNT( s.Id ) AS 'Count' " \ | ||
f"FROM SIGHTINGS s " \ | ||
f"INNER JOIN LOCATIONS l ON l.Id = s.LocationId " \ | ||
f"INNER JOIN SPECIES sp ON sp.Id = s.SpeciesId " \ | ||
f"INNER JOIN CATEGORIES c ON c.Id = sp.CategoryId " \ | ||
f"WHERE Date BETWEEN '{from_date_string}' AND '{to_date_string}' " \ | ||
f"AND l.Id = {location_id} " \ | ||
f"AND c.Id = {category_id} " \ | ||
f"GROUP BY sp.Name" | ||
|
||
return pd.read_sql(sql_query, Engine).set_index("Species") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.