Skip to content

Commit

Permalink
Added option to fetch only latest location
Browse files Browse the repository at this point in the history
  • Loading branch information
dchristl committed Apr 17, 2023
1 parent b141308 commit 7ecf2a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion headless_haystack/lib/dashboard/dashboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class _DashboardState extends State<Dashboard> {
SnackBar(
backgroundColor: Theme.of(context).colorScheme.primary,
content: Text(
'Fetched $count locations',
'Fetched $count location(s)',
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary,
),
Expand Down
12 changes: 9 additions & 3 deletions headless_haystack/lib/history/accessory_history.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class AccessoryHistory extends StatefulWidget {
Key? key,
required this.accessory,
}) : super(key: key);

@override
State<StatefulWidget> createState() {
return _AccessoryHistoryState();
Expand All @@ -30,12 +31,16 @@ class _AccessoryHistoryState extends State<AccessoryHistory> {
bool showPopup = false;
Pair<LatLng, DateTime>? popupEntry;

double numberOfDays = Settings.getValue<int>(numberOfDaysToFetch, defaultValue: 7)!.toDouble();
double numberOfDays =
Settings.getValue<int>(numberOfDaysToFetch, defaultValue: 7)!.toDouble();

@override
void initState() {
super.initState();
_mapController = MapController();
if (numberOfDays < 1) {
numberOfDays = 7;
}
WidgetsBinding.instance.addPostFrameCallback((_) {
mapReady();
});
Expand All @@ -55,8 +60,9 @@ class _AccessoryHistoryState extends State<AccessoryHistory> {
.toList();

return Scaffold(
appBar: AppBar(
title: Text("${widget.accessory.name} (${widget.accessory.locationHistory.length} history reports)"),
appBar: AppBar(
title: Text(
"${widget.accessory.name} (${widget.accessory.locationHistory.length} history reports)"),
),
body: SafeArea(
child: Column(
Expand Down
3 changes: 2 additions & 1 deletion headless_haystack/lib/preferences/preferences_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ class _PreferencesPageState extends State<PreferencesPage> {
title: 'Number of days to fetch location',
settingKey: numberOfDaysToFetch,
values: const <int, String>{
0: "latest location only",
1: "1",
2: "2",
3: "3",
4: "4",
5: "5",
6: "6",
7: "7"
7: "7",
},
selected: 7,
);
Expand Down
9 changes: 7 additions & 2 deletions webserver/FindMy_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,21 @@ def do_POST(self):
res = conn.getresponse()
result = json.loads(res.read())


results = result["results"]

newResults = []
latestEntry = None

for idx, entry in enumerate(results):
if (int(entry["datePublished"]) > startdate):
newResults.append(entry)
if latestEntry is None:
latestEntry = entry
elif latestEntry["datePublished"] < entry["datePublished"]:
latestEntry = entry


if days < 1 and latestEntry is not None:
newResults.append(latestEntry)
result["results"] = newResults
self.send_response(200)
# send response headers
Expand Down

0 comments on commit 7ecf2a9

Please sign in to comment.