AEUPH commited on
Commit
c2f48f9
·
verified ·
1 Parent(s): ac4aa15

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -23,25 +23,34 @@ print("Dataset loaded successfully.")
23
 
24
  from scipy.spatial import KDTree
25
 
26
- print("Extracting positions and building KD-tree...")
27
-
28
- # Assuming final_positions is structured as shown
29
- final_positions = [position for item in dataset for position in item['data']['final_positions']]
30
  positions_array = np.array([[p['x'], p['y'], p['z']] for p in final_positions])
31
 
32
- # Build a KD-tree
33
- tree = KDTree(positions_array)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- print("KD-tree constructed successfully.")
36
 
37
- # Example current_xyz coordinate
38
- current_xyz = [1, 2, 3] # Replace with actual values as needed
39
 
40
- print("Querying KD-tree for the nearest position...")
41
- distance, index = tree.query(current_xyz)
42
- nearest_position = final_positions[index]
43
 
44
- print(f"Nearest position found: {nearest_position} at distance {distance}")
45
 
46
  def safe_convert_single_to_double_quotes(s):
47
  try:
 
23
 
24
  from scipy.spatial import KDTree
25
 
26
+ import time
27
+ # Assuming positions_array is already defined
28
+ # Extract 'final_positions' from each item in the dataset and compile them into a NumPy array
29
+ final_positions = [position for item in dataset['final_positions'] for position in item]
30
  positions_array = np.array([[p['x'], p['y'], p['z']] for p in final_positions])
31
 
32
+ def estimate_time_and_build_kdtree(data):
33
+ start_time = time.time()
34
+ print("Estimating time based on dataset size...")
35
+
36
+ # Mock estimation logic for demonstration
37
+ estimated_time_seconds = len(data) * 0.0001 # Adjust based on your context
38
+ print(f"Estimated time to build KD-tree: {estimated_time_seconds:.2f} seconds")
39
+
40
+ # Actual KD-tree construction
41
+ tree = KDTree(data)
42
+
43
+ end_time = time.time()
44
+ actual_time_taken = end_time - start_time
45
+ print(f"KD-tree built in {actual_time_taken:.2f} seconds.")
46
+ return tree
47
+
48
+ # Now, with positions_array defined, build the KD-tree and estimate time
49
+ tree = estimate_time_and_build_kdtree(positions_array)
50
 
 
51
 
 
 
52
 
 
 
 
53
 
 
54
 
55
  def safe_convert_single_to_double_quotes(s):
56
  try: