Skip to content

Commit

Permalink
Convert timestamps to UK timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
vloothuis committed Nov 14, 2023
1 parent d80fb23 commit 3fb363d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
Binary file modified public/port-0.0.0-py3-none-any.whl
Binary file not shown.
Binary file modified src/framework/processing/py/dist/port-0.0.0-py3-none-any.whl
Binary file not shown.
5 changes: 4 additions & 1 deletion src/framework/processing/py/port/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import zipfile
import json
import datetime
import pytz
import fnmatch
from collections import defaultdict, namedtuple
from contextlib import suppress
Expand All @@ -21,7 +22,9 @@


def parse_datetime(value):
return datetime.datetime.fromtimestamp(value)
utc_datetime = datetime.datetime.fromtimestamp(value, tz=datetime.timezone.utc)
uk_timezone = pytz.timezone('Europe/London')
return uk_timezone.normalize(utc_datetime.astimezone(uk_timezone))


def get_in(data_dict, *key_path):
Expand Down
52 changes: 26 additions & 26 deletions src/framework/processing/py/tests/script_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ def test_video_posts_table():

reference = """
Date Timeslot Videos Stories
0 2023-03-13 22-23 2 1
1 2023-03-14 1-2 3 0
2 2023-03-14 5-6 1 0
3 2023-03-14 12-13 1 0
0 2023-03-13 21-22 2 1
1 2023-03-14 0-1 3 0
2 2023-03-14 4-5 1 0
3 2023-03-14 11-12 1 0
"""
print(result.data_frame)
assert_frame_str_equal(reference, result.data_frame)
Expand Down Expand Up @@ -173,8 +173,8 @@ def test_comments_and_likes_table():

reference = """
Date Timeslot Comments Likes
0 2023-03-13 22-23 1 2
1 2023-03-14 1-2 1 0
0 2023-03-13 21-22 1 2
1 2023-03-14 0-1 1 0
"""
print(result.data_frame)
assert_frame_str_equal(reference, result.data_frame)
Expand Down Expand Up @@ -203,8 +203,8 @@ def test_viewed_table():

reference = """
Date Timeslot Videos Posts
0 2023-03-13 22-23 2 1
1 2023-03-14 13-14 0 1
0 2023-03-13 21-22 2 1
1 2023-03-14 12-13 0 1
"""
print(result.data_frame)
assert_frame_str_equal(reference, result.data_frame)
Expand All @@ -218,10 +218,10 @@ def test_session_info_table():

reference = """
Start Duration (in minutes)
0 2023-03-13 22:33 3.53
1 2023-03-14 01:05 0.97
2 2023-03-14 05:59 0.00
3 2023-03-14 12:27 0.00
0 2023-03-13 21:33 3.53
1 2023-03-14 00:05 0.97
2 2023-03-14 04:59 0.00
3 2023-03-14 11:27 0.00
"""
print(result.data_frame)
assert_frame_str_equal(reference, result.data_frame)
Expand Down Expand Up @@ -272,12 +272,12 @@ def test_direct_message_activity_table():

reference = """
Anonymous ID Sent
0 0 2023-02-27 11:18
1 1 2023-02-27 11:18
2 0 2023-02-27 11:19
3 2 2023-02-27 11:21
4 0 2023-02-27 11:21
5 2 2023-02-27 11:21
0 0 2023-02-27 10:18
1 1 2023-02-27 10:18
2 0 2023-02-27 10:19
3 2 2023-02-27 10:21
4 0 2023-02-27 10:21
5 2 2023-02-27 10:21
"""
print(result.data_frame)
assert_frame_str_equal(reference, result.data_frame)
Expand Down Expand Up @@ -329,11 +329,11 @@ def test_comment_activity_table():

reference = """
Posted
0 2023-03-13 22:37
1 2023-03-13 22:37
2 2023-03-13 23:49
3 2023-03-14 00:26
4 2023-03-16 21:53
0 2023-03-13 21:37
1 2023-03-13 21:37
2 2023-03-13 22:49
3 2023-03-13 23:26
4 2023-03-16 20:53
"""
print(result.data_frame)
assert_frame_str_equal(reference, result.data_frame)
Expand Down Expand Up @@ -378,9 +378,9 @@ def test_posts_liked_table():

reference = """
Liked Link
0 2023-03-13 22:37 https://example.org/test1
1 2023-03-13 22:37 https://example.org/test2
2 2023-03-13 23:49 https://example.org/test3
0 2023-03-13 21:37 https://example.org/test1
1 2023-03-13 21:37 https://example.org/test2
2 2023-03-13 22:49 https://example.org/test3
"""
print(result.data_frame)
assert_frame_str_equal(reference, result.data_frame)
1 change: 1 addition & 0 deletions src/framework/processing/py_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ function installPortPackage() {
console.log('[ProcessingWorker] load port package')
return self.pyodide.runPythonAsync(`
import micropip
await micropip.install("https://files.pythonhosted.org/packages/32/4d/aaf7eff5deb402fd9a24a1449a8119f00d74ae9c2efa79f8ef9994261fc2/pytz-2023.3.post1-py2.py3-none-any.whl")
await micropip.install("../../port-0.0.0-py3-none-any.whl", deps=False)
import port
`)
Expand Down

0 comments on commit 3fb363d

Please sign in to comment.