Skip to content

Commit

Permalink
Merge pull request #1585 from fedspendingtransparency/stg
Browse files Browse the repository at this point in the history
Sprint 71 Deploy (stg->master)
  • Loading branch information
tony-sappe authored Oct 11, 2018
2 parents 12bcdfe + 0c8811c commit 58409b5
Show file tree
Hide file tree
Showing 41 changed files with 743 additions and 968 deletions.
1 change: 1 addition & 0 deletions usaspending_api/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ class FederalAccountByObligationSerializer(serializers.Serializer):

id = serializers.CharField()
account_title = serializers.CharField()
account_number = serializers.CharField()
obligated_amount = serializers.DecimalField(None, 2)
8 changes: 6 additions & 2 deletions usaspending_api/accounts/tests/test_federal_obligations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ def financial_obligations_models():
fiscal_year = mommy.make('submissions.SubmissionAttributes', reporting_fiscal_year=2016)
top_tier_id = mommy.make('references.Agency', id=654, toptier_agency_id=987).toptier_agency_id
top_tier = mommy.make('references.ToptierAgency', toptier_agency_id=top_tier_id)
federal_id_awesome = mommy.make('accounts.FederalAccount', id=6969, account_title='Turtlenecks and Chains')
federal_id_lame = mommy.make('accounts.FederalAccount', id=1234, account_title='Suits and Ties')
federal_id_awesome = mommy.make('accounts.FederalAccount', id=6969, agency_identifier="867",
main_account_code="5309", account_title='Turtlenecks and Chains')
federal_id_lame = mommy.make('accounts.FederalAccount', id=1234, agency_identifier="314",
main_account_code="1592", account_title='Suits and Ties')
"""
Until this gets updated with mock.Mock(),
the following cascade of variables applied to parameters,
Expand Down Expand Up @@ -106,10 +108,12 @@ def test_financial_obligations(client, financial_obligations_models):
assert len(resp.data['results']) == 2
res_awesome = resp.data['results'][0]
assert res_awesome['id'] == '1234'
assert res_awesome['account_number'] == '314-1592'
assert res_awesome['account_title'] == 'Suits and Ties'
assert res_awesome['obligated_amount'] == '400.00'
res_lame = resp.data['results'][1]
assert res_lame['id'] == '6969'
assert res_lame['account_number'] == '867-5309'
assert res_lame['account_title'] == 'Turtlenecks and Chains'
assert res_lame['obligated_amount'] == '100.00'

Expand Down
6 changes: 5 additions & 1 deletion usaspending_api/accounts/v2/filters/account_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ def generate_treasury_account_query(queryset, account_type, tas_id):
ata_subquery = ToptierAgency.objects.filter(cgac_code=OuterRef('{}__allocation_transfer_agency_id'.format(tas_id)))
agency_name_subquery = ToptierAgency.objects.filter(cgac_code=OuterRef('{}__agency_id'.format(tas_id)))
derived_fields = {
# treasury_account_symbol: AID-BPOA/EPOA-MAC-SAC or AID-"X"-MAC-SAC
# treasury_account_symbol: [ATA-]AID-BPOA/EPOA-MAC-SAC or [ATA-]AID-"X"-MAC-SAC
'treasury_account_symbol': Concat(
Case(When(**{'{}__allocation_transfer_agency_id__isnull'.format(tas_id): False,
'then': Concat('{}__allocation_transfer_agency_id'.format(tas_id), Value('-'))}),
default=Value(''),
output_field=CharField()),
'{}__agency_id'.format(tas_id),
Value('-'),
Case(When(**{'{}__availability_type_code'.format(tas_id): 'X', 'then': Value('X')}),
Expand Down
8 changes: 4 additions & 4 deletions usaspending_api/accounts/v2/views/budget_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class ListBudgetFunctionViewSet(APIDocumentationView):
"""
This route sends a request to the backend to retrieve all Budget Functions associated with a TAS, ordered by Budget
Function code.
endpoint_doc: /budget_function.md
endpoint_doc: /budget_functions/list_budget_function.md
"""
@cache_response()
def get(self, request):
# Retrieve all Budget Functions, grouped by code and title, ordered by code
results = TreasuryAppropriationAccount.objects \
.filter(~Q(budget_function_code=''), ~Q(budget_function_code=None)) \
.values('budget_function_code', 'budget_function_title') \
.order_by('budget_function_code').distinct()
.order_by('budget_function_title').distinct()

return Response({'results': results})

Expand All @@ -27,7 +27,7 @@ class ListBudgetSubfunctionViewSet(APIDocumentationView):
"""
This route sends a request to the backend to retrieve all Budget Subfunctions associated with a TAS, ordered by
Budget Subfunction code. Can be filtered by Budget Function.
endpoint_doc: /budget_subfunction.md
endpoint_doc: /budget_functions/list_budget_subfunction.md
"""
@cache_response()
def post(self, request):
Expand All @@ -43,6 +43,6 @@ def post(self, request):
# Group by code and title, order by code
results = queryset \
.values('budget_subfunction_code', 'budget_subfunction_title') \
.order_by('budget_subfunction_code').distinct()
.order_by('budget_subfunction_title').distinct()

return Response({'results': results})
4 changes: 2 additions & 2 deletions usaspending_api/accounts/views/federal_obligations.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def get_queryset(self):
queryset = queryset.annotate(
account_title=F('treasury_account_identifier__federal_account__account_title'),
id=F('treasury_account_identifier__federal_account')

)
# Sum and sort descending obligations_incurred by account
queryset = queryset.values(
'id',
'account_title'
'account_title',
).annotate(
account_number=F('treasury_account_identifier__federal_account__federal_account_code'),
obligated_amount=Sum('obligations_incurred_total_by_tas_cpe')
).order_by('-obligated_amount')
# Return minor object class vars
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## List Budget Functions
**Route:** `/api/v2/budget_functions/list_budget_functions/`

**Method** `GET`

This route sends a request to the backend to retrieve a list of all Budget Functions ordered by their title.


## Response (JSON)

**HTTP Status Code**: 200

```
{
"results": [
{
"budget_function_code": "000",
"budget_function_title": "Governmental Receipts"
},
{
"budget_function_code": "050",
"budget_function_title": "National Defense"
},
{
"budget_function_code": "150",
"budget_function_title": "International Affairs"
},
...
]
}
```

**Response Key Descriptions**

**budget_subfunction_title** - Title of the Budget Subfunction.

**budget_subfunction_code** - Code for the Budget Subfunction.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
## List Budget Subfunctions
**Route:** `/api/v2/budget_functions/list_budget_subfunctions/`

**Method** `POST`

This route sends a request to the backend to retrieve a list of all Budget Subfunctions that can be filtered by Budget Function, ordered by their title.

### Request

```
{
"budget_function":"050"
}
```
**Query Parameters Description**

**budget_function** - `optional` - a string that contains the budget function code to filter by


### Response (JSON)

**HTTP Status Code**: 200

```
{
"results": [
{
"budget_subfunction_title": "Atomic energy defense activities",
"budget_subfunction_code": "053"
},
{
"budget_subfunction_title": "Defense-related activities",
"budget_subfunction_code": "054"
},
{
"budget_subfunction_title": "Department of Defense-Military",
"budget_subfunction_code": "051"
}
]
}
```

**Response Key Descriptions**

**budget_subfunction_title** - Title of the Budget Subfunction.

**budget_subfunction_code** - Code for the Budget Subfunction.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ This route sends a request to the backend to begin generating a zipfile of accou
* `fy` - *required* - fiscal year
* `quarter` - *required* - fiscal quarter
* `file_format` - *optional* - must be `csv`
* `columns` - *optional* - columns to select

### Response (JSON)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Federal Obligations
**Route:** `v2/federal_obligations?fiscal_year=[year]&federal_account_id=[id]`
**Route:** `v2/federal_obligations?fiscal_year=[year]&funding_agency_id=[id]`

**Example:** `v2/federal_obligations?fiscal_year=2017&funding_agency_id=1068`

Expand All @@ -11,7 +11,7 @@ This route sends a request to the backend to retrieve federal obligations.
### Query Parameters Description

* `year` - **REQUIRED** - Required parameter indicating what fiscal year to retrieve federal obligations.
* `id` - **REQUIRED** - Required parameter indicating what Agency to retrieve federal obligations for.
* `funding_agency_id` - **REQUIRED** - Required parameter indicating what Agency to retrieve federal obligations for.
* `limit` - **OPTIONAL** - How many results are returned.
* `page` - **OPTIONAL** - What page of results are returned.

Expand All @@ -31,21 +31,25 @@ This route sends a request to the backend to retrieve federal obligations.
"results": [
{
"id": "2497",
"account_number":"020-1234",
"account_title": "Federal Direct Student Loan Program, Education",
"obligated_amount": "45538408088.64"
},
{
"id": "2484",
"account_number":"020-1534",
"account_title": "Student Financial Assistance, Education",
"obligated_amount": "33796974073.25"
},
{
"id": "2509",
"account_number":"070-1234",
"account_title": "Education for the Disadvantaged, Education",
"obligated_amount": "16789619206.31"
},
{
"id": "2500",
"account_number":"070-1534",
"account_title": "Special Education, Education",
"obligated_amount": "13063113992.31"
},...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
## [Data Dictionary](#data_dictionary)
**Route:** `/api/v2/references/data_dictionary/`

**Method:** `GET`

This route takes no parameters and returns a JSON structure of the Schema team's Rosetta Crosswalk Data Dictionary

### Request
*Not Applicable*

### Response (JSON)

```
{
"rows": [
[
"Interstate Entity",
"https://www.sam.gov",
"Interstate Entity",
"all_contracts_prime_awards_1.csv,\nall_contracts_prime_transactions_1.csv",
"interstate_entity",
null,
null,
null,
null,
"isinterstateentity",
null
],
[
"Joint Venture Economically Disadvantaged Women Owned Small Business",
"https://www.sam.gov OR List characteristic of the contractor such as whether the selected contractor is an Economically Disadvantaged Woman Owned Small Business or not. It can be derived from the SAM data element, 'Business Types'.",
"Joint Venture Economically Disadvantaged Women Owned Small Business",
"all_contracts_prime_awards_1.csv,\nall_contracts_prime_transactions_1.csv",
"joint_venture_economic_disadvantaged_women_owned_small_bus",
null,
null,
null,
null,
"isjointventureecondisadvwomenownedsmallbusiness",
null
]
],
"headers": [
{
"raw": "element",
"display": "Element"
},
{
"raw": "definition",
"display": "Definition"
},
{
"raw": "fpds_element",
"display": "FPDS Element"
},
{
"raw": "award_file",
"display": "Award File"
},
{
"raw": "award_element",
"display": "Award Element"
},
{
"raw": "subaward_file",
"display": "Subaward File"
},
{
"raw": "subaward_element",
"display": "Subaward Element"
},
{
"raw": "account_file",
"display": "Account File"
},
{
"raw": "account_element",
"display": "Account Element"
},
{
"raw": "legacy_award_element",
"display": "Award Element"
},
{
"raw": "legacy_subaward_element",
"display": "Subaward Element"
}
],
"metadata": {
"download_location": "http://files.usaspending.gov/docs/DATA+Transparency+Crosswalk.xlsx",
"total_rows": 393,
"total_size": "116.52KB",
"total_columns": 11
},
"sections": [
{
"colspan": 3,
"section": "Schema Data Label & Description"
},
{
"colspan": 6,
"section": "USA Spending Downloads"
},
{
"colspan": 2,
"section": "Legacy USA Spending"
}
]
}
```


### Errors
Possible HTTP Status Codes:
* 200 : Success
* 204 : No data found in database
* 500 : All other errors

```
{
"detail": "Sample error message"
}
```
14 changes: 14 additions & 0 deletions usaspending_api/api_docs/api_documentation/spending_explorer.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ This route sends a request to the backend to retrieve spending data information
}
```

**NOTE**: For `type: federal_account` responses, the response object will also contain an `account_number` field containing the federal account code,. i.e.,

```
{
"amount": 141781627513.91,
"id": 577,
"type": "federal_account",
"name": "Department of Veterans Affairs",
"code": "036",
"total": 141781627513.91
"account_number": "123-4567"
}
```

**Response Key Descriptions**

**id** - The Database Id for the requested *type*
Expand Down
Loading

0 comments on commit 58409b5

Please sign in to comment.