Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ActivityTracker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
willm3
ActivityTracker
Merge requests
!16
Correctly import datetime
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Correctly import datetime
wmalisch/import-org-and-datetime-import
into
main
Overview
2
Commits
2
Pipelines
0
Changes
5
Merged
willm3
requested to merge
wmalisch/import-org-and-datetime-import
into
main
1 year ago
Overview
2
Commits
2
Pipelines
0
Changes
5
Expand
Created by: will-malisch
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
4713d49e
2 commits,
1 year ago
5 files
+
45
−
24
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
src/activity.py
+
16
−
14
Options
from
scipy.signal
import
find_peaks
from
src.sqlite_db_client
import
SQLiteDBClient
from
pathlib
import
Path
from
datetime
import
datetime
import
numpy
as
np
import
time
import
csv
import
pytz
from
scipy.signal
import
find_peaks
from
src.sqlite_db_client
import
SQLiteDBClient
from
pathlib
import
Path
from
datetime
import
datetime
class
Activity
:
def
__init__
(
self
,
sense
):
self
.
sense
=
sense
@@ -19,15 +20,13 @@ class Activity:
self
.
running
=
True
magnitudes
=
[]
# Get the current date and time (in UTC)
utc_now
=
datetime
.
now
(
pytz
.
utc
)
# Localize the current time to Eastern Standard Time (EST)
est_now
=
utc_now
.
astimezone
(
self
.
est_timezone
)
# Get start time
utc_start
=
datetime
.
now
(
pytz
.
utc
)
est_start
=
utc_start
.
astimezone
(
self
.
est_timezone
)
# Extract the date and time components
start_date
=
est_
now
.
strftime
(
'
%Y-%m-%d
'
)
start_time
=
est_
now
.
strftime
(
'
%H:%M:%S
'
)
start_date
=
est_
start
.
strftime
(
'
%Y-%m-%d
'
)
start_time
=
est_
start
.
strftime
(
'
%H:%M:%S
'
)
# Write accelerometer data to disk as a default in case we need to back it up later
timestamp
=
int
(
time
.
time
())
@@ -71,9 +70,12 @@ class Activity:
# Calculate the peaks - these are steps!
steps
,
_
=
find_peaks
(
magnitudes
,
height
=
(
std_dev
+
mean
))
# Update SQLite database with the recorded activity
end_date
=
est_now
.
strftime
(
'
%Y-%m-%d
'
)
end_time
=
est_now
.
strftime
(
'
%H:%M:%S
'
)
# Update SQLite database with the recorded activity\
utc_end
=
datetime
.
now
(
pytz
.
utc
)
est_end
=
utc_end
.
astimezone
(
self
.
est_timezone
)
end_date
=
est_end
.
strftime
(
'
%Y-%m-%d
'
)
end_time
=
est_end
.
strftime
(
'
%H:%M:%S
'
)
steps_count
=
len
(
steps
)
self
.
db_client
.
insert_activity_entry
(
start_date
,
start_time
,
end_date
,
end_time
,
steps_count
)
Loading