SWDatabase
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
Classes | Functions | Variables
database.database_event Namespace Reference

Classes

class  DBEventError
 Error returned by database_event. More...
 

Functions

def create_table
 Create a table for file event in a database for all event files. More...
 
def create_table_event
 Create a event table event in a database. More...
 
def row2dict
 Classic SQLite routine for transforming a row of tuple into a dictionnary. More...
 
def open_db
 Open DB in dictionnary mode. More...
 
def init_db
 Initialise output database file. More...
 
def find_element
 Find an element in 1 or multiple tables. More...
 
def add_element
 Add an element in a table. More...
 
def update_element
 Update an element in a table through its ID. More...
 
def delete_element
 Delete an element in a table through its ID. More...
 
def compare_element_file
 Compare 2 db_elements file. More...
 
def compare_element_event
 Compare 2 db_elements event. More...
 
def printdiff_element_file
 Show differences between 2 db_elements file. More...
 
def printdiff_element_event
 Show differences between 2 db_elements event. More...
 
def fetch_level_choice
 For a given table_name, return the file fetch level it should use. More...
 
def datetime2event
 Look for the corresponding event in table_name table. More...
 
def nearest_sup
 Look for the nearest and newer event for an given day. More...
 
def nearest_inf
 Look for the nearest and older event for an given day. More...
 
def build_db
 Build the SW database for all files available and for a given table. More...
 

Variables

tuple database_path = os.path.join(path_db,'event.db')
 
list database_tables
 
list attributes = []
 

Function Documentation

def database.database_event.add_element (   table_name,
  connector,
  cursor,
  kwargs 
)

Add an element in a table.

If found 0 corresponding element, just add it.
If found more than 1 corresponding element, raise DBEventError.

Here is the call graph for this function:

Here is the caller graph for this function:

def database.database_event.build_db (   table_name,
  db_file,
  verbose = False 
)

Build the SW database for all files available and for a given table.

Verbose = 0 or False: no verbose
Verbose = 1 or True: some basic
Verbose > 1: more verbose
Will look into folder corresponding to fetch type

Here is the call graph for this function:

def database.database_event.compare_element_event (   db1,
  db2 
)

Compare 2 db_elements event.

For all attribute names (see database_event_attributes), check if db1[attr_name] == db2[attr_name].

Returns
boolean True if identical
def database.database_event.compare_element_file (   db1,
  db2 
)

Compare 2 db_elements file.

For all attribute names (see database_event_attributes), check if db1[attr_name] == db2[attr_name].

Returns
boolean True if identical
def database.database_event.create_table (   connector,
  table_name 
)

Create a table for file event in a database for all event files.

For a table name, create all the attributes.

Here is the caller graph for this function:

def database.database_event.create_table_event (   connector,
  table_name 
)

Create a event table event in a database.

For a table name, create all the attributes.

def database.database_event.datetime2event (   table_name,
  connector,
  cursor,
  date_in,
  fetch_level = None,
  h_accuracy = 3,
  event_type = None 
)

Look for the corresponding event in table_name table.

If h_accuracy > 0: return elements such that date_begin in [x-h,x+h] OR date_peak in [x-h,x+h] OR date_end in [x-h,x+h]
If h_accuracy = 0: return elements such that x in [date_begin,date_peak] OR x in [date_peak,date_end]

Returns
Corresponding element(s) of the database.

Here is the call graph for this function:

def database.database_event.delete_element (   table_name,
  connector,
  cursor,
  element_id 
)

Delete an element in a table through its ID.

def database.database_event.fetch_level_choice (   table_name)

For a given table_name, return the file fetch level it should use.

Todo:
Check input

Here is the caller graph for this function:

def database.database_event.find_element (   table_names,
  connector,
  cursor,
  kwargs 
)

Find an element in 1 or multiple tables.

Parameters
[in]table_nameslist of 1 or multiple table names
[in]connector
[in]cursor
[in]kwargsoptional arguments corresponding to database_event_attributes and their values
[out]resultslist DB element found

Here is the caller graph for this function:

def database.database_event.init_db (   db_file,
  verbose_in 
)

Initialise output database file.

If already exists, replace it. Old db kept into .old.
Verbose = 0 or False: no verbose
Verbose = 1 or True: some basic
Verbose > 1: more verbose

Here is the call graph for this function:

def database.database_event.nearest_inf (   table_name,
  connector,
  cursor,
  date_in,
  fetch_level = None,
  event_type = None 
)

Look for the nearest and older event for an given day.

Returns
Corresponding nearest and older element of the database.

Here is the call graph for this function:

def database.database_event.nearest_sup (   table_name,
  connector,
  cursor,
  date_in,
  fetch_level = None,
  event_type = None 
)

Look for the nearest and newer event for an given day.

Returns
Corresponding nearest and newer element of the database.

Here is the call graph for this function:

def database.database_event.open_db (   db_filename)

Open DB in dictionnary mode.

Returns
conn,cur connector and cursor

Here is the caller graph for this function:

def database.database_event.printdiff_element_event (   db1,
  db2 
)

Show differences between 2 db_elements event.

For all attribute names (see database_event_attributes), if db1[attr_name] != db2[attr_name] print their respective value.

def database.database_event.printdiff_element_file (   db1,
  db2 
)

Show differences between 2 db_elements file.

For all attribute names (see database_event_attributes), if db1[attr_name] != db2[attr_name] print their respective value.

def database.database_event.row2dict (   cursor,
  row 
)

Classic SQLite routine for transforming a row of tuple into a dictionnary.

Usage: conn comes from sqlite3.connect(db_file)
conn.row_factory = row2dict
IN FACT NO NEED FOR IT!!!
Just call conn.row_factory = sqlite3.Row

def database.database_event.update_element (   table_name,
  connector,
  cursor,
  element_id,
  kwargs 
)

Update an element in a table through its ID.

Here is the caller graph for this function:

Variable Documentation

list database.database_event.attributes = []
tuple database.database_event.database_path = os.path.join(path_db,'event.db')
list database.database_event.database_tables
Initial value:
1 = [
2 'OBS_CORONA_DONKI_CME' ,\
3 'OBS_CORONA_SOLARMONITOR_NOAAEVENT' ,\
4 ]