Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Implemented the remove_outdated function
Browse files Browse the repository at this point in the history
  • Loading branch information
arcrose committed Aug 2, 2019
1 parent 5d80815 commit 74c2092
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions alerts/geomodel/locality.py
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
from typing import Any, Dict, List, NamedTuple, Optional

from mozdef_util.query_models import SearchQuery, TermMatch
Expand Down Expand Up @@ -124,11 +124,18 @@ def merge(persisted: List[State], event_sourced: List[State]) -> List[Update]:

return mapped.values()

def remove_outdated(state: State, days_valid: int) -> State:
'''Return a new `State` with localities from `state` that are considered
def remove_outdated(
localities: List[Locality],
days_valid: int
) -> List[Locality]:
'''Return a new list of localities with those that are considered
"outdated" removed. A `Locality` is considered to be out of date when the
recorded last activity within that locality was greater than some number of
days ago.
'''

return state
return [
loc
for loc in localities
if loc.lastaction >= datetime.utcnow() - timedelta(days=days_valid)
]

0 comments on commit 74c2092

Please sign in to comment.