ServerPortfolio  2.0
Python parsers and server
 All Classes Namespaces Files Functions Variables Properties Pages
Public Member Functions | Static Public Member Functions | Public Attributes | Private Attributes | List of all members
serverportfolio.ValidStockUpdate.ValidStockUpdate Class Reference

Extend class Stock with functions related to the validation and saving after a stock update: most of the post_process functionalities. More...

Inheritance diagram for serverportfolio.ValidStockUpdate.ValidStockUpdate:
Inheritance graph
[legend]
Collaboration diagram for serverportfolio.ValidStockUpdate.ValidStockUpdate:
Collaboration graph
[legend]

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

def serverportfolio.ValidStockUpdate.ValidStockUpdate.__init__ (   self,
  parent_stock,
  tk_manager = None 
)

Constructor.

Always owned by a single parent Stock

Parameters
parent_stockstock object
tk_managerinstance of a ManagerTk, needed in interactive session

Definition at line 32 of file ValidStockUpdate.py.

Member Function Documentation

def serverportfolio.ValidStockUpdate.ValidStockUpdate._error_list_csv (   values,
  interactive 
)
staticprivate

Check for common error in historical price data and return a status and an error code.

Parameters
valuesall 6 values [date,4 values,volume] in list_csv (HistPrice)
interactiveboolean
Returns
tuple(status,error_code)

Definition at line 478 of file ValidStockUpdate.py.

def serverportfolio.ValidStockUpdate.ValidStockUpdate._valid_new_value_csv (   self,
  key_action,
  interactive 
)
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.

Parameters
key_actionname of the action
interactiveboolean if interactive mode is present. Wrong data will have a status of 1 if active.
Returns
a dict_interactive for this specific action

Definition at line 413 of file ValidStockUpdate.py.

References serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().

Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.check_new_data().

Here is the call graph for this function:

Here is the caller graph for this function:

def serverportfolio.ValidStockUpdate.ValidStockUpdate._valid_new_value_xml (   self,
  key_action,
  interactive 
)
private

Valid last values retrieved with parsers, try to guess values to be updated.

Precondition
last values in parent dict_stock and dict_stock should not be None, assert
Parameters
key_actionaction name
interactive
Returns
value to be stored in dict_interactive['action']

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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:

  • Volume all 0, or some 0
  • All values are identical : 4703.3, 4703.3, 4703.3, 4703.3
  • GSZ : 25 and 26 December, 1 january same value, volume 0 ! (can be hard coded a for a few days..)

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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Parameters
opt_interactiveoptional 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().

Here is the call graph for this function:

def serverportfolio.ValidStockUpdate.ValidStockUpdate.check_value (   new_value,
  xml_value,
  type_value 
)
static

Generic function to check if new_value can be updated.

Return:

  • 2 Update in all cases
  • 1 Propose to update if Interactive, otherwise discard. Output in log to control(maybe other file). Used also if new_value is the default one.
  • 0 Invalid, eliminate in all cases -1 Valid but identical, no point to update

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

Parameters
new_valuerecent value, obtained from parsers
xml_valuelast value in xml
type_valueStringType 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...

1 self.gen_part_of_list_csv(None)
2 sub_list_generator.send(None)
3 ...
4 sub_list = sub_list_generator.send( last_date )
Parameters
last_date,certainlyalways the
Returns
a list of csv [last_call, last_date]

Definition at line 517 of file ValidStockUpdate.py.

References serverportfolio.Stock.Stock.get_action().

Referenced by serverportfolio.Stock.Stock.save_hist_price().

Here is the call graph for this function:

Here is the caller graph for this function:

def serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent (   self)
def serverportfolio.ValidStockUpdate.ValidStockUpdate.is_valid_value (   value,
  type_value 
)
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:

  • 0 not valid: float('nan')
  • 1 valid
  • -1 type_value is not implemented
    Note
    A conversion to the type_value is tested before, not explicitely in the function.
    But if type_value is Float and the value not convertible, a TypeError s thrown
    Parameters
    valueinput
    type_valuetype 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.

Parameters
e_actionaction
option_postoption 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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

serverportfolio.ValidStockUpdate.ValidStockUpdate._dict_interactive
private
serverportfolio.ValidStockUpdate.ValidStockUpdate._logger
private

Definition at line 33 of file ValidStockUpdate.py.

serverportfolio.ValidStockUpdate.ValidStockUpdate._parent_stock
private

Associated to an unique stock.

Definition at line 38 of file ValidStockUpdate.py.

Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.get_parent().

serverportfolio.ValidStockUpdate.ValidStockUpdate._tk_manager
private

Store a ManagerTk interface in multi-thread mode.

Definition at line 42 of file ValidStockUpdate.py.

Referenced by serverportfolio.ValidStockUpdate.ValidStockUpdate.valid_interactive().

tuple serverportfolio.ValidStockUpdate.ValidStockUpdate.dict_action_inter = self._valid_new_value_csv( key_action, opt_interactive )
static

Definition at line 387 of file ValidStockUpdate.py.

serverportfolio.ValidStockUpdate.ValidStockUpdate.dict_interactive

Definition at line 210 of file ValidStockUpdate.py.


The documentation for this class was generated from the following file: