ptr-editor 0.4.0__tar.gz → 0.4.2__tar.gz

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.
Files changed (155) hide show
  1. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/PKG-INFO +1 -1
  2. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/pyproject.toml +1 -1
  3. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/xml/converter.py +5 -2
  4. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/xml/lxml_adapter.py +27 -3
  5. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/apl/elements.py +9 -2
  6. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/itl/elements.py +5 -1
  7. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/core/ptr_element.py +1 -1
  8. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/timeline.py +29 -1
  9. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_solver/cached_solver.py +16 -2
  10. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_solver/ptr_solver.py +54 -31
  11. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_solver/solvable_mixin.py +13 -2
  12. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/plot.py +15 -2
  13. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/.gitignore +0 -0
  14. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/LICENSE +0 -0
  15. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/README.md +0 -0
  16. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/README.md +0 -0
  17. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/__init__.py +0 -0
  18. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/__init__.py +0 -0
  19. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/base_element.py +0 -0
  20. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/converter_factory.py +0 -0
  21. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/decorators.py +0 -0
  22. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/decorators_utils.py +0 -0
  23. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/field_transformer.py +0 -0
  24. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/fields.py +0 -0
  25. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/inspect.py +0 -0
  26. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/protocols.py +0 -0
  27. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/sentinels.py +0 -0
  28. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/type_utils.py +0 -0
  29. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/core/validator_factory.py +0 -0
  30. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/elements_registry.py +0 -0
  31. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/formatting.py +0 -0
  32. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/globals.py +0 -0
  33. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/pandas.py +0 -0
  34. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/resolution/__init__.py +0 -0
  35. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/resolution/registry.py +0 -0
  36. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/resolution/strategies.py +0 -0
  37. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/xml/__init__.py +0 -0
  38. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/xml/converters.py +0 -0
  39. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/xml/custom_disambiguator.py +0 -0
  40. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/xml/io.py +0 -0
  41. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/attrs_xml/xml/utils.py +0 -0
  42. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/__init__.py +0 -0
  43. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/apl/__init__.py +0 -0
  44. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/apl/jsoc-apl-schema.json +0 -0
  45. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/base.py +0 -0
  46. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/diffing.py +0 -0
  47. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/itl/__init__.py +0 -0
  48. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/itl/jsoc-itl-schema.json +0 -0
  49. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/opl/__init__.py +0 -0
  50. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/opl/csv.py +0 -0
  51. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/opl/elements.py +0 -0
  52. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/opl/jsoc-opl-schema.json +0 -0
  53. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/schema.py +0 -0
  54. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_jsoc/utils.py +0 -0
  55. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/juice_opl/__init__.py +0 -0
  56. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_cli/README.md +0 -0
  57. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_cli/__init__.py +0 -0
  58. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_cli/commands/__init__.py +0 -0
  59. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_cli/commands/validate.py +0 -0
  60. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_cli/commands/version.py +0 -0
  61. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_cli/main.py +0 -0
  62. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_compare/__init__.py +0 -0
  63. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/__init__.py +0 -0
  64. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/accessors/__init__.py +0 -0
  65. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/accessors/accessor.py +0 -0
  66. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/accessors/attrs_dict_accessor.py +0 -0
  67. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/agm_config/__init__.py +0 -0
  68. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/agm_config/agm_config.py +0 -0
  69. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/agm_config/agm_utils.py +0 -0
  70. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/agm_config/html.py +0 -0
  71. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/agm_validator/__init__.py +0 -0
  72. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/agm_validator/agm_config_validator.py +0 -0
  73. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/context/README.md +0 -0
  74. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/context/__init__.py +0 -0
  75. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/context/defaults.py +0 -0
  76. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/context/presets.py +0 -0
  77. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/context/service_config.py +0 -0
  78. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/context/services.py +0 -0
  79. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/core/__init__.py +0 -0
  80. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/core/codenames_gen.py +0 -0
  81. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/core/logging.py +0 -0
  82. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/core/tree_utils.py +0 -0
  83. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/data/__init__.py +0 -0
  84. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/data/snippets.txt +0 -0
  85. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/diffing/__init__.py +0 -0
  86. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/diffing/diff_report.py +0 -0
  87. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/diffing/matcher.py +0 -0
  88. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/diffing/text_diff_result.py +0 -0
  89. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/diffing/timeline_differ_simple.py +0 -0
  90. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/diffing/visualize.py +0 -0
  91. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/__init__.py +0 -0
  92. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/additional_elements.py +0 -0
  93. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/agm_config.py +0 -0
  94. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/array.py +0 -0
  95. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/attitude.py +0 -0
  96. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/blocks.py +0 -0
  97. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/directions.py +0 -0
  98. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/doc.py +0 -0
  99. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/metadata.py +0 -0
  100. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/offset.py +0 -0
  101. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/phase_angle.py +0 -0
  102. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/ref_typed_mixin.py +0 -0
  103. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/surface.py +0 -0
  104. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/units.py +0 -0
  105. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements/values.py +0 -0
  106. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/elements_extractor/__init__.py +0 -0
  107. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/extra/__init__.py +0 -0
  108. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/extra/add_block_comments.py +0 -0
  109. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/factory/__init__.py +0 -0
  110. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/factory/attitudes.py +0 -0
  111. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/factory/blocks.py +0 -0
  112. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/generators/__init__.py +0 -0
  113. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/generators/base.py +0 -0
  114. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/generators/generators.py +0 -0
  115. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/generators/processor.py +0 -0
  116. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/html.py +0 -0
  117. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/io/__init__.py +0 -0
  118. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/io/ptr_converter_setup.py +0 -0
  119. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/io/simplified_converter.py +0 -0
  120. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/io/simplified_converter2.py +0 -0
  121. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/io/xml_formatting.py +0 -0
  122. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/py.typed +0 -0
  123. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/services/__init__.py +0 -0
  124. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/services/quick_access.py +0 -0
  125. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/services/resolution_strategies.py +0 -0
  126. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/spice_accessors/__init__.py +0 -0
  127. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/spice_accessors/directions.py +0 -0
  128. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/spice_accessors/eval_directions.py +0 -0
  129. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/templates/__init__.py +0 -0
  130. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/templates/html.py +0 -0
  131. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/templates/register.py +0 -0
  132. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/templates/template.py +0 -0
  133. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/README.md +0 -0
  134. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/__init__.py +0 -0
  135. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/combinators.py +0 -0
  136. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/html.py +0 -0
  137. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/ptr_validators.py +0 -0
  138. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/result.py +0 -0
  139. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/ruleset_registry.py +0 -0
  140. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/runner.py +0 -0
  141. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/validation/validator.py +0 -0
  142. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/versioned_file_manager/__init__.py +0 -0
  143. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/versioned_file_manager/file_info.py +0 -0
  144. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/versioned_file_manager/html.py +0 -0
  145. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_editor/versioned_file_manager/manager.py +0 -0
  146. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/ptr_solver/__init__.py +0 -0
  147. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/__init__.py +0 -0
  148. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/config.py +0 -0
  149. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/interface.py +0 -0
  150. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/merging.py +0 -0
  151. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/opl.py +0 -0
  152. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/ops.py +0 -0
  153. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/segment_mixin.py +0 -0
  154. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/segments_collection_mixin.py +0 -0
  155. {ptr_editor-0.4.0 → ptr_editor-0.4.2}/src/time_segments/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ptr-editor
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Utilities to edit PTR files.
5
5
  Project-URL: documentation, https://luca-penasa.github.io/ptr-editor
6
6
  Project-URL: homepage, https://luca-penasa.github.io/ptr-editor
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ptr-editor"
3
- version = "0.4.0"
3
+ version = "0.4.2"
4
4
  description = "Utilities to edit PTR files."
5
5
  authors = [
6
6
  { name = "Luca Penasa", email = "luca.penasa@inaf.it" },
@@ -553,9 +553,12 @@ def make_structure_hook_factory(converter: Converter):
553
553
  if forbidden_errors:
554
554
  exc = forbidden_errors[0]
555
555
  log.warning(
556
- f"Unexpected keys encountered during structuring. Extra keys: {exc.extra_fields}. Those won't be preserved when saving the timeline",
556
+ f"Unexpected keys encountered during structuring of {cls.__name__!r}."
557
+ f" Extra keys: {exc.extra_fields}. Those won't be preserved when saving the timeline."
558
+ f" This is typically caused by a malformed XML file where a tag-mismatch cascade"
559
+ f" re-parents child elements onto the wrong ancestor."
557
560
  )
558
- log.debug(f"Original value: {val}")
561
+ log.debug(f"Original value for {cls.__name__}: {val}")
559
562
  log.exception(eg)
560
563
  # remove the extra keys and retry
561
564
  cleaned_val = {
@@ -152,12 +152,36 @@ def parse_xml(xml: str, preprocess: bool = True) -> dict[str, Any]:
152
152
 
153
153
  if parser.error_log:
154
154
  log.warning(
155
- f"XML parsing encountered {len(parser.error_log)} recoverable errors"
155
+ f"XML parsing encountered {len(parser.error_log)} recoverable error(s) "
156
+ f"in {'file: ' + xml if os.path.isfile(xml) else 'inline XML'}. "
157
+ f"The file is malformed and lxml repaired it automatically, but data may be lost."
156
158
  )
157
159
  for error in parser.error_log:
158
- log.debug(
159
- f" Line {error.line}, Column {error.column}: {error.message}"
160
+ log.warning(
161
+ f" XML recovery: line {error.line}, col {error.column}: {error.message}"
160
162
  )
163
+ # Warn about the most dangerous consequence: a tag-mismatch cascade can
164
+ # close <timeline> prematurely, causing blocks after the bad tag to be
165
+ # re-parented to an ancestor element and silently dropped.
166
+ timeline_elems = tree.findall(".//timeline")
167
+ if timeline_elems:
168
+ timeline = timeline_elems[0]
169
+ blocks_in_timeline = len(timeline.findall("block"))
170
+ # Blocks outside timeline that landed on ancestor elements
171
+ orphan_blocks = [
172
+ elem for elem in tree.iter()
173
+ if elem.tag != "timeline" and any(c.tag == "block" for c in elem)
174
+ ]
175
+ if orphan_blocks:
176
+ total_orphans = sum(
177
+ sum(1 for c in elem if c.tag == "block") for elem in orphan_blocks
178
+ )
179
+ log.warning(
180
+ f" XML recovery side-effect: {total_orphans} <block> element(s) "
181
+ f"were re-parented outside <timeline> due to the tag-mismatch cascade. "
182
+ f"Only {blocks_in_timeline} block(s) remain inside <timeline>. "
183
+ f"The orphaned blocks will be dropped when saving."
184
+ )
161
185
 
162
186
  root_dict = _lxml_element_to_dict(tree, force_list_func=is_element_a_list)
163
187
  return {tree.tag: root_dict}
@@ -635,14 +635,21 @@ class ActivityPlan(AplBaseItem, SegmentsCollectionMixin[Activity]):
635
635
 
636
636
 
637
637
  def _format_apl_duration(td: pd.Timedelta) -> str:
638
- """Format a Timedelta as ``ddd.hh:mm:ss[.SSS]`` for the APL duration field.
638
+ """Format a Timedelta as ``[−]ddd.hh:mm:ss[.SSS]`` for the APL duration field.
639
639
 
640
640
  The APL schema pattern for *duration* is:
641
641
  ``^\\d{1,3}\\.\\d{2}:\\d{2}:\\d{2}(\\.\\d{1,3})?$``
642
642
 
643
643
  Unlike the OPL / XML format (which uses a leading sign), APL duration
644
644
  always starts with a three-digit (or fewer) day count followed by a dot.
645
+ Negative durations are represented by negating the Timedelta first so that
646
+ all components are derived from the absolute value, then prepending ``-``.
645
647
  """
648
+ if td.total_seconds() < 0:
649
+ sign = "-"
650
+ td = -td
651
+ else:
652
+ sign = ""
646
653
  total_seconds = int(td.total_seconds())
647
654
  milliseconds = int(td.microseconds // 1000) if td.microseconds else 0
648
655
  days = total_seconds // 86400
@@ -651,7 +658,7 @@ def _format_apl_duration(td: pd.Timedelta) -> str:
651
658
  remainder = remainder % 3600
652
659
  minutes = remainder // 60
653
660
  seconds = remainder % 60
654
- base = f"{days:03d}.{hours:02d}:{minutes:02d}:{seconds:02d}"
661
+ base = f"{sign}{days:03d}.{hours:02d}:{minutes:02d}:{seconds:02d}"
655
662
  if milliseconds:
656
663
  return f"{base}.{milliseconds:03d}"
657
664
  return base
@@ -127,7 +127,11 @@ class RelativeTime(ItlBaseItem):
127
127
  """Get absolute time if calculated."""
128
128
  if self.event_abs_time is not None:
129
129
  return self.event_abs_time + self.delta_time
130
- return None
130
+ msg = (
131
+ "Absolute time not known for this RelativeTime"
132
+ " instance. Cannot compute an abs time."
133
+ )
134
+ raise ValueError(msg)
131
135
 
132
136
  @abs_time.setter
133
137
  def abs_time(self, value: pd.Timestamp | None) -> None:
@@ -273,7 +273,7 @@ class PtrElement(BaseElement):
273
273
 
274
274
  ptr = get_elements_registry()
275
275
 
276
- return ptr.from_xml(xml, disable_defaults=disable_defaults, cls=cls)
276
+ return ptr.from_xml(xml, disable_defaults=disable_defaults)
277
277
 
278
278
  def _repr_html_(self) -> str:
279
279
  """Return syntax-highlighted HTML representation for Jupyter notebooks."""
@@ -1219,7 +1219,35 @@ class Timeline(PtrElement, PtrSolvableMixin, SegmentsCollectionMixin[BLOCKS]):
1219
1219
  # Priority columns are already handled by tabletize_block
1220
1220
  return pd.DataFrame(data).reset_index(drop=True)
1221
1221
 
1222
- def plot(self, hover_cols=["id", "designer", "start", "end"], **kwargs):
1222
+ def plot(self, hover_cols=["id", "designer", "start", "end", 'attitude.target' ], **kwargs):
1223
+ """Plot the timeline as an interactive Gantt chart.
1224
+
1225
+ Defaults to coloring and grouping rows by ``designer``. Height is
1226
+ auto-scaled to the number of unique designers so crowded timelines
1227
+ don't look squashed. Any keyword accepted by
1228
+ :func:`time_segments.plot.plot` or ``plotly.express.timeline`` can be
1229
+ passed to override these defaults.
1230
+
1231
+ Args:
1232
+ hover_cols: Columns shown in the hover tooltip.
1233
+ **kwargs: Forwarded to :func:`time_segments.plot.plot`. Common
1234
+ overrides: ``color``, ``y``, ``height``, ``title``.
1235
+ """
1223
1236
  from time_segments.plot import plot
1224
1237
 
1238
+ tab = self.as_pandas()
1239
+
1240
+ # Default y / color to "attitude.target" — the natural PTR grouping axis.
1241
+ # Fall back to a single "timeline" row when no attitude.target column exists.
1242
+ if "attitude.target" in tab.columns:
1243
+ kwargs.setdefault("color", "attitude.target")
1244
+ if 'designer' in tab.columns:
1245
+ kwargs.setdefault("y", "designer")
1246
+ n_lanes = max(tab["designer"].nunique(), 1)
1247
+ else:
1248
+ n_lanes = 1
1249
+
1250
+ # Auto-scale height: 80 px per lane, 120 px minimum header/padding.
1251
+ kwargs.setdefault("height", max(300, 120 + 40 * n_lanes))
1252
+
1225
1253
  return plot(self, hover_cols=hover_cols, **kwargs)
@@ -1,3 +1,4 @@
1
+ import json
1
2
  import re
2
3
  import xml.etree.ElementTree as ET
3
4
  from collections.abc import Sequence
@@ -14,6 +15,7 @@ from ptr_editor.elements.timeline import Timeline
14
15
 
15
16
  from .ptr_solver import (
16
17
  PtrSolution,
18
+ parse_ptwrapper_log,
17
19
  solve_attitude,
18
20
  )
19
21
 
@@ -147,7 +149,7 @@ class CachedPtrSolver:
147
149
  def unique_cache_path(self):
148
150
  return self.cache_folder / self.make_unique_cache_key()
149
151
 
150
- def solve(self) -> PtrSolution:
152
+ def solve(self, *, min_log_level: str = "ERROR") -> PtrSolution:
151
153
  log.debug(f"Solving ptr. using cache dir {self.cache_folder}")
152
154
 
153
155
  folder = self.unique_cache_path()
@@ -161,10 +163,22 @@ class CachedPtrSolver:
161
163
  f"Ck already there (at {ck_name.absolute()}). "
162
164
  "Not recomputing as cache is enabled.",
163
165
  )
164
- return PtrSolution(ck_file=ck_name.absolute())
166
+ log_entries: list = []
167
+ log_path = folder / "result_log.json"
168
+ if log_path.exists():
169
+ with log_path.open() as f:
170
+ log_entries = json.load(f)
171
+ parse_ptwrapper_log(log_entries, min_log_level=min_log_level) # re-emit log messages
172
+ else:
173
+ log.debug(
174
+ "No cached log file found at %s; returning empty log",
175
+ log_path,
176
+ )
177
+ return PtrSolution(ck_file=ck_name.absolute(), log=log_entries)
165
178
  return solve_attitude(
166
179
  self.ptr_text,
167
180
  out_folder=folder,
168
181
  ck_name="result.ck",
169
182
  metakernel=self.metakernel,
183
+ min_log_level=min_log_level,
170
184
  )
@@ -35,30 +35,13 @@ def _stream_reader(stream, stream_name: str, callback):
35
35
 
36
36
 
37
37
  def _log_ptwrapper_output(stream_name: str, line: str):
38
- """Log ptwrapper output to loguru with appropriate level.
38
+ """Log raw ptwrapper process output at DEBUG level.
39
39
 
40
- Args:
41
- stream_name: "stdout" or "stderr"
42
- line: The line to log
40
+ Structured diagnostics are emitted via :func:`parse_ptwrapper_log` once
41
+ the process finishes, respecting ``min_log_level``. Keeping the live
42
+ stream at DEBUG avoids duplicate / level-violating messages.
43
43
  """
44
- # Parse common ptwrapper patterns and log appropriately
45
- line_lower = line.lower()
46
-
47
- # Check for error patterns
48
- if "error" in line_lower or "failed" in line_lower or stream_name == "stderr":
49
- log.error(f"[ptwrapper:{stream_name}] {line}")
50
- # Check for warning patterns
51
- elif "warning" in line_lower or "warn" in line_lower:
52
- log.warning(f"[ptwrapper:{stream_name}] {line}")
53
- # Check for info patterns
54
- elif any(
55
- keyword in line_lower
56
- for keyword in ["info", "processing", "generating", "writing"]
57
- ):
58
- log.info(f"[ptwrapper:{stream_name}] {line}")
59
- # Everything else as debug
60
- else:
61
- log.debug(f"[ptwrapper:{stream_name}] {line}")
44
+ log.debug(f"[ptwrapper:{stream_name}] {line}")
62
45
 
63
46
 
64
47
  @define
@@ -83,9 +66,24 @@ class PtrSolution:
83
66
  """
84
67
 
85
68
  ck_file: Path = field(converter=Path)
86
- errors: list = field(factory=list)
69
+ log: list[dict] = field(factory=list)
87
70
  _is_loaded: bool = field(init=False, default=False)
88
71
 
72
+ @property
73
+ def errors(self) -> list[dict]:
74
+ """Log entries with severity ERROR."""
75
+ return [e for e in self.log if e.get("severity") == "ERROR"]
76
+
77
+ @property
78
+ def warnings(self) -> list[dict]:
79
+ """Log entries with severity WARNING."""
80
+ return [e for e in self.log if e.get("severity") == "WARNING"]
81
+
82
+ @property
83
+ def info(self) -> list[dict]:
84
+ """Log entries with severity INFO."""
85
+ return [e for e in self.log if e.get("severity") == "INFO"]
86
+
89
87
  def __fspath__(self) -> str:
90
88
  return str(self.ck_file)
91
89
 
@@ -136,22 +134,43 @@ class PtrSolution:
136
134
  self.unload_ck()
137
135
 
138
136
 
137
+ # Mapping from ptwrapper severity strings to loguru level names
138
+ _PTWRAPPER_TO_LOGURU: dict[str, str] = {
139
+ "ERROR": "ERROR",
140
+ "WARNING": "WARNING",
141
+ "INFO": "INFO",
142
+ }
143
+
144
+
139
145
  # module, severity, text, time
140
146
  def parse_ptwrapper_log(
141
147
  logs: list[dict],
142
148
  raise_if_error=False,
149
+ min_log_level: str = "ERROR",
143
150
  ) -> tuple[list[dict], list[dict], list[dict]]:
151
+ """Parse and re-emit ptwrapper log entries via loguru.
152
+
153
+ Args:
154
+ logs: Raw log entries from the ptwrapper JSON log.
155
+ raise_if_error: Raise ``ValueError`` on the first ERROR entry.
156
+ min_log_level: Minimum loguru level to emit. Entries whose severity
157
+ maps to a loguru level *below* this threshold are silenced.
158
+ Defaults to ``"ERROR"`` so only errors are shown.
159
+ """
160
+ min_no = log.level(min_log_level).no
144
161
  errors = []
145
162
  warnings = []
146
163
  for item in logs:
147
- if item.get("severity") == "ERROR":
148
- log.error(f"{item['module']} - {item['text']} @{item['time']}")
164
+ severity = item.get("severity", "INFO")
165
+ loguru_level = _PTWRAPPER_TO_LOGURU.get(severity, "DEBUG")
166
+ if log.level(loguru_level).no >= min_no:
167
+ log.log(loguru_level, f"{item['module']} - {item['text']} @{item['time']}")
168
+ if severity == "ERROR":
149
169
  errors.append(item)
150
170
  if raise_if_error:
151
171
  msg = "Error in log!"
152
172
  raise ValueError(msg)
153
- elif item.get("severity") == "WARNING":
154
- log.warning(f"{item['module']} - {item['text']} @{item['time']}")
173
+ elif severity == "WARNING":
155
174
  warnings.append(item)
156
175
 
157
176
  return errors, warnings, logs
@@ -163,9 +182,9 @@ def solve_attitude_via_ptwrapper(
163
182
  out_folder: str | Path = Path("./"),
164
183
  ck_name: str = "result.ck",
165
184
  dt: float = 5,
166
-
167
185
  raise_on_missing_ck=True,
168
186
  cleanup=True,
187
+ min_log_level: str = "ERROR",
169
188
  ) -> PtrSolution:
170
189
  if not isinstance(metakernel, TourConfig) and not Path(metakernel).exists():
171
190
  msg = "No MK file at {mk}"
@@ -197,7 +216,7 @@ def solve_attitude_via_ptwrapper(
197
216
  metakernel = mkname
198
217
 
199
218
  # -pw \ no using -pw for now
200
- command = f"ptwrapper -m {metakernel} -p {ptr_file} -t {dt} -w {dir}"
219
+ command = f"ptwrapper -m {metakernel} -p {ptr_file} -t {dt} -w {dir} -pw"
201
220
 
202
221
  log.debug(f"Executing {command}")
203
222
 
@@ -276,7 +295,7 @@ def solve_attitude_via_ptwrapper(
276
295
  with Path(in_log).open() as logf:
277
296
  log_json = json.load(logf)
278
297
 
279
- errors, _warnings, _logs = parse_ptwrapper_log(log_json)
298
+ parse_ptwrapper_log(log_json, min_log_level=min_log_level)
280
299
 
281
300
  fname = Path(ck_name).with_suffix("")
282
301
 
@@ -293,7 +312,7 @@ def solve_attitude_via_ptwrapper(
293
312
  except Exception as e:
294
313
  log.warning(f"Error moving power file: {e}. Maybe ptwrapper was run without -pw")
295
314
 
296
- return PtrSolution(ck_file=out_ck, errors=errors)
315
+ return PtrSolution(ck_file=out_ck, log=log_json)
297
316
 
298
317
  # return in_ck, in_ptr, in_log, [errors, warnings, logs]
299
318
 
@@ -306,6 +325,7 @@ def solve_attitude(
306
325
  dt: int = 5,
307
326
  raise_on_missing_ck: bool = True,
308
327
  cleanup: bool = True,
328
+ min_log_level: str = "ERROR",
309
329
  ) -> PtrSolution:
310
330
  """Solve attitude using ptwrapper.
311
331
 
@@ -317,6 +337,8 @@ def solve_attitude(
317
337
  dt: Time step for attitude computation in seconds
318
338
  raise_on_missing_ck: Whether to raise an error if CK file is not generated
319
339
  cleanup: Whether to cleanup temporary files after processing
340
+ min_log_level: Minimum loguru level to emit from the ptwrapper log.
341
+ Defaults to ``"ERROR"``.
320
342
 
321
343
  Returns:
322
344
  PtrSolution containing the path to the CK file and any errors
@@ -332,4 +354,5 @@ def solve_attitude(
332
354
  dt=dt,
333
355
  raise_on_missing_ck=raise_on_missing_ck,
334
356
  cleanup=cleanup,
357
+ min_log_level=min_log_level,
335
358
  )
@@ -55,11 +55,22 @@ class PtrSolvableMixin:
55
55
  self._currently_loaded_ck = None
56
56
 
57
57
  def solve(
58
- self, mk="5_1_150lb_23_1_a3", *, use_cache: bool = True
58
+ self,
59
+ mk="5_1_150lb_23_1_a3",
60
+ *,
61
+ use_cache: bool = True,
62
+ min_log_level: str = "ERROR",
59
63
  ) -> PtrSolution:
60
64
  """
61
65
  Solve the object using the PTR solver.
62
66
 
67
+ Args:
68
+ mk: Metakernel identifier.
69
+ use_cache: Whether to use the solver cache.
70
+ min_log_level: Minimum loguru level of ptwrapper log messages to
71
+ emit. Defaults to ``"ERROR"``; pass ``"WARNING"`` or
72
+ ``"INFO"`` for more verbose output.
73
+
63
74
  Returns:
64
75
  The solver result containing solved pointing information.
65
76
 
@@ -80,7 +91,7 @@ class PtrSolvableMixin:
80
91
  solver = CachedPtrSolver(
81
92
  self._solvable_ptr_(), use_cache=use_cache, metakernel=mk
82
93
  )
83
- return solver.solve()
94
+ return solver.solve(min_log_level=min_log_level)
84
95
 
85
96
  def generate(self):
86
97
  """
@@ -126,6 +126,15 @@ def plot(
126
126
  time_keys = {"x_start", "x_end"}
127
127
  time_config.update({k: kwargs.pop(k) for k in time_keys if k in kwargs})
128
128
 
129
+ # Ensure start/end columns are proper datetimes so plotly can parse them
130
+ # regardless of sub-second precision or timezone suffixes.
131
+ for col in (time_config["x_start"], time_config["x_end"]):
132
+ if col in tab.columns and not pd.api.types.is_datetime64_any_dtype(tab[col]):
133
+ parsed = pd.to_datetime(tab[col], format="ISO8601")
134
+ if parsed.dt.tz is not None:
135
+ parsed = parsed.dt.tz_convert(None)
136
+ tab[col] = parsed
137
+
129
138
  # Create the timeline plot without any hover_data / custom_data
130
139
  fig = px.timeline(tab, **time_config, **kwargs)
131
140
 
@@ -133,8 +142,12 @@ def plot(
133
142
  # px.timeline splits data by the color column — match rows accordingly.
134
143
  color_col = kwargs.get("color", "name")
135
144
  for trace in fig.data:
136
- mask = tab[color_col] == trace.name
137
- trace.hovertext = tab.loc[mask, "_hover_text"].values
145
+ if color_col in tab.columns:
146
+ mask = tab[color_col] == trace.name
147
+ hover_texts = tab.loc[mask, "_hover_text"].values
148
+ else:
149
+ hover_texts = tab["_hover_text"].values
150
+ trace.hovertext = hover_texts
138
151
  trace.hovertemplate = "%{hovertext}<extra></extra>"
139
152
 
140
153
  # Compact hover styling
File without changes
File without changes
File without changes