np_codeocean 0.3.5__py3-none-any.whl → 0.3.6__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.
@@ -87,4 +87,4 @@ def get_current_rig_model(
87
87
  storage_directory,
88
88
  datetime.datetime.now(),
89
89
  rig_name,
90
- )
90
+ )
@@ -106,4 +106,4 @@ def is_retrofitted_rig(rig_name: str) -> bool:
106
106
  """Retrofitted rigs are behavior box rigs that have a speaker attached and
107
107
  have a different solenoid.
108
108
  """
109
- return not rig_name.startswith("G")
109
+ return not rig_name.startswith("G")
@@ -1,78 +1,78 @@
1
- """Stores a history of object changes in local storage. Simple updater and
2
- getter for iterations of a file.
3
- """
4
-
5
- import datetime
6
- import json
7
- import logging
8
- import pathlib
9
- import shutil
10
-
11
- logger = logging.getLogger(__name__)
12
-
13
-
14
- def _generate_item_filename(
15
- *tags: str,
16
- ) -> str:
17
- return "_".join(str(tag) for tag in tags) + "_rig.json"
18
-
19
-
20
- TIMESTAMP_FORMAT = "%Y-%m-%d-%H-%M-%S"
21
-
22
-
23
- def _item_path_sorter(path: pathlib.Path) -> datetime.datetime:
24
- mtime_str = path.stem.replace("_rig", "").split("_")[-1]
25
- return datetime.datetime.strptime(mtime_str, TIMESTAMP_FORMAT)
26
-
27
-
28
- def get_item(
29
- storage_directory: pathlib.Path,
30
- timestamp: datetime.datetime,
31
- *_tags: str,
32
- ) -> pathlib.Path | None:
33
- """Gets latest item before or equal to timestamp."""
34
- search_pattern = _generate_item_filename(*_tags, "*")
35
- logger.info("Search pattern: %s" % search_pattern)
36
- items = list(storage_directory.glob(search_pattern))
37
- if not items:
38
- logger.debug("No item found for tags: %s" % json.dumps(_tags))
39
- return None
40
-
41
- sorted_items = sorted(items, key=_item_path_sorter)
42
- logger.debug("Fetched items: %s" % sorted_items)
43
- logger.debug([_item_path_sorter(item) for item in sorted_items])
44
- filtered = list(
45
- filter(
46
- lambda item: _item_path_sorter(item) <= timestamp,
47
- sorted_items,
48
- )
49
- )
50
- logger.debug("Filtered items: %s" % filtered)
51
- if not filtered:
52
- return None
53
- return filtered[-1]
54
-
55
-
56
- def update_item(
57
- storage_directory: pathlib.Path,
58
- filepath: pathlib.Path,
59
- timestamp: datetime.datetime,
60
- *_tags: str,
61
- ) -> pathlib.Path:
62
- """
63
- Notes
64
- -----
65
- - Also used to initialize a new base rig in local storage.
66
- - If a rig with the same name doest not exist, a new rig will be created.
67
- """
68
- filename = _generate_item_filename(
69
- *_tags,
70
- timestamp.strftime(TIMESTAMP_FORMAT),
71
- )
72
-
73
- return pathlib.Path(
74
- shutil.copy2(
75
- filepath,
76
- storage_directory / filename,
77
- )
78
- )
1
+ """Stores a history of object changes in local storage. Simple updater and
2
+ getter for iterations of a file.
3
+ """
4
+
5
+ import datetime
6
+ import json
7
+ import logging
8
+ import pathlib
9
+ import shutil
10
+
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
+ def _generate_item_filename(
15
+ *tags: str,
16
+ ) -> str:
17
+ return "_".join(str(tag) for tag in tags) + "_rig.json"
18
+
19
+
20
+ TIMESTAMP_FORMAT = "%Y-%m-%d-%H-%M-%S"
21
+
22
+
23
+ def _item_path_sorter(path: pathlib.Path) -> datetime.datetime:
24
+ mtime_str = path.stem.replace("_rig", "").split("_")[-1]
25
+ return datetime.datetime.strptime(mtime_str, TIMESTAMP_FORMAT)
26
+
27
+
28
+ def get_item(
29
+ storage_directory: pathlib.Path,
30
+ timestamp: datetime.datetime,
31
+ *_tags: str,
32
+ ) -> pathlib.Path | None:
33
+ """Gets latest item before or equal to timestamp."""
34
+ search_pattern = _generate_item_filename(*_tags, "*")
35
+ logger.info("Search pattern: %s" % search_pattern)
36
+ items = list(storage_directory.glob(search_pattern))
37
+ if not items:
38
+ logger.debug("No item found for tags: %s" % json.dumps(_tags))
39
+ return None
40
+
41
+ sorted_items = sorted(items, key=_item_path_sorter)
42
+ logger.debug("Fetched items: %s" % sorted_items)
43
+ logger.debug([_item_path_sorter(item) for item in sorted_items])
44
+ filtered = list(
45
+ filter(
46
+ lambda item: _item_path_sorter(item) <= timestamp,
47
+ sorted_items,
48
+ )
49
+ )
50
+ logger.debug("Filtered items: %s" % filtered)
51
+ if not filtered:
52
+ return None
53
+ return filtered[-1]
54
+
55
+
56
+ def update_item(
57
+ storage_directory: pathlib.Path,
58
+ filepath: pathlib.Path,
59
+ timestamp: datetime.datetime,
60
+ *_tags: str,
61
+ ) -> pathlib.Path:
62
+ """
63
+ Notes
64
+ -----
65
+ - Also used to initialize a new base rig in local storage.
66
+ - If a rig with the same name doest not exist, a new rig will be created.
67
+ """
68
+ filename = _generate_item_filename(
69
+ *_tags,
70
+ timestamp.strftime(TIMESTAMP_FORMAT),
71
+ )
72
+
73
+ return pathlib.Path(
74
+ shutil.copy2(
75
+ filepath,
76
+ storage_directory / filename,
77
+ )
78
+ )
@@ -1,4 +1,3 @@
1
-
2
1
  import datetime
3
2
  import logging
4
3
  import pathlib
@@ -153,4 +152,4 @@ def update_rig(
153
152
  else:
154
153
  update_rig_modification_date(build_source, datetime.date.today())
155
154
 
156
- return pathlib.Path(shutil.copy2(build_source, output_path))
155
+ return pathlib.Path(shutil.copy2(build_source, output_path))
@@ -148,4 +148,4 @@ def save_aind_model(
148
148
  # """Retrofitted rigs are behavior box rigs that have a speaker attached and
149
149
  # have a different solenoid.
150
150
  # """
151
- # return not rig_name.startswith("G")
151
+ # return not rig_name.startswith("G")