ServerPortfolio
2.0
Python parsers and server
|
Extend class Stock with functions related to the validation and saving after a stock update: most of the post_process functionalities. More...
Public Member Functions | |
def | __init__ |
Constructor. More... | |
def | get_parent |
Return the parent Stock. More... | |
Generic functions to valid a specific action | |
def | post_process_one_action |
Assure the post_processing of a Stock after the parsing of one unique action. More... | |
def | check_new_data |
Check the validity of the last updated values from Stock.dict_stock and generate dict_interactive. More... | |
def | save_new_data |
Final merge (after user/auto-validation) and write to file. More... | |
def | valid_interactive |
User validation of the new data. More... | |
Static Public Member Functions | |
def | check_value |
Generic function to check if new_value can be updated. More... | |
def | is_valid_value |
Guess if the input value is valid. More... | |
Public Attributes | |
dict_interactive | |
Private Attributes | |
_logger | |
_parent_stock | |
Associated to an unique stock. More... | |
_dict_interactive | |
Dictionary of data after check_new_data. More... | |
_tk_manager | |
Store a ManagerTk interface in multi-thread mode. More... | |
Specific functions to deal with XML | |
def | check_new_xml_data |
Check the validity of the new retrieved data stored Stock._dict_stock. More... | |
def | save_new_xml_data |
Final merge (after user/auto validation) and write XML file. More... | |
def | _valid_new_value_xml |
Valid last values retrieved with parsers, try to guess values to be updated. More... | |
Specific functions to deal with CSV data | |
tuple | dict_action_inter = self._valid_new_value_csv( key_action, opt_interactive ) |
def | check_list_csv |
Check the CSV data are not wrong. More... | |
def | gen_part_of_list_csv |
Generate a sub-list of list_csv, starting from the last call until the last_date (included) More... | |
def | _valid_new_value_csv |
Fill dict_interactive in case of list of data (HistPrice action implemented) dict_inter_action stores chronological group of data, with or without errors. More... | |
def | _error_list_csv |
Check for common error in historical price data and return a status and an error code. More... | |
Extend class Stock with functions related to the validation and saving after a stock update: most of the post_process functionalities.
Object is owned by a Stock object, created in Stock.post_process
Internally dict_interactive is used to check and validate data from Stock.dict_stock
In save_new_data it is merged back to Stock.dict_stock and write into file.
Definition at line 27 of file ValidStockUpdate.py.
def serverportfolio.ValidStockUpdate.ValidStockUpdate.__init__ | ( | self, | |
parent_stock, | |||
tk_manager = None |
|||
) |
Constructor.
Always owned by a single parent Stock
parent_stock | stock object |
tk_manager | instance of a ManagerTk, needed in interactive session |
Definition at line 32 of file ValidStockUpdate.py.
|
staticprivate |
Check for common error in historical price data and return a status and an error code.
values | all 6 values [date,4 values,volume] in list_csv (HistPrice) |
interactive | boolean |
Definition at line 478 of file ValidStockUpdate.py.
|
private |
Fill dict_interactive in case of list of data (HistPrice action implemented) dict_inter_action stores chronological group of data, with or without errors.
Same notation status 0, 1 or 2.
Groups are continguous data considered as valid or invalid.
key_action | name of the action |
interactive | boolean if interactive mode is present. Wrong data will have a status of 1 if active. |
Definition at line 413 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_data().
|
private |
Valid last values retrieved with parsers, try to guess values to be updated.
key_action | action name |
interactive |
Definition at line 264 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_data(), and serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_xml_data().
def serverportfolio.ValidStockUpdate.ValidStockUpdate.check_list_csv | ( | self, | |
opt_interactive = False |
|||
) |
Check the CSV data are not wrong.
Bug with Yahoo, sometimes data download are wrong (can be similar in the web page). Bug found:
Return True if correct, and then can proceed with saving the data into file.
Return False, some errors are found, the data should not be saved by default. But still downloadable ?
Set global error to HistPrice, set local HistPrice error return True if correct to extend DivSplit, InstValue not needed now
Definition at line 374 of file ValidStockUpdate.py.
References serverportfolio.Stock.Stock.get_action().
def serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_data | ( | self, | |
e_action, | |||
interactive | |||
) |
Check the validity of the last updated values from Stock.dict_stock and generate dict_interactive.
Executed before an automatic or interactive update of the XML data (_dict_xml)
Updated data are stored in self.dict_interactive
Definition at line 96 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate._dict_interactive, serverportfolio.Stock.Stock._dict_interactive, serverportfolio.ValidStockUpdate.ValidStockUpdate._valid_new_value_csv(), serverportfolio.ValidStockUpdate.ValidStockUpdate._valid_new_value_xml(), and serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.post_process_one_action().
def serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_xml_data | ( | self, | |
opt_interactive = False |
|||
) |
Check the validity of the new retrieved data stored Stock._dict_stock.
Executed before an automatic or interactive update of the XML data (_dict_xml)
Valid data are stored in self.dict_interactive
opt_interactive | optional validation by user (GUI) |
Definition at line 186 of file ValidStockUpdate.py.
References serverportfolio.Stock.Stock._dict_stock, serverportfolio.ValidStockUpdate.ValidStockUpdate._valid_new_value_xml(), serverportfolio.Stock.Stock.get_action(), serverportfolio.Stock.Stock.saved_as(), and serverportfolio.StockTemplates.StockTemplates.saved_as().
|
static |
Generic function to check if new_value can be updated.
Return:
A conversion of new_value and xml_value to type_value are performed as a check
No exception are throw if types are wrong and return 0
new_value | recent value, obtained from parsers |
xml_value | last value in xml |
type_value | StringType or FloatType. Integers are converted to float. |
Definition at line 557 of file ValidStockUpdate.py.
def serverportfolio.ValidStockUpdate.ValidStockUpdate.gen_part_of_list_csv | ( | self, | |
last_date | |||
) |
Generate a sub-list of list_csv, starting from the last call until the last_date (included)
First call, after initialization, start at the first data of the list
Not found a nice way to run the first call, must use None
or could pass the list_data as well, but confusing...
last_date,certainly | always the |
Definition at line 517 of file ValidStockUpdate.py.
References serverportfolio.Stock.Stock.get_action().
Referenced by serverportfolio.Stock.Stock.save_hist_price().
def serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent | ( | self | ) |
Return the parent Stock.
Definition at line 45 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate._parent_stock.
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate._valid_new_value_csv(), serverportfolio.ValidStockUpdate.ValidStockUpdate._valid_new_value_xml(), serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_data(), serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_data(), serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_xml_data(), and serverportfolio.ValidStockUpdate.ValidStockUpdate.valid_interactive().
|
static |
Guess if the input value is valid.
A conversion to the type is tested efore in the code... Used only to test new value, the xml_value is considered already valid
Return 0, 1 or 2:
value | input |
type_value | type of the value: string or float. Other will return -2 |
Definition at line 621 of file ValidStockUpdate.py.
def serverportfolio.ValidStockUpdate.ValidStockUpdate.post_process_one_action | ( | self, | |
e_action, | |||
option_post | |||
) |
Assure the post_processing of a Stock after the parsing of one unique action.
This function is intended to be executed during the post_processing stage of a stock, with a specific action.
e_action | action |
option_post | option to the post-process stage |
Definition at line 55 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate._dict_interactive, serverportfolio.Stock.Stock._dict_interactive, serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_data(), serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_data(), and serverportfolio.ValidStockUpdate.ValidStockUpdate.valid_interactive().
def serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_data | ( | self, | |
e_action | |||
) |
Final merge (after user/auto-validation) and write to file.
The correct format xml/csv is called.
Definition at line 134 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate._dict_interactive, serverportfolio.Stock.Stock._dict_interactive, serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent(), and serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_xml_data().
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.post_process_one_action().
def serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_xml_data | ( | self | ) |
Final merge (after user/auto validation) and write XML file.
This step includes the merging of the data in self.dist_interactive,
and (re-)write the file by a call to write_xml, include TEST_MODE for unit-test
Definition at line 215 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_data().
def serverportfolio.ValidStockUpdate.ValidStockUpdate.valid_interactive | ( | self | ) |
User validation of the new data.
Use a Tk GUI Interface for the validation.
Tkinter does not support multi-threading, a lock must be implemented. Should try to regroup 2 interfaces in one
Definition at line 156 of file ValidStockUpdate.py.
References serverportfolio.ValidStockUpdate.ValidStockUpdate._dict_interactive, serverportfolio.Stock.Stock._dict_interactive, serverportfolio.ValidStockUpdate.ValidStockUpdate._tk_manager, and serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.post_process_one_action().
|
private |
Dictionary of data after check_new_data.
Definition at line 40 of file ValidStockUpdate.py.
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_data(), serverportfolio.ValidStockUpdate.ValidStockUpdate.post_process_one_action(), serverportfolio.ValidStockUpdate.ValidStockUpdate.save_new_data(), and serverportfolio.ValidStockUpdate.ValidStockUpdate.valid_interactive().
|
private |
Definition at line 33 of file ValidStockUpdate.py.
|
private |
Associated to an unique stock.
Definition at line 38 of file ValidStockUpdate.py.
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().
|
private |
Store a ManagerTk interface in multi-thread mode.
Definition at line 42 of file ValidStockUpdate.py.
Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.valid_interactive().
|
static |
Definition at line 387 of file ValidStockUpdate.py.
serverportfolio.ValidStockUpdate.ValidStockUpdate.dict_interactive |
Definition at line 210 of file ValidStockUpdate.py.