Services for DNA operations.
- Java 8
- Maven
- Python 3.7 (for AWS Lambda function)
-
This API is hosted by AWS Elastic Beanstalk. Host URI can be found in the next section.
-
A few extra, non-specified endpoints (
POST /humans
andGET /dnas/{id}
) were added.
-
Aggregate DNA stats are provided by an AWS Lambda function, with Python script code. This Lambda is triggered by any update to the Dna DynamoDB table, and will shift count stats on
INSERT
andREMOVE
events. (There's no endpoint for removal, but it was kept this way in order to make testing easier.) -
Since aggregate data is generated by a Lambda, eventual consistency should be expected for DNA stats. In my tests, however, data seemed to have always been updated almost in real time.
-
The Python function can be found at
src/main/resources/dna-stats-aggregator.py
-
Ratio will be null when there are 0 humans registered (no division by zero allowed).
-
The Simian Algorithm is inside the
DnaCategorizer
class, as a private method. -
The method takes a
List<String>
rather than aString[]
as a parameter for consistency - specially since converting this List to an Array and then to a Char Matrix (as the algorithm does) could slightly impact performance. -
The algorithm will search for at least 2 sequences of 4 equal letters for it to be considered a Simian. Since it wasn't stated that those sequences should be distinct, repeated sequences will also be considered (e.g. 2 sequences of
AAAA
).
- SpringBoot's default integration test is annotated with
@Ignore
due to AWS access keys not being hardcoded in properties. These are input as environment variables. Still, test coverage will be above 80% lines of code as required.
Returns any DNA by ID.
GET /dnas/2dfbc2b5-163e-36e4-a0fc-30bd5b534426
Response:
{
"dna_id": "2dfbc2b5-163e-36e4-a0fc-30bd5b534426",
"category": "HUMAN",
"dna": [
"TTGCGA",
"CAGTGC",
"TTATGT",
"AGAGGA",
"CCCTTA",
"TCACTG"
]
}
Creates DNA for a Simian. Returns the new resource.
POST /dnas/simians
Body:
{
"dna": ["ATGCGA", "CAGTGC", "TTATGT", "AAAAGG", "CCCCTA", "TCCCTG"]
}
Response:
{
"dna_id": "asdfs878-163e-36e4-a0fc-asdf7s8df8",
"category": "SIMIAN",
"dna": [
"ATGCGA",
"CAGTGC",
"TTATGT",
"AAAAGG",
"CCCCTA",
"TCCCTG"
]
}
Creates DNA for a Human. Returns the new resource.
POST /dnas/humans
Body:
{
"dna": ["TTGCGA", "CAGTGC", "TTATGT", "AGAGGA", "CCCTTA", "TCACTG"]
}
Response:
{
"dna_id": "2dfbc2b5-163e-36e4-a0fc-30bd5b534426",
"category": "HUMAN",
"dna": [
"TTGCGA",
"CAGTGC",
"TTATGT",
"AGAGGA",
"CCCTTA",
"TCACTG"
]
}
Returns DNA Stats to count simians, humans and ratio of simians per humans. Ratio should be presented with a scale of 4.
Note: Eventual consistency should be expected.
GET /dnas/stats
Response:
{
"count_mutant_dna": 2,
"count_human_dna": 3,
"ratio": 0.6667
}