-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rob
committed
Jul 1, 2023
1 parent
a61516b
commit e006e80
Showing
9 changed files
with
300 additions
and
57 deletions.
There are no files selected for viewing
This file contains 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 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,47 @@ | ||
from syscore.constants import arg_not_supplied | ||
|
||
from sysdata.production.temporary_override import temporaryOverrideData | ||
from sysdata.mongodb.mongo_override import from_dict_to_override, from_override_to_dict | ||
from sysobjects.production.override import Override | ||
from sysdata.mongodb.mongo_generic import mongoDataWithSingleKey | ||
from syslogging.logger import get_logger | ||
|
||
TEMPORARY_OVERRIDE_COLLECTION = "temporary_override_collection" | ||
KEY = "instrument_code" | ||
|
||
|
||
class mongoTemporaryOverrideData(temporaryOverrideData): | ||
def __init__( | ||
self, mongo_db=arg_not_supplied, log=get_logger("mongoTemporaryOverrideData") | ||
): | ||
|
||
super().__init__(log=log) | ||
self._mongo_data = mongoDataWithSingleKey( | ||
TEMPORARY_OVERRIDE_COLLECTION, KEY, mongo_db=mongo_db | ||
) | ||
|
||
def __repr__(self): | ||
return "mongoTemporaryOverrideData %s" % str(self.mongo_data) | ||
|
||
@property | ||
def mongo_data(self): | ||
return self._mongo_data | ||
|
||
def get_stored_override_for_instrument(self, instrument_code: str) -> Override: | ||
override_as_dict = self.mongo_data.get_result_dict_for_key(instrument_code) | ||
|
||
return from_dict_to_override(override_as_dict) | ||
|
||
def _add_stored_override_without_checking( | ||
self, instrument_code: str, override_for_instrument: Override | ||
): | ||
override_as_dict = from_override_to_dict(override_for_instrument) | ||
self.mongo_data.add_data( | ||
key=instrument_code, data_dict=override_as_dict, allow_overwrite=True | ||
) | ||
|
||
def _delete_stored_override_without_checking(self, instrument_code: str): | ||
self.mongo_data.delete_data_without_any_warning(instrument_code) | ||
|
||
def does_instrument_have_override_stored(self, instrument_code) -> bool: | ||
return self.mongo_data.key_is_in_data(instrument_code) |
This file contains 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 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,49 @@ | ||
from sysdata.base_data import baseData | ||
|
||
from sysobjects.production.override import Override | ||
from syslogging.logger import get_logger | ||
|
||
|
||
class temporaryOverrideData(baseData): | ||
""" | ||
Temporary close is a way of temporarily setting position limits to | ||
zero | ||
We use this table to store the old position limits | ||
""" | ||
|
||
def __init__(self, log=get_logger("temporaryOverrideData")): | ||
super().__init__(log=log) | ||
|
||
def add_stored_override( | ||
self, instrument_code: str, override_for_instrument: Override | ||
): | ||
if self.does_instrument_have_override_stored(instrument_code): | ||
raise Exception( | ||
"Need to clear_stored_override_for_instrument before adding a new one for %s" | ||
% instrument_code | ||
) | ||
|
||
self._add_stored_override_without_checking( | ||
instrument_code=instrument_code, | ||
override_for_instrument=override_for_instrument, | ||
) | ||
|
||
def get_stored_override_for_instrument(self, instrument_code: str) -> Override: | ||
raise NotImplementedError("Need to use inheriting class") | ||
|
||
def clear_stored_override_for_instrument(self, instrument_code: str): | ||
if self.does_instrument_have_override_stored(instrument_code): | ||
self._delete_stored_override_without_checking(instrument_code) | ||
|
||
def _add_stored_override_without_checking( | ||
self, instrument_code: str, override_for_instrument: Override | ||
): | ||
raise NotImplementedError("Need to use inheriting class") | ||
|
||
def does_instrument_have_override_stored(self, instrument_code) -> bool: | ||
raise NotImplementedError("Need to use inheriting class") | ||
|
||
def _delete_stored_override_without_checking(self, instrument_code: str): | ||
raise NotImplementedError("Need to use inheriting class") |
This file contains 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 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 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
Oops, something went wrong.