Commit Graph

2708 Commits

Author SHA1 Message Date
Katie Smith
71796311fa Delete unused aggregate_statistics endpoint
`@service_blueprint.route('/<uuid:service_id>/fragment/aggregate_statistics')`
is not being used anywhere, so has been removed. The `provider_statistics_dao`
can also be removed, since the function this contained was only used for
the endpoint.
2018-05-21 15:03:39 +01:00
Rebecca Law
4d8255b8d9 Merge branch 'master' into fix-ft-billing-migration 2018-05-21 11:06:31 +01:00
Rebecca Law
9fad623d91 Update the ft_billing query to only include billable notification status types.
Update test_provider_statistics dao - this is really irrelevant since the endpoint using the query is not being used. We have a PR coming to delete the unused code.
Update rate_multiplier to always be an integer
2018-05-21 10:56:16 +01:00
Rebecca Law
eb083e30ed - Only rebuild current month for monthly_billing if today is in the current year.
- Change the usage queries to a union so that billing_units is correct for all notification types. Removing the business logic from the schema.
- Added tests for different fragment counts, rates and sheet counts.
2018-05-16 12:21:59 +01:00
Rebecca Law
40d8f78b2b Convert the day_start from a string to a datetime. 2018-05-15 14:00:06 +01:00
Rebecca Law
271ce6d76e Changed the update/insert to a postgres upsert to avoid concurrency issues. 2018-05-15 11:21:10 +01:00
Rebecca Law
3615f3d00f In order to re-run the create_nightly_billing for dates in the past, we added a condition on which table is used.
This will allow us to re-run nightly billing for those 2 days where it failed.
For the majority of time the query will run on Notiifcations.
2018-05-14 16:21:16 +01:00
Rebecca Law
a640605a7c Merge pull request #1867 from alphagov/use-ft-billing-for-usage
Update ft_billing table to use integer data types
2018-05-14 13:04:52 +01:00
Rebecca Law
828ebb6079 Fix test 2018-05-14 12:48:42 +01:00
Chris Waszczuk
0e9fca09fb Merge pull request #1855 from alphagov/inbound-sms-max-7-days
Only get inbound messages that are a maximum of 7 days old
2018-05-14 11:15:52 +01:00
Rebecca Law
2ae4cf18e8 Merge branch 'use-ft-billing-for-usage' of github.com:alphagov/notifications-api 2018-05-14 09:16:40 +01:00
Rebecca Law
d98581cfe6 Added a new endpoint for yearly usage totals using ft_billing. 2018-05-11 16:25:16 +01:00
Rebecca Law
8028f6cc28 We found that the reporting task failed twice because of integrity constraints.
This was because the rate_multiplier was being added as 1 and 1.0 which was not resolving to the same.
This updates the table to use Integrer.
Also changed the logging for the task.
2018-05-10 15:35:58 +01:00
chrisw
2abbb590ab Only get inbound messages that are a maximum of 7 days old 2018-05-10 14:00:55 +01:00
Leo Hemsted
95475d130b Merge pull request #1865 from alphagov/separate-stats-endpoint
create new stats endpoint
2018-05-09 14:28:46 +01:00
Leo Hemsted
c30f13ea67 create new stats endpoint
the admin app currently calls get_detailed_service, which gets
notification stats, adds them on to the rest of the detailed service
endpoint, and returns them. However, the admin app then only looks at
the stats - it doesn't look at the rest of the service object.

This is called in a few high profile places - the dashboard, the
notification summary page, and when you send a job. By creating a
separate endpoint that ignores the rest of the service object (and no
marshmallow too!), the hope is that we'll improve some slowness we've
been seeing.

Note: The old detailed function will still need to stay - it's used
by get_services(detailed=True) for the platform admin page.
2018-05-09 12:02:56 +01:00
Rebecca Law
d52e65d89a Merge pull request #1863 from alphagov/use-ft-billing-for-usage
Use ft billing for usage
2018-05-08 17:00:56 +01:00
Rebecca Law
3e3b885bdc Realised that it's best to cast the Month as date. 2018-05-08 13:53:44 +01:00
Rebecca Law
dd113a8e86 Update the tests so that they ignore timezone in the month returned by query.
The timezone added is that of the database - locally a db will get timezone=GB, but the servers are using UTC (which is right)
This date is trucated to month, and is BST, here time and timezone is irrelevant.
2018-05-08 13:44:06 +01:00
Rebecca Law
fd6e5f39cf Changes as per requested from code review
Move the serialize method to the billing_schema
Update variable names
Improve tests
Fix bug in command
2018-05-08 12:09:29 +01:00
Rebecca Law
ea3523199a New endpoint to get monthly billing usage from the ft_billing table.
New command to compare the results of monthly billing to ft_billing.
2018-05-04 13:09:14 +01:00
Chris Hill-Scott
54d0e64582 Merge pull request #1853 from alphagov/pass-letter-date-to-template-preview
Pass date of letter to template preview
2018-05-04 10:52:47 +01:00
Rebecca Law
18c2b9a56d Use better date function to get the first of each month.
Build the json object to return for the new endpoint.
2018-05-02 09:36:13 +01:00
Rebecca Law
0fb9c1d318 Add notification_type to query 2018-05-02 09:36:13 +01:00
Rebecca Law
a9c5ba7674 Remove the truncate date function for the query. 2018-05-01 16:48:34 +01:00
Rebecca Law
93c7ab6251 Because dates are confusing we need to fix this query once more.
The template statistics are returning 7 days inclusive, however the big numbers on the dashboard are for 8 days.
This PR fixes that.
2018-05-01 10:47:47 +01:00
Chris Hill-Scott
8ae800b117 Pass date of letter to template preview
Otherwise all letters will show the current date.

Also beefed up the tests around this part of the code a bit.
2018-04-30 15:47:49 +01:00
Katie Smith
f2d4bc795e Add DAO function and endpoint for archiving letter contact blocks
Added a new DAO function which archives letter contact blocks by
setting archived to True. This raises an ArchiveValidationError if
trying to archive the default letter block for a service or the default
letter contact block for a template.

Added a new endpoint for archiving letter contact blocks.
2018-04-30 15:25:17 +01:00
Katie Smith
472b86f3f4 Add DAO function and endpoint for archiving SMS senders
Added a new DAO function which archives SMS senders by setting
archived to True. This raises an ArchiveValidationError, if
trying to archive a default SMS sender or an inbound number.

Added a new endpoint for archiving SMS senders.
2018-04-30 15:25:17 +01:00
Katie Smith
5f43fe23a7 Add DAO function and endpoint for archiving email reply_to addresses
Added a new DAO function which archives email reply_to addresses by
setting archived to True. This raises a new type of error, an
ArchiveValidationError, if trying to archive a default reply_to address.

Added a new endpoint for archiving email reply_to addresses.
2018-04-30 15:25:17 +01:00
Katie Smith
663021e494 Only return active SMS senders
Updated the DAO methods which return a single SMS sender and all SMS senders
to only return the non-archived senders. Changed the error raised in the Admin
interface from a SQLAlchemyError to a BadRequestError.
2018-04-30 15:25:17 +01:00
Katie Smith
f810daa3c5 Only return non-archived letter contact blocks
Changed DAO functions which return one letter contact block and all
letter contact blocks for a service to only return non-archived ones.
2018-04-30 15:25:17 +01:00
Katie Smith
a57b2f50c2 Only return non-archived email reply_to addresses
Updated the DAO methods which return a single email reply_to address and
all reply_to addresses to only return the non-archived addresses.

Changed the type of error that gets raised when using the Admin
interface to be BadRequestError instead of a SQLAlchemyError.
2018-04-30 15:25:17 +01:00
Katie Smith
be28f2e2de Add 'archived' column to the 3 reply_to models
Added a new boolean column, `archived`,  with a default of False to the
three models which are used to specify the 'reply to' address for
notifications:
 * ServiceEmailReplyTo
 * ServiceSmsSender
 * ServiceLetterContact
2018-04-30 15:25:17 +01:00
Leo Hemsted
238e85ea9e Merge pull request #1833 from alphagov/read-redis
Read template usage stats from new redis keys
2018-04-30 15:15:16 +01:00
Leo Hemsted
e35c1bde77 ensure tests have test_ prefix
also remove unused code branch

thanks, coverage!
2018-04-30 13:23:02 +01:00
Leo Hemsted
0efa223fb2 rename days_ago to midnight_n_days_ago
also add some more timezone boundary tests and minor code cleanup
2018-04-30 11:50:56 +01:00
Chris Hill-Scott
84024a9efc Refuse to process invalid files
Since the admin app won’t be checking the metadata when it starts a job
now it’s possible that someone could make a post request which attempts
to start a job for an invalid file. This commit adds a check to make
sure that can’t happen.

This is more of an extra safety thing, rather than something that the
admin app or a user will see.
2018-04-30 11:47:27 +01:00
Chris Hill-Scott
a4857c08ab Read job metadata from S3 metadata
All of our uploads now have the metadata about the job set on them in
S3. So this commit moves to using that metadata, if it’s there, instead
of the data in the body of the post request.

The aim of this is to stop the admin app having to post this data, which
means that it won’t have to keep this data in the session for the
while doing the file upload flow.
2018-04-30 11:47:13 +01:00
Chris Hill-Scott
79c6671500 Normalise whitespace and use client fixtures
Using the client fixture means that fewer nested indentation is needed.
Which, along with consistent indenting, makes the code easier to read.
2018-04-30 11:46:58 +01:00
Leo Hemsted
310b8eda4c refactor dao_get_template_usage now that limit_days no longer used
doesnt need to have any conditional stuff now - always requires a date
2018-04-30 11:13:21 +01:00
Leo Hemsted
7dc34fc3a4 set 0'd dict in redis if no data exists in redis
to get the data for a day can be reasonably slow (a few hundred
milliseconds), and if someone's viewing a service with no activity we
don't want to do that query seven times every two seconds. So if there
is no data in redis, when we get the data out of the database, we
should put it in redis so we can just grab it from there next time.

This'll happen in two cases:
* redis data is deleted
* the service sent no messages that day

additionally, make sure that we convert nicely from redis' return
values (ascii strings) to unicode keys and integer counts.
2018-04-30 11:13:21 +01:00
Leo Hemsted
85fd7c3869 add new tests for template statistics 2018-04-30 11:13:21 +01:00
Leo Hemsted
9e8b6fd00d refactor template stats endpoint to read from new redis keys
New redis keys are partitioned per service per day. New process is as
follows:

* require a count of days to filter by. Currently admin always gives 7.
* for each day, check and see if there's anything in redis. There won't
  be if either a) redis is/was down or b) the service didn't send any
  notifications that day
  - if there isn't, go to the database and get a count out.
* combine all these stats together
* get the names/template types etc out of the DB at the end.
2018-04-30 11:13:21 +01:00
Leo Hemsted
5e702449cb move days_ago to utils and make it tz aware
it's used in a few places - it should definitely know what timezones
are and return datetimes rather than dates, which are hard to work with
in terms of figuring out how tz aware they are.
2018-04-30 11:13:21 +01:00
Leo Hemsted
67019fc5a1 add day filter to template usage dao, and remove NotificationHistory
we should be very careful with when we get data from
NotificationHistory - this should probably only be from scheduled
tasks. `dao_get_template_usage` is only called from the template
statistics rest endpoint, so shouldn't ever hit template history.

also, moved tests out to new file to break up the 2k test file a bit
2018-04-30 11:13:21 +01:00
Leo Hemsted
901383777b Merge pull request #1844 from alphagov/zendesk
zendesk instead of deskpro
2018-04-27 16:59:08 +01:00
Leo Hemsted
897ab93148 zendesk instead of deskpro 2018-04-27 16:36:39 +01:00
Chris Waszczuk
cc6e4fabe1 Merge pull request #1839 from alphagov/make-service-stats-7-days-max
Adjust get_service_stats to get counts for a maximum of 7 days ago
2018-04-26 15:10:40 +01:00
Rebecca Law
51af6b27a0 Update name of method to clarify the meaning.
Update group by to use label.
Update test.
2018-04-25 17:00:19 +01:00