-
Notifications
You must be signed in to change notification settings - Fork 1
Localization #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Localization #31
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
63c47ee
Migrate to uv
joshuaRiefman b0635c6
Add initial localization files
joshuaRiefman 16fafe1
Finish language localization
joshuaRiefman 5e7cf9b
Add temporal localization
joshuaRiefman ddccf6c
Add spatial localization
joshuaRiefman 8b09c90
Add test skipping
joshuaRiefman 26f57d7
Ruff Lint
joshuaRiefman cf085a1
Fix import issue
joshuaRiefman 4f6b5b1
Fix import issue (1)
joshuaRiefman 3b2c2f4
Typo :(
joshuaRiefman 532dbc4
Add ability to inject custom localization
joshuaRiefman 09b7441
Add frequency to localization
joshuaRiefman be0ce23
Fix documentation to reflect correct usage
joshuaRiefman 9454552
Merge branch 'main' into localization
joshuaRiefman a6a9762
Fix TimeSeries merge
joshuaRiefman 95f25dc
Remove old doc now
joshuaRiefman e2d3e4b
Update with SunbeamDB
joshuaRiefman 9c1cfa9
Fixes from PR review
joshuaRiefman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| static_data/**/*.csv | ||
| static_data/**/*.csv | ||
| */**/*.toml |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from .language_localization import LanguageLocalization as _LanguageLocalization, CanonicalName | ||
| from .temporal_localization import TemporalLocalization as _TemporalLocalization | ||
| from .spatial_localization import SpatialLocalization as _SpatialLocalization | ||
| from .versioned_table import VersionedTable | ||
| from .localization import Localization | ||
| import pathlib | ||
|
|
||
|
|
||
| INFLUXDB_LANGUAGE_LOCALIZATION_TABLE_PATH = pathlib.Path(__file__).parent / "influxdb_language_localization.toml" | ||
| if not INFLUXDB_LANGUAGE_LOCALIZATION_TABLE_PATH.exists(): | ||
| raise FileNotFoundError(f"Localization file {INFLUXDB_LANGUAGE_LOCALIZATION_TABLE_PATH} not found! " | ||
| f"A localization file is required to use this module") | ||
| else: | ||
| InfluxDBLanguageLocalization = _LanguageLocalization(INFLUXDB_LANGUAGE_LOCALIZATION_TABLE_PATH) | ||
|
|
||
| SUNBEAMDB_LANGUAGE_LOCALIZATION_TABLE_PATH = pathlib.Path(__file__).parent / "sunbeamdb_language_localization.toml" | ||
| if not SUNBEAMDB_LANGUAGE_LOCALIZATION_TABLE_PATH.exists(): | ||
| raise FileNotFoundError(f"Localization file {SUNBEAMDB_LANGUAGE_LOCALIZATION_TABLE_PATH} not found! " | ||
| f"A localization file is required to use this module") | ||
| else: | ||
| SunbeamDBLanguageLocalization = _LanguageLocalization(SUNBEAMDB_LANGUAGE_LOCALIZATION_TABLE_PATH) | ||
|
|
||
|
|
||
| TEMPORAL_LOCALIZATION_TABLE_PATH = pathlib.Path(__file__).parent / "temporal_localization.toml" | ||
| if not TEMPORAL_LOCALIZATION_TABLE_PATH.exists(): | ||
| raise FileNotFoundError(f"Localization file {TEMPORAL_LOCALIZATION_TABLE_PATH} not found! " | ||
| f"A localization file is required to use this module") | ||
| else: | ||
| TemporalLocalization = _TemporalLocalization(TEMPORAL_LOCALIZATION_TABLE_PATH) | ||
|
|
||
|
|
||
| SPATIAL_LOCALIZATION_TABLE_PATH = pathlib.Path(__file__).parent / "spatial_localization.toml" | ||
| if not SPATIAL_LOCALIZATION_TABLE_PATH.exists(): | ||
| raise FileNotFoundError(f"Localization file {SPATIAL_LOCALIZATION_TABLE_PATH} not found! " | ||
| f"A localization file is required to use this module") | ||
| else: | ||
| SpatialLocalization = _SpatialLocalization(SPATIAL_LOCALIZATION_TABLE_PATH) | ||
|
|
||
|
|
||
| __all__ = [ | ||
| "VersionedTable", | ||
| "Localization", | ||
| "InfluxDBLanguageLocalization", | ||
| "SunbeamDBLanguageLocalization", | ||
| "TemporalLocalization", | ||
| "SpatialLocalization", | ||
| "CanonicalName" | ||
| ] | ||
81 changes: 81 additions & 0 deletions
81
data_tools/localization/influxdb_language_localization.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| [2024-01-01] # 2024-07-12 – 2024-07-20 | ||
| VehicleSpeed = ["VehicleVelocity", "MDI", "m/s", 5] | ||
| PackVoltage = ["TotalPackVoltage", "BMS", "V", 1] | ||
| PackCurrent = ["PackCurrent", "ECU", "A", 5] | ||
| MotorCurrent = ["BatteryCurrent", "MC", "A", 5] | ||
| AcceleratorPosition = ["AcceleratorPosition", "MC", "", 10] | ||
| MinimumModuleVoltage = ["VoltageofLeast", "BMS","V", 1] | ||
| MaximumModuleVoltage = ["VoltageofHighest", "BMS", "V", 1] | ||
| BrakePressed = ["MechBrakePressed", "MCB", "", 10] | ||
| MotorCurrentDirection = ["BatteryCurrentDirection", "MC", "", 5] | ||
|
|
||
| MPPTInputVoltageA = ["VoltSensor1", "AMB", "V", 4] | ||
| MPPTInputVoltageB = ["VoltSensor2", "AMB", "V", 4] | ||
| MPPTInputCurrentA = ["CurrentSensor1", "AMB", "A", 4] | ||
| MPPTInputCurrentB = ["CurrentSensor2", "AMB", "A", 4] | ||
|
|
||
|
|
||
| [2025-01-01] # 2025-04-01 – 2025-07-23 | ||
| VehicleSpeed = ["MotorRotatingSpeed", "MC", "km/h", 10] | ||
| PackVoltage = ["TotalPackVoltage", "BMS", "V", 10] | ||
| PackCurrent = ["PackCurrent", "ECU", "A", 5] | ||
| MotorCurrent = ["BatteryCurrent", "MC", "A", 10] | ||
| AcceleratorPosition = ["AcceleratorPosition", "MC", "", 10] | ||
| MinimumModuleVoltage = ["VoltageofLeast", "BMS","V", 10] | ||
| MaximumModuleVoltage = ["VoltageofHighest", "BMS", "V", 10] | ||
| BrakePressed = ["BrakePressed", "DRD", "", 10] | ||
| MotorCurrentDirection = ["BatteryCurrentDirection", "MC", "", 10] | ||
|
|
||
| MPPTOutputVoltageA = ["OutputVoltageA", "MPPT", "V", 3] | ||
| MPPTOutputVoltageB = ["OutputVoltageB", "MPPT", "V", 3] | ||
| MPPTOutputVoltageC = ["OutputVoltageC", "MPPT", "V", 3] | ||
| MPPTOutputCurrentA = ["OutputCurrentA", "MPPT", "A", 3] | ||
| MPPTOutputCurrentB = ["OutputCurrentB", "MPPT", "A", 3] | ||
| MPPTOutputCurrentC = ["OutputCurrentC", "MPPT", "A", 3] | ||
|
|
||
| MPPTInputVoltageA = ["InputVoltageA", "MPPT", "V", 3] | ||
| MPPTInputVoltageB = ["InputVoltageB", "MPPT", "V", 3] | ||
| MPPTInputVoltageC = ["InputVoltageC", "MPPT", "V", 3] | ||
| MPPTInputCurrentA = ["InputCurrentA", "MPPT", "A", 3] | ||
| MPPTInputCurrentB = ["InputCurrentB", "MPPT", "A", 3] | ||
| MPPTInputCurrentC = ["InputCurrentC", "MPPT", "A", 3] | ||
|
|
||
| GPSLatitude = ["GPSLatitude", "TEL", "", 3] | ||
| GPSLongitude = ["GPSLongitude", "TEL", "", 3] | ||
|
|
||
| Acceleration_X = ["Acceleration_X", "TEL", "", 10] | ||
| Acceleration_Y = ["Acceleration_Y", "TEL", "", 10] | ||
| Acceleration_Z = ["Acceleration_Z", "TEL", "", 10] | ||
|
|
||
|
|
||
| [2026-01-01] # 2026-01-20 – | ||
| VehicleSpeed = ["MotorRotatingSpeed", "MC", "km/h", 10] | ||
| PackVoltage = ["TotalPackVoltage", "BMS", "V", 10] | ||
| PackCurrent = ["PackCurrent", "ECU", "A", 5] | ||
| MotorCurrent = ["BatteryCurrent", "MC", "A", 10] | ||
| AcceleratorPosition = ["AcceleratorPosition", "MC", "", 10] | ||
| MinimumModuleVoltage = ["VoltageofLeast", "BMS", "V", 10] | ||
| MaximumModuleVoltage = ["VoltageofHighest", "BMS", "V", 10] | ||
| BrakePressed = ["BrakePressed", "DRD", "", 10] | ||
| MotorCurrentDirection = ["BatteryCurrentDirection", "MC", "", 10] | ||
|
|
||
| MPPTOutputVoltageA = ["OutputVoltageA", "MPPT", "V", 3] | ||
| MPPTOutputVoltageB = ["OutputVoltageB", "MPPT", "V", 3] | ||
| MPPTOutputVoltageC = ["OutputVoltageC", "MPPT", "V", 3] | ||
| MPPTOutputCurrentA = ["OutputCurrentA", "MPPT", "A", 3] | ||
| MPPTOutputCurrentB = ["OutputCurrentB", "MPPT", "A", 3] | ||
| MPPTOutputCurrentC = ["OutputCurrentC", "MPPT", "A", 3] | ||
|
|
||
| MPPTInputVoltageA = ["InputVoltageA", "MPPT", "V", 3] | ||
| MPPTInputVoltageB = ["InputVoltageB", "MPPT", "V", 3] | ||
| MPPTInputVoltageC = ["InputVoltageC", "MPPT", "V", 3] | ||
| MPPTInputCurrentA = ["InputCurrentA", "MPPT", "A", 3] | ||
| MPPTInputCurrentB = ["InputCurrentB", "MPPT", "A", 3] | ||
| MPPTInputCurrentC = ["InputCurrentC", "MPPT", "A", 3] | ||
|
|
||
| GPSLatitude = ["GPSLatitude", "TEL", "", 4] | ||
| GPSLongitude = ["GPSLongitude", "TEL", "", 4] | ||
|
|
||
| Acceleration_X = ["Acceleration_X", "TEL", "", 10] | ||
| Acceleration_Y = ["Acceleration_Y", "TEL", "", 10] | ||
| Acceleration_Z = ["Acceleration_Z", "TEL", "", 10] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| from data_tools.localization.localization import Localization | ||
| from enum import StrEnum | ||
| from datetime import date | ||
|
|
||
|
|
||
| class LanguageLocalization(Localization): | ||
| def localize(self, canonical_name: str, current_date: date | str) -> tuple[str, str, str, float]: | ||
| """ | ||
| Return the (field, board, units, frequency) | ||
| """ | ||
| name, board, units, frequency = self._localization_table.lookup(canonical_name, current_date) | ||
| return name, board, units, frequency | ||
|
|
||
|
|
||
| class CanonicalName(StrEnum): | ||
| VehicleSpeed = "VehicleSpeed" | ||
| PackVoltage = "PackVoltage" | ||
| PackCurrent = "PackCurrent" | ||
| MotorCurrent = "MotorCurrent" | ||
| AcceleratorPosition = "AcceleratorPosition" | ||
| MinimumModuleVoltage = "MinimumModuleVoltage" | ||
| MaximumModuleVoltage = "MaximumModuleVoltage" | ||
| BrakePressed = "BrakePressed" | ||
| MotorCurrentDirection = "MotorCurrentDirection" | ||
|
|
||
| MPPTOutputVoltageA = "MPPTOutputVoltageA" | ||
| MPPTOutputVoltageB = "MPPTOutputVoltageB" | ||
| MPPTOutputVoltageC = "MPPTOutputVoltageC" | ||
| MPPTOutputCurrentA = "MPPTOutputCurrentA" | ||
| MPPTOutputCurrentB = "MPPTOutputCurrentB" | ||
| MPPTOutputCurrentC = "MPPTOutputCurrentC" | ||
|
|
||
| MPPTInputVoltageA = "MPPTInputVoltageA" | ||
| MPPTInputVoltageB = "MPPTInputVoltageB" | ||
| MPPTInputVoltageC = "MPPTInputVoltageC" | ||
| MPPTInputCurrentA = "MPPTInputCurrentA" | ||
| MPPTInputCurrentB = "MPPTInputCurrentB" | ||
| MPPTInputCurrentC = "MPPTInputCurrentC" | ||
|
|
||
| GPSLatitude = "GPSLatitude" | ||
| GPSLongitude = "GPSLongitude" | ||
|
|
||
| Acceleration_X = "Acceleration_X" | ||
| Acceleration_Y = "Acceleration_Y" | ||
| Acceleration_Z = "Acceleration_Z" | ||
|
|
||
| MotorPower = "MotorPower" | ||
| MotorEfficiency = "MotorEfficiency" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from data_tools.localization.versioned_table import VersionedTable | ||
| from abc import ABC, abstractmethod | ||
| import pathlib | ||
|
|
||
|
|
||
| class Localization(ABC): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice to have a brief docstring describing the purpose of the class. Same goes for the other new classes. |
||
| _instance: "Localization | None" = None | ||
|
|
||
| def __init__(self, localization_table: pathlib.Path): | ||
| self._localization_table = VersionedTable.from_toml_file(str(localization_table.absolute())) | ||
|
|
||
| @abstractmethod | ||
| def localize(self, *args, **kwargs): ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| from data_tools.localization.localization import Localization | ||
| from datetime import datetime | ||
|
|
||
|
|
||
| class SpatialLocalization(Localization): | ||
| def localize(self, query_datetime: datetime) -> tuple[list, str]: | ||
| """ | ||
| Return the timedelta to add to InfluxDB query ranges to account for timezone reporting errors in InfluxDB. | ||
| The same error should be subtracted from returned data ranges to amend them. | ||
| """ | ||
| coords, name = self._localization_table.lookup("position", query_datetime.date()) | ||
|
|
||
| return coords, name |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate the imports neatly ordered by line length