tottag 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ """
2
+ Function: This script finds all .pkl files in a specified directory, extracts the subject_id from the filename,
3
+ loads the corresponding data, and processes it using the get_daily_ranging_statistics function.
4
+
5
+ Usage:
6
+ cd SociTrack/software/management/dashboard
7
+ python3 1_tottags_batch.py
8
+ """
9
+
10
+ import re
11
+ import csv
12
+
13
+ # Define input and output file paths
14
+ input_file = "/Users/hannahpiersiak/Desktop/tottags/ranging_statistics.txt"
15
+ output_file = "/Users/hannahpiersiak/Desktop/tottags/ranging_statistics.csv"
16
+
17
+ # Open the input file and read its contents
18
+ with open(input_file, "r") as file:
19
+ data = file.readlines()
20
+
21
+ # Prepare data extraction
22
+ csv_data = []
23
+ current_date = None
24
+
25
+ # Regex patterns to extract data
26
+ date_pattern = re.compile(r"Ranging Statistics on (\d{2}/\d{2}/\d{4}):")
27
+ stats_pattern = re.compile(r"Statistics to (r\.\d+_CG\d|Either of \[.*\]):")
28
+ value_pattern = re.compile(r"^\s+(\w.+):\s+([\d.]+|nan)")
29
+
30
+ # Parse the file line by line
31
+ for line in data:
32
+ date_match = date_pattern.search(line)
33
+ stats_match = stats_pattern.search(line)
34
+ value_match = value_pattern.search(line)
35
+
36
+ if date_match:
37
+ current_date = date_match.group(1) # Extract the date
38
+ elif stats_match:
39
+ current_target = stats_match.group(1) # Extract the target (CG1, CG2, or Either)
40
+ minutes_range = minutes_touch = mean_distance = None
41
+ elif value_match:
42
+ key, value = value_match.groups()
43
+ if key == "Minutes in Range":
44
+ minutes_range = value
45
+ elif key == "Minutes in Touching Distance":
46
+ minutes_touch = value
47
+ elif key == "Mean Distance While in Range":
48
+ mean_distance = value
49
+ # Save row when all values for a section are collected
50
+ csv_data.append([current_date, current_target, minutes_range, minutes_touch, mean_distance])
51
+
52
+ # Write to CSV file
53
+ with open(output_file, "w", newline="") as file:
54
+ writer = csv.writer(file)
55
+ writer.writerow(["Date", "Target", "Minutes in Range", "Minutes in Touching Distance", "Mean Distance While in Range"])
56
+ writer.writerows(csv_data)
57
+
58
+ print(f"CSV file saved: {output_file}")
59
+
@@ -0,0 +1,34 @@
1
+ """
2
+ Function: This script finds all .pkl files in a specified directory, extracts the subject_id from the filename,
3
+ loads the corresponding data, and processes it using the get_daily_ranging_statistics function.
4
+
5
+ Usage:
6
+ cd SociTrack/software/management/dashboard
7
+ python3 1_tottags_batch.py
8
+ """
9
+
10
+ import os
11
+ from processing import *
12
+
13
+
14
+ def process_pkl_files(directory):
15
+ """Find all .pkl files in the directory, extract subject_id, load data, and process it."""
16
+ for filename in os.listdir(directory):
17
+ if filename.endswith(".pkl"):
18
+ filepath = os.path.join(directory, filename)
19
+
20
+ # Extract subject_id from filename
21
+ subject_id = filename.split("_")[0]
22
+
23
+ # Load pkl data
24
+ TC = load_data(filepath)
25
+
26
+ # Call the function with formatted parameters
27
+ get_daily_ranging_statistics(TC, [f"{subject_id}_CG1", f"{subject_id}_CG2"], 3)
28
+
29
+
30
+ # Define directory path
31
+ directory_path = "/Users/hannahpiersiak/Desktop/tottags"
32
+
33
+ # Run the function
34
+ process_pkl_files(directory_path)
@@ -0,0 +1,61 @@
1
+ import csv
2
+ import re
3
+
4
+ # Input and output file paths
5
+ input_file = "/Users/hannahpiersiak/Desktop/tottags/ranging_statistics.txt"
6
+ output_file = "/Users/hannahpiersiak/Desktop/tottags/ranging_statistics.csv"
7
+
8
+ # Regular expressions to extract relevant data
9
+ date_pattern = re.compile(r"Ranging Statistics on (\d{2}/\d{2}/\d{4}):")
10
+ entity_pattern = re.compile(r"Statistics to (\S+):")
11
+ minutes_range_pattern = re.compile(r"Minutes in Range: (\d+)")
12
+ minutes_touch_pattern = re.compile(r"Minutes in Touching Distance: (\d+)")
13
+ mean_distance_pattern = re.compile(r"Mean Distance While in Range: (.+)")
14
+
15
+ # Storage variables
16
+ data = []
17
+ current_date = None
18
+ current_entity = None
19
+
20
+ # Read and parse the text file
21
+ with open(input_file, "r") as infile:
22
+ for line in infile:
23
+ line = line.strip()
24
+
25
+ # Extract date
26
+ date_match = date_pattern.match(line)
27
+ if date_match:
28
+ current_date = date_match.group(1)
29
+ print(f"Date found: {current_date}") # Debugging line
30
+ continue
31
+
32
+ # Extract entity
33
+ entity_match = entity_pattern.match(line)
34
+ if entity_match:
35
+ current_entity = entity_match.group(1)
36
+ print(f"Entity found: {current_entity}") # Debugging line
37
+ continue
38
+
39
+ # Extract statistics
40
+ minutes_range_match = minutes_range_pattern.match(line)
41
+ minutes_touch_match = minutes_touch_pattern.match(line)
42
+ mean_distance_match = mean_distance_pattern.match(line)
43
+
44
+ if minutes_range_match:
45
+ minutes_range = int(minutes_range_match.group(1))
46
+ if minutes_touch_match:
47
+ minutes_touch = int(minutes_touch_match.group(1))
48
+ if mean_distance_match:
49
+ mean_distance = mean_distance_match.group(1) # Keep as string for 'nan' handling
50
+
51
+ # Save extracted data
52
+ print(f"Adding data: {current_date}, {current_entity}, {minutes_range}, {minutes_touch}, {mean_distance}") # Debugging line
53
+ data.append([current_date, current_entity, minutes_range, minutes_touch, mean_distance])
54
+
55
+ # Write to CSV
56
+ with open(output_file, "w", newline="") as outfile:
57
+ writer = csv.writer(outfile)
58
+ writer.writerow(["Date", "Entity", "Minutes in Range", "Minutes in Touching Distance", "Mean Distance While in Range"])
59
+ writer.writerows(data)
60
+
61
+ print(f"Data successfully written to {output_file}")
@@ -0,0 +1,34 @@
1
+ """
2
+ Function: This script finds all .pkl files in a specified directory, extracts the subject_id from the filename,
3
+ loads the corresponding data, and processes it using the get_daily_ranging_statistics function.
4
+
5
+ Usage:
6
+ cd SociTrack/software/management/dashboard
7
+ python3 1_tottags_batch.py
8
+ """
9
+
10
+ import os
11
+ from processing import *
12
+
13
+
14
+ def process_pkl_files(directory):
15
+ """Find all .pkl files in the directory, extract subject_id, load data, and process it."""
16
+ for filename in os.listdir(directory):
17
+ if filename.endswith(".pkl"):
18
+ filepath = os.path.join(directory, filename)
19
+
20
+ # Extract subject_id from filename
21
+ subject_id = filename.split("_")[0]
22
+
23
+ # Load pkl data
24
+ CG1 = load_data(filepath)
25
+
26
+ # Call the function with formatted parameters
27
+ get_daily_ranging_statistics(CG1, [f"{subject_id}_CG2"], 3)
28
+
29
+
30
+ # Define directory path
31
+ directory_path = "/Users/hannahpiersiak/Desktop/tottags"
32
+
33
+ # Run the function
34
+ process_pkl_files(directory_path)
tottag/__init__.py ADDED
File without changes